-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
DualLibQPBMSOSVM.cpp
127 lines (112 loc) · 3.13 KB
/
DualLibQPBMSOSVM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2012 Michal Uricar
* Copyright (C) 2012 Michal Uricar
*/
#include <shogun/structure/DualLibQPBMSOSVM.h>
#include <shogun/structure/libbmrm.h>
#include <shogun/structure/libppbm.h>
#include <shogun/structure/libp3bm.h>
#include <shogun/structure/libncbm.h>
using namespace shogun;
CDualLibQPBMSOSVM::CDualLibQPBMSOSVM()
:CLinearStructuredOutputMachine()
{
init();
}
CDualLibQPBMSOSVM::CDualLibQPBMSOSVM(
CStructuredModel* model,
CStructuredLabels* labs,
float64_t _lambda,
SGVector< float64_t > W)
: CLinearStructuredOutputMachine(model, labs)
{
set_TolRel(0.001);
set_TolAbs(0.0);
set_BufSize(1000);
set_lambda(_lambda);
set_cleanICP(true);
set_cleanAfter(10);
set_K(0.4);
set_Tmax(100);
set_cp_models(1);
set_verbose(false);
set_solver(BMRM);
// get dimension of w
uint32_t nDim=this->m_model->get_dim();
// Check for initial solution
if (W.vlen==0)
{
m_w=SGVector< float64_t >(nDim);
m_w.zero();
}
else
{
set_w(W);
}
init();
}
CDualLibQPBMSOSVM::~CDualLibQPBMSOSVM()
{
}
void CDualLibQPBMSOSVM::init()
{
SG_ADD(&m_TolRel, "m_TolRel", "Relative tolerance", MS_AVAILABLE);
SG_ADD(&m_TolAbs, "m_TolAbs", "Absolute tolerance", MS_AVAILABLE);
SG_ADD(&m_BufSize, "m_BuffSize", "Size of CP Buffer", MS_AVAILABLE);
SG_ADD(&m_lambda, "m_lambda", "Regularization constant lambda",
MS_AVAILABLE);
SG_ADD(&m_cleanICP, "m_cleanICP", "Inactive cutting plane removal flag",
MS_AVAILABLE);
SG_ADD(&m_cleanAfter,
"m_cleanAfter",
"Number of inactive iterations after which ICP will be removed",
MS_AVAILABLE);
SG_ADD(&m_K, "m_K", "Parameter K", MS_NOT_AVAILABLE);
SG_ADD(&m_Tmax, "m_Tmax", "Parameter Tmax", MS_AVAILABLE);
SG_ADD(&m_cp_models, "m_cp_models", "Number of cutting plane models",
MS_AVAILABLE);
SG_ADD(&m_verbose, "m_verbose", "Verbosity flag", MS_NOT_AVAILABLE);
}
bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
{
if (data)
set_features(data);
// Initialize the model for training
m_model->init_training();
// call the solver
switch(m_solver)
{
case BMRM:
m_result=svm_bmrm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
m_verbose);
break;
case PPBMRM:
m_result=svm_ppbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
m_verbose);
break;
case P3BMRM:
m_result=svm_p3bm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax,
m_cp_models, m_verbose);
break;
case NCBM:
m_result=svm_ncbm_solver(this, m_w.vector, m_TolRel, m_TolAbs,
m_lambda, m_BufSize, m_cleanICP, m_cleanAfter, true /* convex */,
true /* use line search*/, m_verbose);
}
if (m_result.exitflag==1)
return true;
else
return false;
}
EMachineType CDualLibQPBMSOSVM::get_classifier_type()
{
return CT_LIBQPSOSVM;
}