SHOGUN v0.9.0
组合类型 | 公有成员 | 静态公有成员 | 保护成员 | 保护属性
CSparseFeatures< ST >模板类参考

详细描述

template<class ST>
class shogun::CSparseFeatures< ST >

Template class SparseFeatures implements sparse matrices.

Features are an array of TSparse, sorted w.r.t. vec_index (increasing) and withing same vec_index w.r.t. feat_index (increasing);

Sparse feature vectors can be accessed via get_sparse_feature_vector() and should be freed (this operation is a NOP in most cases) via free_sparse_feature_vector().

As this is a template class it can directly be used for different data types like sparse matrices of real valued, integer, byte etc type.

在文件SparseFeatures.h55行定义。

继承图,类CSparseFeatures< ST >
Inheritance graph
[图例]

所有成员的列表。

组合类型

struct  sparse_feature_iterator

公有成员

 CSparseFeatures (int32_t size=0)
 CSparseFeatures (TSparse< ST > *src, int32_t num_feat, int32_t num_vec, bool copy=false)
 CSparseFeatures (ST *src, int32_t num_feat, int32_t num_vec)
 CSparseFeatures (const CSparseFeatures &orig)
 CSparseFeatures (CFile *loader)
virtual ~CSparseFeatures ()
void free_sparse_feature_matrix ()
void free_sparse_features ()
virtual CFeaturesduplicate () const
ST get_feature (int32_t num, int32_t index)
ST * get_full_feature_vector (int32_t num, int32_t &len)
void get_full_feature_vector (ST **dst, int32_t *len, int32_t num)
virtual int32_t get_nnz_features_for_vector (int32_t num)
TSparseEntry< ST > * get_sparse_feature_vector (int32_t num, int32_t &len, bool &vfree)
ST dense_dot (ST alpha, int32_t num, ST *vec, int32_t dim, ST b)
void add_to_dense_vec (float64_t alpha, int32_t num, float64_t *vec, int32_t dim, bool abs_val=false)
void free_sparse_feature_vector (TSparseEntry< ST > *feat_vec, int32_t num, bool free)
TSparse< ST > * get_sparse_feature_matrix (int32_t &num_feat, int32_t &num_vec)
void get_sparse_feature_matrix (TSparse< ST > **dst, int32_t *num_feat, int32_t *num_vec, int64_t *nnz)
void clean_tsparse (TSparse< ST > *sfm, int32_t num_vec)
CSparseFeatures< ST > * get_transposed ()
TSparse< ST > * get_transposed (int32_t &num_feat, int32_t &num_vec)
virtual void set_sparse_feature_matrix (TSparse< ST > *src, int32_t num_feat, int32_t num_vec)
ST * get_full_feature_matrix (int32_t &num_feat, int32_t &num_vec)
void get_full_feature_matrix (ST **dst, int32_t *num_feat, int32_t *num_vec)
virtual bool set_full_feature_matrix (ST *src, int32_t num_feat, int32_t num_vec)
virtual bool apply_preproc (bool force_preprocessing=false)
virtual int32_t get_size ()
bool obtain_from_simple (CSimpleFeatures< ST > *sf)
virtual int32_t get_num_vectors ()
int32_t get_num_features ()
int32_t set_num_features (int32_t num)
virtual EFeatureClass get_feature_class ()
virtual EFeatureType get_feature_type ()
void free_feature_vector (TSparseEntry< ST > *feat_vec, int32_t num, bool free)
int64_t get_num_nonzero_entries ()
float64_tcompute_squared (float64_t *sq)
float64_t compute_squared_norm (CSparseFeatures< float64_t > *lhs, float64_t *sq_lhs, int32_t idx_a, CSparseFeatures< float64_t > *rhs, float64_t *sq_rhs, int32_t idx_b)
void load (CFile *loader)
void save (CFile *writer)
CLabelsload_svmlight_file (char *fname, bool do_sort_features=true)
void sort_features ()
bool write_svmlight_file (char *fname, CLabels *label)
virtual int32_t get_dim_feature_space ()
virtual float64_t dot (int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
virtual float64_t dense_dot (int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
virtual void * get_feature_iterator (int32_t vector_index)
virtual bool get_next_feature (int32_t &index, float64_t &value, void *iterator)
virtual void free_feature_iterator (void *iterator)
virtual const char * get_name () const

静态公有成员

static ST sparse_dot (ST alpha, TSparseEntry< ST > *avec, int32_t alen, TSparseEntry< ST > *bvec, int32_t blen)

保护成员

virtual TSparseEntry< ST > * compute_sparse_feature_vector (int32_t num, int32_t &len, TSparseEntry< ST > *target=NULL)

保护属性

int32_t num_vectors
 total number of vectors
int32_t num_features
 total number of features
TSparse< ST > * sparse_feature_matrix
 array of sparse vectors of size num_vectors
CCache< TSparseEntry< ST > > * feature_cache

构造及析构函数文档

CSparseFeatures ( int32_t  size = 0)

constructor

参数:
sizecache size

在文件SparseFeatures.h72行定义。

CSparseFeatures ( TSparse< ST > *  src,
int32_t  num_feat,
int32_t  num_vec,
bool  copy = false 
)

convenience constructor that creates sparse features from the ones passed as argument

参数:
srcdense feature matrix
num_featnumber of features
num_vecnumber of vectors
copytrue to copy feature matrix

在文件SparseFeatures.h85行定义。

CSparseFeatures ( ST *  src,
int32_t  num_feat,
int32_t  num_vec 
)

convenience constructor that creates sparse features from dense features

参数:
srcdense feature matrix
num_featnumber of features
num_vecnumber of vectors

在文件SparseFeatures.h113行定义。

CSparseFeatures ( const CSparseFeatures< ST > &  orig)

copy constructor

在文件SparseFeatures.h123行定义。

CSparseFeatures ( CFile loader)

constructor loading features from file

参数:
loaderFile object to load data from

在文件SparseFeatures.h149行定义。

virtual ~CSparseFeatures ( ) [virtual]

default destructor

在文件SparseFeatures.h159行定义。


成员函数文档

void add_to_dense_vec ( float64_t  alpha,
int32_t  num,
float64_t vec,
int32_t  dim,
bool  abs_val = false 
) [virtual]

add a sparse feature vector onto a dense one dense+=alpha*sparse

参数:
alphascalar to multiply with
numindex of feature vector
vecdense vector
dimlength of the dense vector
abs_valif true, do dense+=alpha*abs(sparse)

实现了CDotFeatures

在文件SparseFeatures.h471行定义。

virtual bool apply_preproc ( bool  force_preprocessing = false) [virtual]

apply preprocessor

参数:
force_preprocessingif preprocssing shall be forced
返回:
if applying was successful

在文件SparseFeatures.h823行定义。

void clean_tsparse ( TSparse< ST > *  sfm,
int32_t  num_vec 
)

clean TSparse

参数:
sfmsparse feature matrix
num_vecnumber of vectors in matrix

在文件SparseFeatures.h553行定义。

virtual TSparseEntry<ST>* compute_sparse_feature_vector ( int32_t  num,
int32_t &  len,
TSparseEntry< ST > *  target = NULL 
) [protected, virtual]

compute feature vector for sample num if target is set the vector is written to target len is returned by reference

NOT IMPLEMENTED!

参数:
numnum
lenlen
targettarget

在文件SparseFeatures.h1476行定义。

float64_t* compute_squared ( float64_t sq)

compute a^2 on all feature vectors

参数:
sqthe square for each vector is stored in here
返回:
the square for each vector

在文件SparseFeatures.h946行定义。

float64_t compute_squared_norm ( CSparseFeatures< float64_t > *  lhs,
float64_t sq_lhs,
int32_t  idx_a,
CSparseFeatures< float64_t > *  rhs,
float64_t sq_rhs,
int32_t  idx_b 
)

compute (a-b)^2 (== a^2+b^2-2ab) usually called by kernels'/distances' compute functions works on two feature vectors, although it is a member of a single feature: can either be called by lhs or rhs.

参数:
lhsleft-hand side features
sq_lhssquared values of left-hand side
idx_aindex of left-hand side's vector to compute
rhsright-hand side features
sq_rhssquared values of right-hand side
idx_bindex of right-hand side's vector to compute

在文件SparseFeatures.h979行定义。

virtual float64_t dense_dot ( int32_t  vec_idx1,
const float64_t vec2,
int32_t  vec2_len 
) [virtual]

compute dot product between vector1 and a dense vector

参数:
vec_idx1index of first vector
vec2pointer to real valued vector
vec2_lenlength of real valued vector

实现了CDotFeatures

在文件SparseFeatures.h1347行定义。

ST dense_dot ( ST  alpha,
int32_t  num,
ST *  vec,
int32_t  dim,
ST  b 
)

compute the dot product between dense weights and a sparse feature vector alpha * sparse^T * w + b

参数:
alphascalar to multiply with
numindex of feature vector
vecdense vector to compute dot product with
dimlength of the dense vector
bbias
返回:
dot product between dense weights and a sparse feature vector

在文件SparseFeatures.h442行定义。

virtual float64_t dot ( int32_t  vec_idx1,
CDotFeatures df,
int32_t  vec_idx2 
) [virtual]

compute dot product between vector1 and vector2, appointed by their indices

参数:
vec_idx1index of first vector
dfDotFeatures (of same kind) to compute dot product with
vec_idx2index of second vector

实现了CDotFeatures

在文件SparseFeatures.h1321行定义。

virtual CFeatures* duplicate ( ) const [virtual]

duplicate feature object

返回:
feature object

实现了CFeatures

在文件SparseFeatures.h189行定义。

virtual void free_feature_iterator ( void *  iterator) [virtual]

clean up iterator call this function with the iterator returned by get_first_feature

参数:
iteratoras returned by get_first_feature

实现了CDotFeatures

在文件SparseFeatures.h1452行定义。

void free_feature_vector ( TSparseEntry< ST > *  feat_vec,
int32_t  num,
bool  free 
)

free feature vector

参数:
feat_vecfeature vector to free
numindex of vector in cache
freeif vector really should be deleted

在文件SparseFeatures.h919行定义。

void free_sparse_feature_matrix ( )

free sparse feature matrix

在文件SparseFeatures.h167行定义。

void free_sparse_feature_vector ( TSparseEntry< ST > *  feat_vec,
int32_t  num,
bool  free 
)

free sparse feature vector

参数:
feat_vecfeature vector to free
numindex of this vector in the cache
freeif vector should be really deleted

在文件SparseFeatures.h507行定义。

void free_sparse_features ( )

free sparse feature matrix and cache

在文件SparseFeatures.h178行定义。

virtual int32_t get_dim_feature_space ( ) [virtual]

obtain the dimensionality of the feature space

(not mix this up with the dimensionality of the input space, usually obtained via get_num_features())

返回:
dimensionality

实现了CDotFeatures

在文件SparseFeatures.h1309行定义。

ST get_feature ( int32_t  num,
int32_t  index 
)

get a single feature

参数:
numnumber of feature vector to retrieve
indexindex of feature in this vector
返回:
sum of features that match dimension index and 0 if none is found

在文件SparseFeatures.h201行定义。

virtual EFeatureClass get_feature_class ( ) [virtual]

get feature class

返回:
feature class SPARSE

实现了CFeatures

在文件SparseFeatures.h905行定义。

virtual void* get_feature_iterator ( int32_t  vector_index) [virtual]

iterate over the non-zero features

call get_feature_iterator first, followed by get_next_feature and free_feature_iterator to cleanup

参数:
vector_indexthe index of the vector over whose components to iterate over
返回:
feature iterator (to be passed to get_next_feature)

实现了CDotFeatures

在文件SparseFeatures.h1404行定义。

virtual EFeatureType get_feature_type ( ) [virtual]

get feature type

返回:
templated feature type

实现了CFeatures

ST* get_full_feature_matrix ( int32_t &  num_feat,
int32_t &  num_vec 
)

gets a copy of a full feature matrix num_feat,num_vectors are returned by reference

参数:
num_featnumber of features in matrix
num_vecnumber of vectors in matrix
返回:
full feature matrix

在文件SparseFeatures.h664行定义。

void get_full_feature_matrix ( ST **  dst,
int32_t *  num_feat,
int32_t *  num_vec 
)

gets a copy of a full feature matrix (swig compatible) num_feat,num_vectors are returned by reference

参数:
dstfull feature matrix
num_featnumber of features in matrix
num_vecnumber of vectors in matrix

在文件SparseFeatures.h699行定义。

ST* get_full_feature_vector ( int32_t  num,
int32_t &  len 
)

converts a sparse feature vector into a dense one preprocessed compute_feature_vector caller cleans up

参数:
numindex of feature vector
lenlength is returned by reference
返回:
dense feature vector

在文件SparseFeatures.h233行定义。

void get_full_feature_vector ( ST **  dst,
int32_t *  len,
int32_t  num 
)

get the fully expanded dense feature vector num

参数:
dstfeature vector
lenlength is returned by reference
numindex of feature vector

在文件SparseFeatures.h265行定义。

virtual const char* get_name ( void  ) const [virtual]
返回:
object name

实现了CSGObject

在文件SparseFeatures.h1463行定义。

virtual bool get_next_feature ( int32_t &  index,
float64_t value,
void *  iterator 
) [virtual]

iterate over the non-zero features

call this function with the iterator returned by get_first_feature and call free_feature_iterator to cleanup

参数:
indexis returned by reference (-1 when not available)
valueis returned by reference
iteratoras returned by get_first_feature
返回:
true if a new non-zero feature got returned

实现了CDotFeatures

在文件SparseFeatures.h1433行定义。

virtual int32_t get_nnz_features_for_vector ( int32_t  num) [virtual]

get number of non-zero features in vector

参数:
numwhich vector
返回:
number of non-zero features in vector

实现了CDotFeatures

在文件SparseFeatures.h297行定义。

int32_t get_num_features ( )

get number of features

返回:
number of features

在文件SparseFeatures.h880行定义。

int64_t get_num_nonzero_entries ( )

get number of non-zero entries in sparse feature matrix

返回:
number of non-zero entries in sparse feature matrix

在文件SparseFeatures.h932行定义。

virtual int32_t get_num_vectors ( ) [virtual]

get number of feature vectors

返回:
number of feature vectors

实现了CFeatures

在文件SparseFeatures.h874行定义。

virtual int32_t get_size ( ) [virtual]

get memory footprint of one feature

返回:
memory footprint of one feature

实现了CFeatures

在文件SparseFeatures.h853行定义。

TSparse<ST>* get_sparse_feature_matrix ( int32_t &  num_feat,
int32_t &  num_vec 
)

get the pointer to the sparse feature matrix num_feat,num_vectors are returned by reference

参数:
num_featnumber of features in matrix
num_vecnumber of vectors in matrix
返回:
feature matrix

在文件SparseFeatures.h523行定义。

void get_sparse_feature_matrix ( TSparse< ST > **  dst,
int32_t *  num_feat,
int32_t *  num_vec,
int64_t *  nnz 
)

get the pointer to the sparse feature matrix (swig compatible) num_feat,num_vectors are returned by reference

参数:
dstfeature matrix
num_featnumber of features in matrix
num_vecnumber of vectors in matrix
nnznumber of nonzero elements

在文件SparseFeatures.h539行定义。

TSparseEntry<ST>* get_sparse_feature_vector ( int32_t  num,
int32_t &  len,
bool &  vfree 
)

get sparse feature vector for sample num from the matrix as it is if matrix is initialized, else return preprocessed compute_feature_vector

参数:
numindex of feature vector
lennumber of sparse entries is returned by reference
vfreewhether returned vector must be freed by caller via free_sparse_feature_vector
返回:
sparse feature vector

在文件SparseFeatures.h316行定义。

TSparse<ST>* get_transposed ( int32_t &  num_feat,
int32_t &  num_vec 
)

compute and return the transpose of the sparse feature matrix which will be prepocessed. num_feat, num_vectors are returned by reference caller has to clean up

参数:
num_featnumber of features in matrix
num_vecnumber of vectors in matrix
返回:
transposed sparse feature matrix

在文件SparseFeatures.h585行定义。

CSparseFeatures<ST>* get_transposed ( )

get a transposed copy of the features

返回:
transposed copy

在文件SparseFeatures.h568行定义。

void load ( CFile loader) [virtual]

load features from file

参数:
loaderFile object to load data from

重载CFeatures

CLabels* load_svmlight_file ( char *  fname,
bool  do_sort_features = true 
)

load features from file

参数:
fnamefilename to load from
do_sort_featuresif true features will be sorted to ensure they are in ascending order
返回:
label object with corresponding labels

在文件SparseFeatures.h1054行定义。

bool obtain_from_simple ( CSimpleFeatures< ST > *  sf)

obtain sparse features from simple features

参数:
sfsimple features
返回:
if obtaining was successful

在文件SparseFeatures.h860行定义。

void save ( CFile writer) [virtual]

save features to file

参数:
writerFile object to write data to

重载CFeatures

virtual bool set_full_feature_matrix ( ST *  src,
int32_t  num_feat,
int32_t  num_vec 
) [virtual]

creates a sparse feature matrix from a full dense feature matrix necessary to set feature_matrix, num_features and num_vectors where num_features is the column offset, and columns are linear in memory see above for definition of sparse_feature_matrix

参数:
srcfull feature matrix
num_featnumber of features in matrix
num_vecnumber of vectors in matrix

在文件SparseFeatures.h734行定义。

int32_t set_num_features ( int32_t  num)

set number of features

Sometimes when loading sparse features not all possible dimensions are used. This may pose a problem to classifiers when being applied to higher dimensional test-data. This function allows to artificially explode the feature space

参数:
numthe number of features, must be larger than the current number of features
返回:
previous number of features

在文件SparseFeatures.h893行定义。

virtual void set_sparse_feature_matrix ( TSparse< ST > *  src,
int32_t  num_feat,
int32_t  num_vec 
) [virtual]

set feature matrix necessary to set feature_matrix, num_features, num_vectors, where num_features is the column offset, and columns are linear in memory see below for definition of feature_matrix

参数:
srcnew sparse feature matrix
num_featnumber of features in matrix
num_vecnumber of vectors in matrix

在文件SparseFeatures.h648行定义。

void sort_features ( )

ensure that features occur in ascending order, only call when no preprocessors are attached

在文件SparseFeatures.h1221行定义。

static ST sparse_dot ( ST  alpha,
TSparseEntry< ST > *  avec,
int32_t  alen,
TSparseEntry< ST > *  bvec,
int32_t  blen 
) [static]

compute the dot product between two sparse feature vectors alpha * vec^T * vec

参数:
alphascalar to multiply with
avecfirst sparse feature vector
alenavec's length
bvecsecond sparse feature vector
blenbvec's length
返回:
dot product between the two sparse feature vectors

在文件SparseFeatures.h384行定义。

bool write_svmlight_file ( char *  fname,
CLabels label 
)

write features to file using svm light format

参数:
fnamefilename to write to
labelLabel object (number of labels must correspond to number of features)
返回:
true if successful

在文件SparseFeatures.h1269行定义。


成员数据文档

CCache< TSparseEntry<ST> >* feature_cache [protected]

feature cache

在文件SparseFeatures.h1494行定义。

int32_t num_features [protected]

total number of features

在文件SparseFeatures.h1488行定义。

int32_t num_vectors [protected]

total number of vectors

在文件SparseFeatures.h1485行定义。

TSparse<ST>* sparse_feature_matrix [protected]

array of sparse vectors of size num_vectors

在文件SparseFeatures.h1491行定义。


该类的文档由以下文件生成:

SHOGUN Machine Learning Toolbox - Documentation