SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatentSOSVM.cpp
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2012 Viktor Gal
00008  * Copyright (C) 2012 Viktor Gal
00009  */
00010 
00011 #include <shogun/latent/LatentSOSVM.h>
00012 #include <shogun/structure/DualLibQPBMSOSVM.h>
00013 
00014 using namespace shogun;
00015 
00016 CLatentSOSVM::CLatentSOSVM()
00017     : CLinearLatentMachine()
00018 {
00019     register_parameters();
00020     m_so_solver=NULL;
00021 }
00022 
00023 CLatentSOSVM::CLatentSOSVM(CLatentModel* model, CLinearStructuredOutputMachine* so_solver, float64_t C)
00024     : CLinearLatentMachine(model, C)
00025 {
00026     register_parameters();
00027     set_so_solver(so_solver);
00028 }
00029 
00030 CLatentSOSVM::~CLatentSOSVM()
00031 {
00032     SG_UNREF(m_so_solver);
00033 }
00034 
00035 CLatentLabels* CLatentSOSVM::apply_latent()
00036 {
00037     return NULL;
00038 }
00039 
00040 void CLatentSOSVM::set_so_solver(CLinearStructuredOutputMachine* so)
00041 {
00042     SG_REF(so);
00043     SG_UNREF(m_so_solver);
00044     m_so_solver = so;
00045 }
00046 
00047 float64_t CLatentSOSVM::do_inner_loop(float64_t cooling_eps)
00048 {
00049     float64_t lambda = 1/m_C;
00050     CDualLibQPBMSOSVM* so = new CDualLibQPBMSOSVM();
00051     so->set_lambda(lambda);
00052     so->train();
00053 
00054     /* copy the resulting w */
00055     SGVector<float64_t> cur_w = so->get_w();
00056     memcpy(w.vector, cur_w.vector, cur_w.vlen*sizeof(float64_t));
00057 
00058     /* get the primal objective value */
00059     float64_t po = so->get_result().Fp;
00060 
00061     SG_UNREF(so);
00062 
00063     return po;
00064 }
00065 
00066 void CLatentSOSVM::register_parameters()
00067 {
00068     m_parameters->add((CSGObject**)&m_so_solver, "so_solver", "Structured Output Solver.");
00069 }
00070 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation