SHOGUN
v3.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
features
HashedSparseFeatures.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) 2013 Evangelos Anagnostopoulos
8
* Copyright (C) 2013 Evangelos Anagnostopoulos
9
*/
10
11
#ifndef _HASHED_SPARSEFEATURES_H__
12
#define _HASHED_SPARSEFEATURES_H__
13
14
#include <
shogun/features/SparseFeatures.h
>
15
#include <
shogun/features/DotFeatures.h
>
16
#include <
shogun/lib/SGSparseVector.h
>
17
18
namespace
shogun
19
{
20
template
<
class
ST>
class
CSparseFeatures;
21
template
<
class
ST>
class
SGSparseVector;
22
class
CDotFeatures;
23
27
template
<
class
ST>
class
CHashedSparseFeatures
:
public
CDotFeatures
28
{
29
public
:
30
37
CHashedSparseFeatures
(int32_t size=0,
bool
use_quadr =
false
,
bool
keep_lin_terms =
true
);
38
46
CHashedSparseFeatures
(
CSparseFeatures<ST>
* feats, int32_t d,
bool
use_quadr =
false
,
47
bool
keep_lin_terms =
true
);
48
56
CHashedSparseFeatures
(
SGSparseMatrix<ST>
matrix, int32_t d,
bool
use_quadr =
false
,
57
bool
keep_lin_terms =
true
);
58
66
CHashedSparseFeatures
(
CFile
* loader, int32_t d,
bool
use_quadr =
false
,
67
bool
keep_lin_terms =
true
);
68
70
CHashedSparseFeatures
(
const
CHashedSparseFeatures
& orig);
71
73
virtual
CFeatures
*
duplicate
()
const
;
74
76
virtual
~CHashedSparseFeatures
();
77
85
virtual
int32_t
get_dim_feature_space
()
const
;
86
96
virtual
float64_t
dot
(int32_t vec_idx1,
CDotFeatures
* df,
97
int32_t vec_idx2);
98
107
virtual
float64_t
dense_dot
(int32_t vec_idx1,
const
float64_t
* vec2,
108
int32_t vec2_len);
109
120
virtual
void
add_to_dense_vec
(
float64_t
alpha, int32_t vec_idx1,
121
float64_t
* vec2, int32_t vec2_len,
bool
abs_val =
false
);
122
128
virtual
int32_t
get_nnz_features_for_vector
(int32_t num);
129
141
virtual
void
*
get_feature_iterator
(int32_t vector_index);
142
155
virtual
bool
get_next_feature
(int32_t& index,
float64_t
& value,
156
void
* iterator);
157
163
virtual
void
free_feature_iterator
(
void
* iterator);
164
166
virtual
const
char
*
get_name
()
const
;
167
172
virtual
EFeatureType
get_feature_type
()
const
;
173
178
virtual
EFeatureClass
get_feature_class
()
const
;
179
184
virtual
int32_t
get_num_vectors
()
const
;
185
190
SGSparseVector<ST>
get_hashed_feature_vector
(int32_t vec_idx)
const
;
191
200
static
SGSparseVector<ST>
hash_vector
(
SGVector<ST>
vec, int32_t
dim
,
201
bool
use_quadratic
=
false
,
bool
keep_linear_terms
=
true
);
202
203
212
static
SGSparseVector<ST>
hash_vector
(
SGSparseVector<ST>
vec, int32_t dim,
213
bool
use_quadratic
=
false
,
bool
keep_linear_terms
=
true
);
214
215
private
:
216
void
init(
CSparseFeatures<ST>
* feats, int32_t d,
bool
use_quadr,
bool
keep_lin_terms);
217
218
protected
:
219
221
CSparseFeatures<ST>
*
sparse_feats
;
222
224
int32_t
dim
;
225
227
bool
use_quadratic
;
228
230
bool
keep_linear_terms
;
231
};
232
}
233
234
#endif // _HASHED_SPARSEFEATURES_H__
SHOGUN
Machine Learning Toolbox - Documentation