SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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);
82  set_store_train_info(false);
84 }
85 
87 {
88  if (data)
89  set_features(data);
90 
91  if (m_verbose||m_store_train_info)
92  {
93  if (m_helper != NULL)
95 
96  m_helper = new CSOSVMHelper();
98  }
99 
100  // Initialize the model for training
102  // call the solver
103  switch(m_solver)
104  {
105  case BMRM:
106  m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
107  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
108  m_store_train_info);
109  break;
110  case PPBMRM:
111  m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
112  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
113  m_verbose);
114  break;
115  case P3BMRM:
116  m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
117  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
118  m_cp_models, m_verbose);
119  break;
120  case NCBM:
121  m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
122  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
123  true /* use line search*/, m_verbose);
124  break;
125  default:
126  SG_ERROR("CDualLibQPBMSOSVM: m_solver=%d is not supported", m_solver);
127  }
128 
129  if (m_result.exitflag>0)
130  return true;
131  else
132  return false;
133 }
134 
136 {
137  return CT_LIBQPSOSVM;
138 }
139 
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)
void set_store_train_info(bool store_train_info)
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 store_train_info)
Definition: libbmrm.cpp:185
#define SG_ERROR(...)
Definition: SGIO.h:129
void set_cleanICP(bool cleanICP)
virtual int32_t get_dim() const =0
#define SG_REF(x)
Definition: SGObject.h:51
int32_t size() const
Definition: SGVector.h:115
index_t vlen
Definition: SGVector.h:494
#define ASSERT(x)
Definition: SGIO.h:201
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:50
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:31
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...
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set_Tmax(uint32_t Tmax)
The class Features is the base class of all feature objects.
Definition: Features.h:68
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:309
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:81
void set_solver(ESolver solver)
virtual EMachineType get_classifier_type()

SHOGUN Machine Learning Toolbox - Documentation