SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
latent
LatentSOSVM.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 Viktor Gal
8
* Copyright (C) 2012 Viktor Gal
9
*/
10
11
#include <
shogun/latent/LatentSOSVM.h
>
12
#include <
shogun/structure/DualLibQPBMSOSVM.h
>
13
14
using namespace
shogun;
15
16
CLatentSOSVM::CLatentSOSVM
()
17
:
CLinearLatentMachine
()
18
{
19
register_parameters();
20
m_so_solver=NULL;
21
}
22
23
CLatentSOSVM::CLatentSOSVM
(
CLatentModel
* model,
CLinearStructuredOutputMachine
* so_solver,
float64_t
C)
24
:
CLinearLatentMachine
(model, C)
25
{
26
register_parameters();
27
set_so_solver
(so_solver);
28
}
29
30
CLatentSOSVM::~CLatentSOSVM
()
31
{
32
SG_UNREF
(m_so_solver);
33
}
34
35
CLatentLabels
*
CLatentSOSVM::apply_latent
()
36
{
37
return
NULL;
38
}
39
40
void
CLatentSOSVM::set_so_solver
(
CLinearStructuredOutputMachine
* so)
41
{
42
SG_REF
(so);
43
SG_UNREF
(m_so_solver);
44
m_so_solver = so;
45
}
46
47
float64_t
CLatentSOSVM::do_inner_loop
(
float64_t
cooling_eps)
48
{
49
float64_t
lambda = 1/
m_C
;
50
CDualLibQPBMSOSVM
* so =
new
CDualLibQPBMSOSVM
();
51
so->
set_lambda
(lambda);
52
so->
train
();
53
54
/* copy the resulting w */
55
SGVector<float64_t>
cur_w = so->
get_w
();
56
memcpy(
w
.
vector
, cur_w.
vector
, cur_w.
vlen
*
sizeof
(
float64_t
));
57
58
/* get the primal objective value */
59
float64_t
po = so->
get_result
().
Fp
;
60
61
SG_UNREF
(so);
62
63
return
po;
64
}
65
66
void
CLatentSOSVM::register_parameters()
67
{
68
m_parameters
->
add
((
CSGObject
**)&m_so_solver,
"so_solver"
,
"Structured Output Solver."
);
69
}
70
SHOGUN
Machine Learning Toolbox - Documentation