SHOGUN  v3.0.0
 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  SG_ADD(&m_verbose, "m_verbose", "Verbosity flag", MS_NOT_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_verbose(false);
85 }
86 
88 {
89  if (data)
90  set_features(data);
91 
92  // Initialize the model for training
94  // call the solver
95  switch(m_solver)
96  {
97  case BMRM:
98  m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
99  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
100  m_verbose);
101  break;
102  case PPBMRM:
103  m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
104  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
105  m_verbose);
106  break;
107  case P3BMRM:
108  m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
109  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
110  m_cp_models, m_verbose);
111  break;
112  case NCBM:
113  m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
114  m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
115  true /* use line search*/, m_verbose);
116  break;
117  default:
118  SG_ERROR("CDualLibQPBMSOSVM: m_solver=%d is not supported", m_solver);
119  }
120 
121  if (m_result.exitflag==1)
122  return true;
123  else
124  return false;
125 }
126 
128 {
129  return CT_LIBQPSOSVM;
130 }
131 

SHOGUN Machine Learning Toolbox - Documentation