SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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);
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 

SHOGUN Machine Learning Toolbox - Documentation