CSparseFeatures< ST > Class Template Reference

Inheritance diagram for CSparseFeatures< ST >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class ST>
class CSparseFeatures< ST >

template class SparseFeatures

Definition at line 57 of file SparseFeatures.h.


Public Member Functions

 CSparseFeatures (INT size=0)
 CSparseFeatures (const CSparseFeatures &orig)
 CSparseFeatures (CHAR *fname)
virtual ~CSparseFeatures ()
void free_sparse_feature_matrix ()
void free_sparse_features ()
virtual CFeaturesduplicate () const
ST * get_full_feature_vector (INT num, INT &len)
INT get_num_sparse_vec_features (INT num)
TSparseEntry< ST > * get_sparse_feature_vector (INT num, INT &len, bool &vfree)
ST sparse_dot (ST alpha, TSparseEntry< ST > *avec, INT alen, TSparseEntry< ST > *bvec, INT blen)
void dense_dot_range (ST *output, INT start, INT stop, ST *alphas, ST *vec, INT dim, ST b)
ST dense_dot (ST alpha, INT num, ST *vec, INT dim, ST b)
void add_to_dense_vec (ST alpha, INT num, ST *vec, INT dim, bool abs_val=false)
void free_sparse_feature_vector (TSparseEntry< ST > *feat_vec, INT num, bool free)
TSparse< ST > * get_sparse_feature_matrix (INT &num_feat, INT &num_vec)
void clean_tsparse (TSparse< ST > *sfm, INT num_vec)
TSparse< ST > * get_transposed (INT &num_feat, INT &num_vec)
virtual void set_sparse_feature_matrix (TSparse< ST > *sfm, INT num_feat, INT num_vec)
ST * get_full_feature_matrix (INT &num_feat, INT &num_vec)
virtual bool set_full_feature_matrix (ST *ffm, INT num_feat, INT num_vec)
virtual bool apply_preproc (bool force_preprocessing=false)
virtual INT get_size ()
bool obtain_from_simple (CSimpleFeatures< ST > *sf)
virtual INT get_num_vectors ()
INT get_num_features ()
INT set_num_features (INT num)
virtual EFeatureClass get_feature_class ()
virtual EFeatureType get_feature_type ()
void free_feature_vector (TSparseEntry< ST > *feat_vec, INT num, bool free)
LONG get_num_nonzero_entries ()
DREALcompute_squared (DREAL *sq)
DREAL compute_squared_norm (CSparseFeatures< DREAL > *lhs, DREAL *sq_lhs, INT idx_a, CSparseFeatures< DREAL > *rhs, DREAL *sq_rhs, INT idx_b)
CLabelsload_svmlight_file (CHAR *fname)
bool write_svmlight_file (CHAR *fname, CLabels *label)
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
template<>
EFeatureType get_feature_type ()
virtual INT add_preproc (CPreProc *p)
 set preprocessor
virtual CPreProcdel_preproc (INT num)
 del current preprocessor
CPreProcget_preproc (INT num)
 get current preprocessor
void set_preprocessed (INT num)
bool is_preprocessed (INT num)
INT get_num_preprocessed ()
 get whether specified preprocessor (or all if num=1) was/were already applied
INT get_num_preproc ()
void clean_preprocs ()
 clears all preprocs
INT get_cache_size ()
virtual bool reshape (INT num_features, INT num_vectors)
void list_feature_obj ()
virtual bool load (CHAR *fname)
virtual bool save (CHAR *fname)
bool check_feature_compatibility (CFeatures *f)

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version

Protected Member Functions

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

Protected Attributes

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

Constructor & Destructor Documentation

template<class ST>
CSparseFeatures< ST >::CSparseFeatures ( INT  size = 0  ) 

constructor

Parameters:
size cache size

Definition at line 64 of file SparseFeatures.h.

template<class ST>
CSparseFeatures< ST >::CSparseFeatures ( const CSparseFeatures< ST > &  orig  ) 

copy constructor

Definition at line 70 of file SparseFeatures.h.

template<class ST>
CSparseFeatures< ST >::CSparseFeatures ( CHAR fname  ) 

constructor

Parameters:
fname filename to load features from

Definition at line 94 of file SparseFeatures.h.

