SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
machine
LinearMachine.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) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/machine/LinearMachine.h
>
12
#include <
shogun/base/Parameter.h
>
13
14
using namespace
shogun;
15
16
CLinearMachine::CLinearMachine
()
17
:
CMachine
(), w_dim(0), w(NULL), bias(0), features(NULL)
18
{
19
20
m_parameters
->
add_vector
(&
w
, &
w_dim
,
"w"
,
"Parameter vector w."
);
21
m_parameters
->
add
(&
bias
,
"bias"
,
"Bias b."
);
22
m_parameters
->
add
((
CSGObject
**) &
features
,
"features"
,
"Feature object."
);
23
24
}
25
26
CLinearMachine::~CLinearMachine
()
27
{
28
SG_FREE
(
w
);
29
SG_UNREF
(
features
);
30
}
31
32
bool
CLinearMachine::load
(FILE* srcfile)
33
{
34
SG_SET_LOCALE_C
;
35
SG_RESET_LOCALE
;
36
return
false
;
37
}
38
39
bool
CLinearMachine::save
(FILE* dstfile)
40
{
41
SG_SET_LOCALE_C
;
42
SG_RESET_LOCALE
;
43
return
false
;
44
}
45
46
CLabels
*
CLinearMachine::apply
()
47
{
48
if
(!
features
)
49
return
NULL;
50
51
int32_t num=
features
->
get_num_vectors
();
52
ASSERT
(num>0);
53
ASSERT
(
w_dim
==
features
->
get_dim_feature_space
());
54
55
float64_t
* out=
SG_MALLOC
(
float64_t
, num);
56
features
->
dense_dot_range
(out, 0, num, NULL,
w
,
w_dim
,
bias
);
57
58
return
new
CLabels
(
SGVector<float64_t>
(out,num));
59
}
60
61
CLabels
*
CLinearMachine::apply
(
CFeatures
* data)
62
{
63
if
(!data)
64
SG_ERROR
(
"No features specified\n"
);
65
if
(!data->
has_property
(
FP_DOT
))
66
SG_ERROR
(
"Specified features are not of type CDotFeatures\n"
);
67
set_features
((
CDotFeatures
*) data);
68
return
apply
();
69
}
SHOGUN
Machine Learning Toolbox - Documentation