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
preprocessor
DimensionReductionPreprocessor.cpp
Go to the documentation of this file.
1
#include <
shogun/preprocessor/DimensionReductionPreprocessor.h
>
2
#include <
shogun/converter/EmbeddingConverter.h
>
3
#include <
shogun/kernel/LinearKernel.h
>
4
#include <
shogun/distance/EuclidianDistance.h
>
5
6
using namespace
shogun;
7
8
namespace
shogun
9
{
10
CDimensionReductionPreprocessor::CDimensionReductionPreprocessor
()
11
:
CSimplePreprocessor
<
float64_t
>()
12
{
13
m_target_dim
= 1;
14
m_distance
=
new
CEuclidianDistance
();
15
m_kernel
=
new
CLinearKernel
();
16
m_converter
= NULL;
17
18
init
();
19
}
20
21
CDimensionReductionPreprocessor::CDimensionReductionPreprocessor
(
CEmbeddingConverter
* converter)
22
:
CSimplePreprocessor
<
float64_t
>()
23
{
24
SG_REF
(converter);
25
m_target_dim
= 1;
26
m_distance
=
new
CEuclidianDistance
();
27
m_kernel
=
new
CLinearKernel
();
28
m_converter
= converter;
29
30
init
();
31
}
32
33
CDimensionReductionPreprocessor::~CDimensionReductionPreprocessor
()
34
{
35
SG_UNREF
(
m_distance
);
36
SG_UNREF
(
m_kernel
);
37
SG_UNREF
(
m_converter
);
38
}
39
40
SGMatrix<float64_t>
CDimensionReductionPreprocessor::apply_to_feature_matrix
(
CFeatures
* features)
41
{
42
if
(
m_converter
)
43
{
44
m_converter
->
set_target_dim
(
m_target_dim
);
45
CSimpleFeatures<float64_t>
* embedding =
m_converter
->
embed
(features);
46
SGMatrix<float64_t>
embedding_feature_matrix = embedding->
steal_feature_matrix
();
47
((
CSimpleFeatures<float64_t>
*)features)->set_feature_matrix(embedding_feature_matrix);
48
delete
embedding;
49
return
embedding_feature_matrix;
50
}
51
else
52
{
53
SG_WARNING
(
"Converter to process was not set.\n"
);
54
return
((
CSimpleFeatures<float64_t>
*)features)->get_feature_matrix();
55
}
56
}
57
58
bool
CDimensionReductionPreprocessor::init
(
CFeatures
* data)
59
{
60
return
true
;
61
}
62
63
void
CDimensionReductionPreprocessor::cleanup
()
64
{
65
66
}
67
68
EPreprocessorType
CDimensionReductionPreprocessor::get_type
()
const
{
return
P_DIMENSIONREDUCTIONPREPROCESSOR
; };
69
70
void
CDimensionReductionPreprocessor::set_target_dim
(int32_t dim)
71
{
72
ASSERT
(dim>0);
73
m_target_dim
= dim;
74
}
75
76
int32_t
CDimensionReductionPreprocessor::get_target_dim
()
const
77
{
78
return
m_target_dim
;
79
}
80
81
void
CDimensionReductionPreprocessor::set_distance
(
CDistance
* distance)
82
{
83
SG_UNREF
(
m_distance
);
84
SG_REF
(distance);
85
m_distance
= distance;
86
}
87
88
CDistance
*
CDimensionReductionPreprocessor::get_distance
()
const
89
{
90
SG_REF
(
m_distance
);
91
return
m_distance
;
92
}
93
94
void
CDimensionReductionPreprocessor::set_kernel
(
CKernel
* kernel)
95
{
96
SG_UNREF
(
m_kernel
);
97
SG_REF
(kernel);
98
m_kernel
= kernel;
99
}
100
101
CKernel
*
CDimensionReductionPreprocessor::get_kernel
()
const
102
{
103
SG_REF
(
m_kernel
);
104
return
m_kernel
;
105
}
106
107
void
CDimensionReductionPreprocessor::init
()
108
{
109
this->
m_parameters
->
add
((
CSGObject
**)&
m_converter
,
"converter"
,
110
"embedding converter used to apply to data"
);
111
this->
m_parameters
->
add
(&
m_target_dim
,
"target_dim"
,
112
"target dimensionality of preprocessor"
);
113
this->
m_parameters
->
add
((
CSGObject
**)&
m_distance
,
"distance"
,
114
"distance to be used for embedding"
);
115
this->
m_parameters
->
add
((
CSGObject
**)&
m_kernel
,
"kernel"
,
116
"kernel to be used for embedding"
);
117
}
118
}
SHOGUN
Machine Learning Toolbox - Documentation