SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
DualLibQPBMSOSVM.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 Michal Uricar
8  * Copyright (C) 2012 Michal Uricar
9  */
10 
16 
17 using namespace shogun;
18 
21 {
22  init();
23 }
24 
26  CStructuredModel* model,
27  CStructuredLabels* labs,
28  float64_t _lambda,
30  : CLinearStructuredOutputMachine(model, labs)
31 {
32  init();
33  set_lambda(_lambda);
34 
35  // get dimension of w
36  int32_t nDim=this->m_model->get_dim();
37 
38  // Check for initial solution
39  if (W.vlen==0)
40  {
42  get_w().zero();
43  }
44  else
45  {
46  ASSERT(W.size() == nDim);
47  set_w(W);
48  }
49 }
50 
52 {
53 }
54 
55 void CDualLibQPBMSOSVM::init()
56 {
57  SG_ADD(&m_TolRel, "m_TolRel", "Relative tolerance", MS_AVAILABLE);
58  SG_ADD(&m_TolAbs, "m_TolAbs", "Absolute tolerance", MS_AVAILABLE);
59  SG_ADD(&m_BufSize, "m_BuffSize", "Size of CP Buffer", MS_AVAILABLE);
60  SG_ADD(&m_lambda, "m_lambda", "Regularization constant lambda",
61  MS_AVAILABLE);
62  SG_ADD(&m_cleanICP, "m_cleanICP", "Inactive cutting plane removal flag",
63  MS_AVAILABLE);
64  SG_ADD(&m_cleanAfter,
65  "m_cleanAfter",
66  "Number of inactive iterations after which ICP will be removed",
67  MS_AVAILABLE);
68  SG_ADD(&m_K, "m_K", "Parameter K", MS_NOT_AVAILABLE);
69  SG_ADD(&m_Tmax, "m_Tmax", "Parameter Tmax", MS_AVAILABLE);
70  SG_ADD(&m_cp_models, "m_cp_models", "Number of cutting plane models",
71  MS_AVAILABLE);
72 
73  set_TolRel(0.001);
74  set_TolAbs(0.0);
75  set_BufSize(1000);
76  set_lambda(0.0);
77  set_cleanICP(true);
78  set_cleanAfter(10);
79  set_K(0.4);
80  set_Tmax(100);
81  set_cp_models(1);
83 }
84 
86 {
87  if (data)
88  set_features(data);
89 
90  if (m_verbose)
91  {
92  if (m_helper != NULL)
94 
95  m_helper = new CSOSVMHelper();
97  }
98 
99  // Initialize the model for training
101  // call the solver
102  switch(m_solver)
103  {
104  case BMRM:
105  m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
106  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
107  m_verbose);
108  break;
109  case PPBMRM:
110  m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
111  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
112  m_verbose);
113  break;
114  case P3BMRM:
115  m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
116  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
117  m_cp_models, m_verbose);
118  break;
119  case NCBM:
120  m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
121  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
122  true /* use line search*/, m_verbose);
123  break;
124  default:
125  SG_ERROR("CDualLibQPBMSOSVM: m_solver=%d is not supported", m_solver);
126  }
127 
128  if (m_result.exitflag>0)
129  return true;
130  else
131  return false;
132 }
133 
135 {
136  return CT_LIBQPSOSVM;
137 }
138 
EMachineType
Definition: Machine.h:33
Base class of the labels used in Structured Output (SO) problems.
void set_BufSize(uint32_t BufSize)
void set_w(SGVector< float64_t > W)
#define SG_UNREF(x)
Definition: SGRefObject.h:35
#define SG_ERROR(...)
Definition: SGIO.h:131
void set_cleanICP(bool cleanICP)
virtual int32_t get_dim() const =0
int32_t size() const
Definition: SGVector.h:54
index_t vlen
Definition: SGVector.h:706
#define ASSERT(x)
Definition: SGIO.h:203
BmrmStatistics svm_ppbm_solver(CDualLibQPBMSOSVM *machine, float64_t *W, float64_t TolRel, float64_t TolAbs, float64_t _lambda, uint32_t _BufSize, bool cleanICP, uint32_t cleanAfter, float64_t K, uint32_t Tmax, bool verbose)
Definition: libppbm.cpp:34
double float64_t
Definition: common.h:48
#define SG_REF(x)
Definition: SGRefObject.h:34
class CSOSVMHelper contains helper functions to compute primal objectives, dual objectives, average training losses, duality gaps etc. These values will be recorded to check convergence. This class is inspired by the matlab implementation of the block coordinate Frank-Wolfe SOSVM solver [1].
Definition: SOSVMHelper.h:29
BmrmStatistics svm_bmrm_solver(CDualLibQPBMSOSVM *machine, float64_t *W, float64_t TolRel, float64_t TolAbs, float64_t _lambda, uint32_t _BufSize, bool cleanICP, uint32_t cleanAfter, float64_t K, uint32_t Tmax, bool verbose)
Definition: libbmrm.cpp:185
void set_TolAbs(float64_t TolAbs)
void set_lambda(float64_t _lambda)
Class CStructuredModel that represents the application specific model and contains most of the applic...
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
void set_Tmax(uint32_t Tmax)
The class Features is the base class of all feature objects.
Definition: Features.h:62
BmrmStatistics svm_ncbm_solver(CDualLibQPBMSOSVM *machine, float64_t *w, float64_t TolRel, float64_t TolAbs, float64_t _lambda, uint32_t _BufSize, bool cleanICP, uint32_t cleanAfter, bool is_convex, bool line_search, bool verbose)
Definition: libncbm.cpp:308
void set_cp_models(uint32_t cp_models)
bool train_machine(CFeatures *data=NULL)
BmrmStatistics svm_p3bm_solver(CDualLibQPBMSOSVM *machine, float64_t *W, float64_t TolRel, float64_t TolAbs, float64_t _lambda, uint32_t _BufSize, bool cleanICP, uint32_t cleanAfter, float64_t K, uint32_t Tmax, uint32_t cp_models, bool verbose)
Definition: libp3bm.cpp:34
void set_cleanAfter(uint32_t cleanAfter)
void set_TolRel(float64_t TolRel)
#define SG_ADD(...)
Definition: SGObject.h:71
void set_solver(ESolver solver)
virtual EMachineType get_classifier_type()

SHOGUN Machine Learning Toolbox - Documentation