SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
latent
LatentSOSVM.cpp
浏览该文件的文档.
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
机器学习工具包 - 项目文档