SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
lib
SGSparseVector.h
浏览该文件的文档.
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 Thoralf Klein
8
* Written (W) 2012 Fernando José Iglesias García
9
* Written (W) 2010,2012 Soeren Sonnenburg
10
* Copyright (C) 2010 Berlin Institute of Technology
11
* Copyright (C) 2012 Soeren Sonnenburg
12
*/
13
14
#ifndef __SGSPARSEVECTOR_H__
15
#define __SGSPARSEVECTOR_H__
16
17
#include <
shogun/lib/config.h
>
18
#include <
shogun/lib/DataType.h
>
19
#include <
shogun/lib/SGReferencedData.h
>
20
21
namespace
shogun
22
{
23
class
CFile;
24
26
template
<
class
T>
struct
SGSparseVectorEntry
27
{
29
index_t
feat_index
;
31
T
entry
;
32
};
33
39
template
<
class
T>
class
SGSparseVector
:
public
SGReferencedData
40
{
41
public
:
43
SGSparseVector
();
44
51
SGSparseVector
(
SGSparseVectorEntry<T>
* feats,
index_t
num_entries,
52
bool
ref_counting=
true
);
53
55
SGSparseVector
(
index_t
num_entries,
bool
ref_counting=
true
);
56
58
SGSparseVector
(
const
SGSparseVector
& orig);
59
60
virtual
~SGSparseVector
();
61
73
T
dense_dot
(T alpha, T* vec, int32_t dim, T b);
74
81
template
<
typename
ST> T
dense_dot
(
SGVector<ST>
vec);
82
90
T
sparse_dot
(
const
SGSparseVector<T>
& v);
91
99
static
T
sparse_dot
(
const
SGSparseVector<T>
& a,
const
SGSparseVector<T>
& b);
100
106
inline
SGSparseVector<T>
get
()
107
{
108
return
*
this
;
109
}
110
116
int32_t
get_num_dimensions
();
117
126
void
sort_features
(
bool
stable_pointer =
false
);
127
134
T
get_feature
(int32_t index);
135
142
SGVector<T>
get_dense
(int32_t dimension);
143
149
SGVector<T>
get_dense
();
150
152
SGSparseVector<T>
clone
()
const
;
153
158
void
load
(
CFile
* loader);
159
164
void
save
(
CFile
* saver);
165
166
172
void
display_vector
(
const
char
* name=
"vector"
,
173
const
char
* prefix=
""
);
174
175
protected
:
176
virtual
void
copy_data
(
const
SGReferencedData
& orig);
177
178
virtual
void
init_data
();
179
180
virtual
void
free_data
();
181
194
static
int32_t
cmp_dot_prod_symmetry_fast
(
index_t
alen,
index_t
blen);
195
205
static
T
dot_prod_asymmetric
(
const
SGSparseVector<T>
& a,
const
SGSparseVector<T>
& b);
206
216
static
T
dot_prod_symmetric
(
const
SGSparseVector<T>
& a,
const
SGSparseVector<T>
& b);
217
218
public
:
220
index_t
num_feat_entries
;
221
223
SGSparseVectorEntry<T>
*
features
;
224
225
};
226
227
}
228
229
#endif // __SGSPARSEVECTOR_H__
SHOGUN
机器学习工具包 - 项目文档