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
kernel
ScatterKernelNormalizer.h
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) 2010 Soeren Sonnenburg
8
* Copyright (C) 2010 Berlin Institute of Technology
9
*/
10
11
#ifndef _SCATTERKERNELNORMALIZER_H___
12
#define _SCATTERKERNELNORMALIZER_H___
13
14
#include <
shogun/kernel/KernelNormalizer.h
>
15
#include <
shogun/kernel/IdentityKernelNormalizer.h
>
16
#include <
shogun/kernel/Kernel.h
>
17
#include <
shogun/features/Labels.h
>
18
#include <
shogun/io/SGIO.h
>
19
20
namespace
shogun
21
{
23
class
CScatterKernelNormalizer
:
public
CKernelNormalizer
24
{
25
26
public
:
28
CScatterKernelNormalizer
() :
CKernelNormalizer
()
29
{
30
init
();
31
}
32
35
CScatterKernelNormalizer
(
float64_t
const_diag,
float64_t
const_offdiag,
36
CLabels
* labels,
CKernelNormalizer
* normalizer=NULL)
37
:
CKernelNormalizer
()
38
{
39
init
();
40
41
m_testing_class
=-1;
42
m_const_diag
=const_diag;
43
m_const_offdiag
=const_offdiag;
44
45
ASSERT
(labels)
46
SG_REF
(labels);
47
m_labels
=labels;
48
49
if
(normalizer==NULL)
50
normalizer=
new
CIdentityKernelNormalizer
();
51
SG_REF
(normalizer);
52
m_normalizer
=normalizer;
53
54
SG_DEBUG
(
"Constructing ScatterKernelNormalizer with const_diag=%g"
55
" const_offdiag=%g num_labels=%d and normalizer='%s'\n"
,
56
const_diag, const_offdiag, labels->
get_num_labels
(),
57
normalizer->get_name());
58
}
59
61
virtual
~CScatterKernelNormalizer
()
62
{
63
SG_UNREF
(
m_labels
);
64
SG_UNREF
(
m_normalizer
);
65
}
66
69
virtual
bool
init
(
CKernel
* k)
70
{
71
m_normalizer
->
init
(k);
72
return
true
;
73
}
74
79
int32_t
get_testing_class
()
80
{
81
return
m_testing_class
;
82
}
83
88
void
set_testing_class
(int32_t c)
89
{
90
m_testing_class
=c;
91
}
92
98
inline
virtual
float64_t
normalize
(
float64_t
value, int32_t idx_lhs,
99
int32_t idx_rhs)
100
{
101
value=
m_normalizer
->
normalize
(value, idx_lhs, idx_rhs);
102
float64_t
c=
m_const_offdiag
;
103
104
if
(
m_testing_class
>=0)
105
{
106
if
(
m_labels
->
get_label
(idx_lhs) ==
m_testing_class
)
107
c=
m_const_diag
;
108
}
109
else
110
{
111
if
(
m_labels
->
get_label
(idx_lhs) ==
m_labels
->
get_label
(idx_rhs))
112
c=
m_const_diag
;
113
114
}
115
return
value*c;
116
}
117
122
inline
virtual
float64_t
normalize_lhs
(
float64_t
value, int32_t idx_lhs)
123
{
124
SG_ERROR
(
"normalize_lhs not implemented"
);
125
return
0;
126
}
127
132
inline
virtual
float64_t
normalize_rhs
(
float64_t
value, int32_t idx_rhs)
133
{
134
SG_ERROR
(
"normalize_rhs not implemented"
);
135
return
0;
136
}
137
139
inline
virtual
const
char
*
get_name
()
const
140
{
141
return
"ScatterKernelNormalizer"
;
142
}
143
144
private
:
145
void
init()
146
{
147
m_const_diag
= 1.0;
148
m_const_offdiag
= 1.0;
149
150
m_labels
= NULL;
151
m_normalizer
= NULL;
152
153
m_testing_class
= -1;
154
155
156
m_parameters
->
add
(&
m_testing_class
,
"m_testing_class"
157
"Testing Class."
);
158
m_parameters
->
add
(&
m_const_diag
,
"m_const_diag"
159
"Factor to multiply to diagonal elements."
);
160
m_parameters
->
add
(&
m_const_offdiag
,
"m_const_offdiag"
161
"Factor to multiply to off-diagonal elements."
);
162
163
m_parameters
->
add
((
CSGObject
**) &
m_labels
,
"m_labels"
,
"Labels"
);
164
m_parameters
->
add
((
CSGObject
**) &
m_normalizer
,
"m_normalizer"
,
"Kernel normalizer."
);
165
}
166
167
protected
:
168
170
float64_t
m_const_diag
;
172
float64_t
m_const_offdiag
;
173
175
CLabels
*
m_labels
;
176
178
CKernelNormalizer
*
m_normalizer
;
179
181
int32_t
m_testing_class
;
182
};
183
}
184
#endif
185
SHOGUN
Machine Learning Toolbox - Documentation