SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LatentSOSVM.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Viktor Gal
8  * Copyright (C) 2012 Viktor Gal
9  */
10 
12 #ifdef USE_GPL_SHOGUN
14 
15 using namespace shogun;
16 
17 CLatentSOSVM::CLatentSOSVM()
19 {
20  register_parameters();
21  m_so_solver=NULL;
22 }
23 
24 CLatentSOSVM::CLatentSOSVM(CLatentModel* model, CLinearStructuredOutputMachine* so_solver, float64_t C)
25  : CLinearLatentMachine(model, C)
26 {
27  register_parameters();
28  set_so_solver(so_solver);
29 }
30 
31 CLatentSOSVM::~CLatentSOSVM()
32 {
33  SG_UNREF(m_so_solver);
34 }
35 
36 CLatentLabels* CLatentSOSVM::apply_latent()
37 {
38  return NULL;
39 }
40 
41 void CLatentSOSVM::set_so_solver(CLinearStructuredOutputMachine* so)
42 {
43  SG_REF(so);
44  SG_UNREF(m_so_solver);
45  m_so_solver = so;
46 }
47 
48 float64_t CLatentSOSVM::do_inner_loop(float64_t cooling_eps)
49 {
50  float64_t lambda = 1/m_C;
51  CDualLibQPBMSOSVM* so = new CDualLibQPBMSOSVM();
52  so->set_lambda(lambda);
53  so->train();
54 
55  /* copy the resulting w */
56  SGVector<float64_t> cur_w = so->get_w();
57  memcpy(w.vector, cur_w.vector, cur_w.vlen*sizeof(float64_t));
58 
59  /* get the primal objective value */
60  float64_t po = so->get_result().Fp;
61 
62  SG_UNREF(so);
63 
64  return po;
65 }
66 
67 void CLatentSOSVM::register_parameters()
68 {
69  m_parameters->add((CSGObject**)&m_so_solver, "so_solver", "Structured Output Solver.");
70 }
71 
72 #endif //USE_GPL_SHOGUN
Abstract class CLatentModel It represents the application specific model and contains most of the app...
Definition: LatentModel.h:33
#define SG_REF(x)
Definition: SGObject.h:51
index_t vlen
Definition: SGVector.h:492
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
double float64_t
Definition: common.h:50
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
abstract implementaion of Linear Machine with latent variable This is the base implementation of all ...
abstract class for latent labels As latent labels always depends on the given application, this class only defines the API that the user has to implement for latent labels.
Definition: LatentLabels.h:26

SHOGUN Machine Learning Toolbox - Documentation