template<class ST>
virtual CSparseFeatures< ST >::~CSparseFeatures (  )  [virtual]

Definition at line 99 of file SparseFeatures.h.


Member Function Documentation

template<class ST>
void CSparseFeatures< ST >::free_sparse_feature_matrix (  ) 

free sparse feature matrix

Definition at line 107 of file SparseFeatures.h.

template<class ST>
void CSparseFeatures< ST >::free_sparse_features (  ) 

free sparse feature matrix and cache

Definition at line 118 of file SparseFeatures.h.

template<class ST>
virtual CFeatures* CSparseFeatures< ST >::duplicate (  )  const [virtual]

duplicate feature object

Returns:
feature object

Implements CFeatures.

Definition at line 129 of file SparseFeatures.h.

template<class ST>
ST* CSparseFeatures< ST >::get_full_feature_vector ( INT  num,
INT len 
)

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

Parameters:
num index of feature vector
len length is returned by reference
Returns:
dense feature vector

Definition at line 142 of file SparseFeatures.h.

template<class ST>
INT CSparseFeatures< ST >::get_num_sparse_vec_features ( INT  num  ) 

get number of sparse features in vector

Parameters:
num which vector
Returns:
number of sparse features in vector

Definition at line 174 of file SparseFeatures.h.

template<class ST>
TSparseEntry<ST>* CSparseFeatures< ST >::get_sparse_feature_vector ( INT  num,
INT 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

Parameters:
num index of feature vector
len number of sparse entries is returned by reference
vfree whether returned vector must be freed by caller via free_sparse_feature_vector
Returns:
sparse feature vector

Definition at line 193 of file SparseFeatures.h.

template<class ST>
ST CSparseFeatures< ST >::sparse_dot ( ST  alpha,
TSparseEntry< ST > *  avec,
INT  alen,
TSparseEntry< ST > *  bvec,
INT  blen 
)

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

Parameters:
alpha scalar to multiply with
avec first sparse feature vector
alen avec's length
bvec second sparse feature vector
blen bvec's length
Returns:
dot product between the two sparse feature vectors

Definition at line 261 of file SparseFeatures.h.

template<class ST>
void CSparseFeatures< ST >::dense_dot_range ( ST *  output,
INT  start,
INT  stop,
ST *  alphas,
ST *  vec,
INT  dim,
ST  b 
)

compute the dot product for a range of vectors alphas[i] * sparse[i]^T * w + b

Parameters:
output result for the given vector range
start start vector range from this idx
stop stop vector range at this idx
alphas scalars to multiply with
vec dense vector to compute dot product with
dim length of the dense vector
b bias

Definition at line 320 of file SparseFeatures.h.

template<class ST>
ST CSparseFeatures< ST >::dense_dot ( ST  alpha,
INT  num,
ST *  vec,
INT  dim,
ST  b 
)

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

Parameters:
alpha scalar to multiply with
num index of feature vector
vec dense vector to compute dot product with
dim length of the dense vector
b bias
Returns:
dot product between dense weights and a sparse feature vector

Definition at line 340 of file SparseFeatures.h.

template<class ST>
void CSparseFeatures< ST >::add_to_dense_vec ( ST  alpha,
INT  num,
ST *  vec,
INT  dim,
bool  abs_val = false 
)

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

Parameters:
alpha scalar to multiply with
num index of feature vector
vec dense vector
dim length of the dense vector
abs_val if true, do dense+=alpha*abs(sparse)

Definition at line 369 of file SparseFeatures.h.

template<class ST>
void CSparseFeatures< ST >::free_sparse_feature_vector ( TSparseEntry< ST > *  feat_vec,
INT  num,
bool  free 
)

free sparse feature vector

Parameters:
feat_vec feature vector to free
num index of this vector in the cache
free if vector should be really deleted

Definition at line 401 of file SparseFeatures.h.

template<class ST>
TSparse<ST>* CSparseFeatures< ST >::get_sparse_feature_matrix ( INT num_feat,
INT num_vec 
)

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

Parameters:
num_feat number of features in matrix
num_vec number of vectors in matrix
Returns:
feature matrix

Definition at line 417 of file SparseFeatures.h.

template<class ST>
void CSparseFeatures< ST >::clean_tsparse ( TSparse< ST > *  sfm,
INT  num_vec 
)

clean TSparse

Parameters:
sfm sparse feature matrix
num_vec number of vectors in matrix

Definition at line 430 of file SparseFeatures.h.

template<class ST>
TSparse<ST>* CSparseFeatures< ST >::get_transposed ( INT num_feat,
INT 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

Parameters:
num_feat number of features in matrix
num_vec number of vectors in matrix
Returns:
transposed sparse feature matrix

Definition at line 450 of file SparseFeatures.h.

template<class ST>
virtual void CSparseFeatures< ST >::set_sparse_feature_matrix ( TSparse< ST > *  sfm,
INT  num_feat,
INT  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

Parameters:
sfm new sparse feature matrix
num_feat number of features in matrix
num_vec number of vectors in matrix

Definition at line 513 of file SparseFeatures.h.

template<class ST>
ST* CSparseFeatures< ST >::get_full_feature_matrix ( INT num_feat,
INT num_vec 
)

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

Parameters:
num_feat number of features in matrix
num_vec number of vectors in matrix
Returns:
full feature matrix

Definition at line 529 of file SparseFeatures.h.

template<class ST>
virtual bool CSparseFeatures< ST >::set_full_feature_matrix ( ST *  ffm,
INT  num_feat,
INT  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

Parameters:
ffm full feature matrix
num_feat number of features in matrix
num_vec number of vectors in matrix

Definition at line 566 of file SparseFeatures.h.

template<class ST>
virtual bool CSparseFeatures< ST >::apply_preproc ( bool  force_preprocessing = false  )  [virtual]

apply preprocessor

Parameters:
force_preprocessing if preprocssing shall be forced
Returns:
if applying was successful

Definition at line 655 of file SparseFeatures.h.

template<class ST>
virtual INT CSparseFeatures< ST >::get_size (  )  [virtual]

get memory footprint of one feature

Returns:
memory footprint of one feature

Implements CFeatures.

Definition at line 685 of file SparseFeatures.h.

template<class ST>
bool CSparseFeatures< ST >::obtain_from_simple ( CSimpleFeatures< ST > *  sf  ) 

obtain sparse features from simple features

Parameters:
sf simple features
Returns:
if obtaining was successful

Definition at line 692 of file SparseFeatures.h.

template<class ST>
virtual INT CSparseFeatures< ST >::get_num_vectors (  )  [virtual]

get number of feature vectors

Returns:
number of feature vectors

Implements CFeatures.

Definition at line 706 of file SparseFeatures.h.

template<class ST>
INT CSparseFeatures< ST >::get_num_features (  ) 

get number of features

Returns:
number of features

Definition at line 712 of file SparseFeatures.h.

template<class ST>
INT CSparseFeatures< ST >::set_num_features ( INT  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

Parameters:
num the number of features, must be larger than the current number of features
Returns:
previous number of features

Definition at line 725 of file SparseFeatures.h.

template<class ST>
virtual EFeatureClass CSparseFeatures< ST >::get_feature_class (  )  [virtual]

get feature class

Returns:
feature class SPARSE

Implements CFeatures.

Definition at line 737 of file SparseFeatures.h.

template<class ST>
virtual EFeatureType CSparseFeatures< ST >::get_feature_type (  )  [virtual]

get feature type

Returns:
templated feature type

Implements CFeatures.

template<class ST>
void CSparseFeatures< ST >::free_feature_vector ( TSparseEntry< ST > *  feat_vec,
INT  num,
bool  free 
)

free feature vector

Parameters:
feat_vec feature vector to free
num index of vector in cache
free if vector really should be deleted

Definition at line 751 of file SparseFeatures.h.

template<class ST>
LONG CSparseFeatures< ST >::get_num_nonzero_entries (  ) 

get number of non-zero entries in sparse feature matrix

Returns:
number of non-zero entries in sparse feature matrix

Definition at line 764 of file SparseFeatures.h.

template<class ST>
DREAL* CSparseFeatures< ST >::compute_squared ( DREAL sq  ) 

compute a^2 on all feature vectors

Parameters:
sq the square for each vector is stored in here
Returns:
the square for each vector

Definition at line 778 of file SparseFeatures.h.

template<class ST>
DREAL CSparseFeatures< ST >::compute_squared_norm ( CSparseFeatures< DREAL > *  lhs,
DREAL sq_lhs,
INT  idx_a,
CSparseFeatures< DREAL > *  rhs,
DREAL sq_rhs,
INT  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.

Parameters:
lhs left-hand side features
sq_lhs squared values of left-hand side
idx_a index of left-hand side's vector to compute
rhs right-hand side features
sq_rhs squared values of right-hand side
idx_b index of right-hand side's vector to compute

Definition at line 811 of file SparseFeatures.h.

template<class ST>
CLabels* CSparseFeatures< ST >::load_svmlight_file ( CHAR fname  ) 

load features from file

Parameters:
fname filename to load from
Returns:
label object with corresponding labels

Definition at line 872 of file SparseFeatures.h.

template<class ST>
bool CSparseFeatures< ST >::write_svmlight_file ( CHAR fname,
CLabels label 
)

write features to file using svm light format

Parameters:
fname filename to write to
label Label object (number of labels must correspond to number of features)
Returns:
true if successful

Definition at line 1040 of file SparseFeatures.h.

template<class ST>
virtual TSparseEntry<ST>* CSparseFeatures< ST >::compute_sparse_feature_vector ( INT  num,
INT 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!

Parameters:
num num
len len
target target

Definition at line 1084 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< CHAR >::get_feature_type (  )  [virtual]

get feature type the CHAR feature can deal with

Returns:
feature type CHAR

Implements CFeatures.

Definition at line 1110 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< BYTE >::get_feature_type (  )  [virtual]

get feature type the BYTE feature can deal with

Returns:
feature type BYTE

Implements CFeatures.

Definition at line 1119 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< SHORT >::get_feature_type (  )  [virtual]

get feature type the SHORT feature can deal with

Returns:
feature type SHORT

Implements CFeatures.

Definition at line 1128 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< WORD >::get_feature_type (  )  [virtual]

get feature type the WORD feature can deal with

Returns:
feature type WORD

Implements CFeatures.

Definition at line 1137 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< INT >::get_feature_type (  )  [virtual]

get feature type the INT feature can deal with

Returns:
feature type INT

Implements CFeatures.

Definition at line 1146 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< UINT >::get_feature_type (  )  [virtual]

get feature type the UINT feature can deal with

Returns:
feature type UINT

Implements CFeatures.

Definition at line 1155 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< LONG >::get_feature_type (  )  [virtual]

get feature type the LONG feature can deal with

Returns:
feature type LONG

Implements CFeatures.

Definition at line 1164 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< ULONG >::get_feature_type (  )  [virtual]

get feature type the ULONG feature can deal with

Returns:
feature type ULONG

Implements CFeatures.

Definition at line 1173 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< DREAL >::get_feature_type (  )  [virtual]

get feature type the DREAL feature can deal with

Returns:
feature type DREAL

Implements CFeatures.

Definition at line 1182 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< SHORTREAL >::get_feature_type (  )  [virtual]

get feature type the SHORTREAL feature can deal with

Returns:
feature type SHORTREAL

Implements CFeatures.

Definition at line 1191 of file SparseFeatures.h.

template<>
EFeatureType CSparseFeatures< LONGREAL >::get_feature_type (  )  [virtual]

get feature type the LONGREAL feature can deal with

Returns:
feature type LONGREAL

Implements CFeatures.

Definition at line 1200 of file SparseFeatures.h.

INT CFeatures::add_preproc ( CPreProc p  )  [virtual, inherited]

set preprocessor

add preprocessor

Parameters:
p preprocessor to set
Returns:
something inty

Definition at line 48 of file Features.cpp.

CPreProc * CFeatures::del_preproc ( INT  num  )  [virtual, inherited]

del current preprocessor

delete preprocessor from list caller has to clean up returned preproc

Parameters:
num index of preprocessor in list

Definition at line 107 of file Features.cpp.

CPreProc * CFeatures::get_preproc ( INT  num  )  [inherited]

get current preprocessor

get specified preprocessor

Parameters:
num index of preprocessor in list

Definition at line 78 of file Features.cpp.

void CFeatures::set_preprocessed ( INT  num  )  [inherited]

set applied flag for preprocessor

Parameters:
num index of preprocessor in list

Definition at line 95 of file Features.h.

bool CFeatures::is_preprocessed ( INT  num  )  [inherited]

get whether specified preprocessor was already applied

Parameters:
num index of preprocessor in list

Definition at line 101 of file Features.h.

INT CFeatures::get_num_preprocessed (  )  [inherited]

get whether specified preprocessor (or all if num=1) was/were already applied

get the number of applied preprocs

Returns:
number of applied preprocessors

Definition at line 87 of file Features.cpp.

INT CFeatures::get_num_preproc (  )  [inherited]

get number of preprocessors

Returns:
number of preprocessors

Definition at line 113 of file Features.h.

void CFeatures::clean_preprocs (  )  [inherited]

clears all preprocs

clears all preprocs

Definition at line 101 of file Features.cpp.

INT CFeatures::get_cache_size (  )  [inherited]

get cache size

Returns:
cache size

Definition at line 122 of file Features.h.

virtual bool CFeatures::reshape ( INT  num_features,
INT  num_vectors 
) [virtual, inherited]

in case there is a feature matrix allow for reshaping

NOT IMPLEMENTED!

Parameters:
num_features new number of features
num_vectors new number of vectors
Returns:
if reshaping was succesful

Reimplemented in CSimpleFeatures< ST >, CSimpleFeatures< double >, CSimpleFeatures< float >, CSimpleFeatures< int >, CSimpleFeatures< short int >, CSimpleFeatures< unsigned char >, CSimpleFeatures< char >, and CSimpleFeatures< unsigned short int >.

Definition at line 140 of file Features.h.

void CFeatures::list_feature_obj (  )  [inherited]

list feature object

Definition at line 152 of file Features.cpp.

bool CFeatures::load ( CHAR fname  )  [virtual, inherited]

load features from file

Parameters:
fname filename to load from
Returns:
if loading was successful

Reimplemented in CByteFeatures, CCharFeatures, CIntFeatures, CRealFeatures, CShortFeatures, CShortRealFeatures, CStringFeatures< ST >, CWordFeatures, CStringFeatures< unsigned char >, and CStringFeatures< unsigned short int >.

Definition at line 213 of file Features.cpp.

bool CFeatures::save ( CHAR fname  )  [virtual, inherited]

save features to file

Parameters:
fname filename to save to
Returns:
if saving was successful

Reimplemented in CByteFeatures, CCharFeatures, CIntFeatures, CRealFeatures, CShortFeatures, CShortRealFeatures, CStringFeatures< ST >, CWordFeatures, CStringFeatures< unsigned char >, and CStringFeatures< unsigned short int >.

Definition at line 218 of file Features.cpp.

bool CFeatures::check_feature_compatibility ( CFeatures f  )  [inherited]

check feature compatibility

Parameters:
f features to check for compatibility
Returns:
if features are compatible

Definition at line 223 of file Features.cpp.


Member Data Documentation

template<class ST>
INT CSparseFeatures< ST >::num_vectors [protected]

total number of vectors

Definition at line 1093 of file SparseFeatures.h.

template<class ST>
INT CSparseFeatures< ST >::num_features [protected]

total number of features

Definition at line 1096 of file SparseFeatures.h.

template<class ST>
TSparse<ST>* CSparseFeatures< ST >::sparse_feature_matrix [protected]

array of sparse vectors of size num_vectors

Definition at line 1099 of file SparseFeatures.h.

template<class ST>
CCache< TSparseEntry<ST> >* CSparseFeatures< ST >::feature_cache [protected]

feature cache

Definition at line 1102 of file SparseFeatures.h.

CParallel CSGObject::parallel [static, inherited]

Definition at line 105 of file SGObject.h.

CIO CSGObject::io [static, inherited]

Definition at line 106 of file SGObject.h.

CVersion CSGObject::version [static, inherited]

Definition at line 107 of file SGObject.h.


The documentation for this class was generated from the following file:

SHOGUN Machine Learning Toolbox - Documentation