SHOGUN
v2.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
kernel
string
CommUlongStringKernel.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) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#ifndef _COMMULONGSTRINGKERNEL_H___
12
#define _COMMULONGSTRINGKERNEL_H___
13
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/mathematics/Math.h
>
16
#include <
shogun/lib/DynamicArray.h
>
17
#include <
shogun/kernel/string/StringKernel.h
>
18
19
namespace
shogun
20
{
21
template
<
class
T>
class
CDynamicArray;
22
template
<
class
ST>
class
CStringFeatures;
23
48
class
CCommUlongStringKernel
:
public
CStringKernel
<uint64_t>
49
{
50
public
:
56
CCommUlongStringKernel
(int32_t size=10,
bool
use_sign
=
false
);
57
65
CCommUlongStringKernel
(
66
CStringFeatures<uint64_t>
* l,
CStringFeatures<uint64_t>
* r,
67
bool
use_sign
=
false
,
68
int32_t size=10);
69
70
virtual
~CCommUlongStringKernel
();
71
78
virtual
bool
init
(
CFeatures
* l,
CFeatures
* r);
79
81
virtual
void
cleanup
();
82
87
virtual
EKernelType
get_kernel_type
() {
return
K_COMMULONGSTRING
; }
88
93
virtual
const
char
*
get_name
()
const
{
return
"CommUlongStringKernel"
; }
94
102
virtual
bool
init_optimization
(
103
int32_t count, int32_t* IDX,
float64_t
* weights);
104
109
virtual
bool
delete_optimization
();
110
116
virtual
float64_t
compute_optimized
(int32_t idx);
117
129
inline
void
merge_dictionaries
(
130
int32_t& t, int32_t j, int32_t& k, uint64_t* vec, uint64_t* dic,
131
float64_t
* dic_weights,
float64_t
weight, int32_t vec_idx)
132
{
133
while
(k<
dictionary
.
get_num_elements
() &&
dictionary
[k] < vec[j-1])
134
{
135
dic[t]=
dictionary
[k];
136
dic_weights[t]=
dictionary_weights
[k];
137
t++;
138
k++;
139
}
140
141
if
(k<
dictionary
.
get_num_elements
() &&
dictionary
[k]==vec[j-1])
142
{
143
dic[t]=vec[j-1];
144
dic_weights[t]=
dictionary_weights
[k]+
normalizer
->
normalize_lhs
(weight, vec_idx);
145
k++;
146
}
147
else
148
{
149
dic[t]=vec[j-1];
150
dic_weights[t]=
normalizer
->
normalize_lhs
(weight, vec_idx);
151
}
152
t++;
153
}
154
160
virtual
void
add_to_normal
(int32_t idx,
float64_t
weight);
161
163
virtual
void
clear_normal
();
164
166
virtual
void
remove_lhs
();
167
169
virtual
void
remove_rhs
();
170
175
inline
virtual
EFeatureType
get_feature_type
() {
return
F_ULONG
; }
176
183
void
get_dictionary
(
184
int32_t &dsize, uint64_t*& dict,
float64_t
*& dweights)
185
{
186
dsize=
dictionary
.
get_num_elements
();
187
dict=
dictionary
.
get_array
();
188
dweights =
dictionary_weights
.
get_array
();
189
}
190
191
protected
:
200
float64_t
compute
(int32_t idx_a, int32_t idx_b);
201
202
protected
:
204
CDynamicArray<uint64_t>
dictionary
;
206
CDynamicArray<float64_t>
dictionary_weights
;
207
209
bool
use_sign
;
210
};
211
}
212
#endif
/* _COMMULONGFSTRINGKERNEL_H__ */
SHOGUN
Machine Learning Toolbox - Documentation