SHOGUN  4.2.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 
12 #ifdef USE_GPL_SHOGUN
17 
18 using namespace shogun;
19 
20 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM()
22 {
23  init();
24 }
25 
26 CDualLibQPBMSOSVM::CDualLibQPBMSOSVM(
27  CStructuredModel* model,
28  CStructuredLabels* labs,
29  float64_t _lambda,
31  : CLinearStructuredOutputMachine(model, labs)
32 {
33  init();
34  set_lambda(_lambda);
35 
36  // get dimension of w
37  int32_t nDim=this->m_model->get_dim();
38 
39  // Check for initial solution
40  if (W.vlen==0)
41  {
42  set_w(SGVector< float64_t >(nDim));
43  get_w().zero();
44  }
45  else
46  {
47  ASSERT(W.size() == nDim);
48  set_w(W);
49  }
50 }
51 
52 CDualLibQPBMSOSVM::~CDualLibQPBMSOSVM()
53 {
54 }
55 
56 void CDualLibQPBMSOSVM::init()
57 {
58  SG_ADD(&m_TolRel, "m_TolRel", "Relative tolerance", MS_AVAILABLE);
59  SG_ADD(&m_TolAbs, "m_TolAbs", "Absolute tolerance", MS_AVAILABLE);
60  SG_ADD(&m_BufSize, "m_BuffSize", "Size of CP Buffer", MS_AVAILABLE);
61  SG_ADD(&m_lambda, "m_lambda", "Regularization constant lambda",
62  MS_AVAILABLE);
63  SG_ADD(&m_cleanICP, "m_cleanICP", "Inactive cutting plane removal flag",
64  MS_AVAILABLE);
65  SG_ADD(&m_cleanAfter,
66  "m_cleanAfter",
67  "Number of inactive iterations after which ICP will be removed",
68  MS_AVAILABLE);
69  SG_ADD(&m_K, "m_K", "Parameter K", MS_NOT_AVAILABLE);
70  SG_ADD(&m_Tmax, "m_Tmax", "Parameter Tmax", MS_AVAILABLE);
71  SG_ADD(&m_cp_models, "m_cp_models", "Number of cutting plane models",
72  MS_AVAILABLE);
73 
74  set_TolRel(0.001);
75  set_TolAbs(0.0);
76  set_BufSize(1000);
77  set_lambda(0.0);
78  set_cleanICP(true);
79  set_cleanAfter(10);
80  set_K(0.4);
81  set_Tmax(100);
82  set_cp_models(1);
83  set_store_train_info(false);
84  set_solver(BMRM);
85 }
86 
87 bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
88 {
89  if (data)
90  set_features(data);
91 
92  if (m_verbose||m_store_train_info)
93  {
94  if (m_helper != NULL)
95  SG_UNREF(m_helper);
96 
97  m_helper = new CSOSVMHelper();
98  SG_REF(m_helper);
99  }
100 
101  // Initialize the model for training
102  m_model->init_training();
103  // call the solver
104  switch(m_solver)
105  {
106  case BMRM:
107  m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
108  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
109  m_store_train_info);
110  break;
111  case PPBMRM:
112  m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
113  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
114  m_verbose);
115  break;
116  case P3BMRM:
117  m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
118  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
119  m_cp_models, m_verbose);
120  break;
121  case NCBM:
122  m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
123  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
124  true /* use line search*/, m_verbose);
125  break;
126  default:
127  SG_ERROR("CDualLibQPBMSOSVM: m_solver=%d is not supported", m_solver);
128  }
129 
130  if (m_result.exitflag>0)
131  return true;
132  else
133  return false;
134 }
135 
136 EMachineType CDualLibQPBMSOSVM::get_classifier_type()
137 {
138  return CT_LIBQPSOSVM;
139 }
140 
141 #endif //USE_GPL_SHOGUN
EMachineType
Definition: Machine.h:33
Base class of the labels used in Structured Output (SO) problems.
#define SG_ERROR(...)
Definition: SGIO.h:129
#define SG_REF(x)
Definition: SGObject.h:51
int32_t size() const
Definition: SGVector.h:113
index_t vlen
Definition: SGVector.h:492
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
virtual bool init(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:65
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
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
The class Features is the base class of all feature objects.
Definition: Features.h:68
#define SG_ADD(...)
Definition: SGObject.h:81

SHOGUN Machine Learning Toolbox - Documentation