
Public Member Functions | |
| CSparseFeatures (int32_t size=0) | |
| CSparseFeatures (const CSparseFeatures &orig) | |
| CSparseFeatures (char *fname) | |
| virtual | ~CSparseFeatures () |
| void | free_sparse_feature_matrix () |
| void | free_sparse_features () |
| virtual CFeatures * | duplicate () const |
| ST * | get_full_feature_vector (int32_t num, int32_t &len) |
| int32_t | get_num_sparse_vec_features (int32_t num) |
| TSparseEntry< ST > * | get_sparse_feature_vector (int32_t num, int32_t &len, bool &vfree) |
| ST | sparse_dot (ST alpha, TSparseEntry< ST > *avec, int32_t alen, TSparseEntry< ST > *bvec, int32_t blen) |
| void | dense_dot_range (ST *output, int32_t start, int32_t stop, ST *alphas, ST *vec, int32_t dim, ST b) |
| ST | dense_dot (ST alpha, int32_t num, ST *vec, int32_t dim, ST b) |
| void | add_to_dense_vec (ST alpha, int32_t num, ST *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 | clean_tsparse (TSparse< ST > *sfm, int32_t num_vec) |
| TSparse< ST > * | get_transposed (int32_t &num_feat, int32_t &num_vec) |
| virtual void | set_sparse_feature_matrix (TSparse< ST > *sfm, int32_t num_feat, int32_t num_vec) |
| ST * | get_full_feature_matrix (int32_t &num_feat, int32_t &num_vec) |
| virtual bool | set_full_feature_matrix (ST *ffm, 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_t * | compute_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) |
| CLabels * | load_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 () |
Protected Member Functions | |
| virtual TSparseEntry< ST > * | compute_sparse_feature_vector (int32_t num, int32_t &len, TSparseEntry< ST > *target=NULL) |
Protected Attributes | |
| 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 |
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.
Definition at line 65 of file SparseFeatures.h.
| CSparseFeatures< ST >::CSparseFeatures | ( | int32_t | size = 0 |
) |
| CSparseFeatures< ST >::CSparseFeatures | ( | const CSparseFeatures< ST > & | orig | ) |
copy constructor
Definition at line 78 of file SparseFeatures.h.
| CSparseFeatures< ST >::CSparseFeatures | ( | char * | fname | ) |
constructor
| fname | filename to load features from |
Definition at line 102 of file SparseFeatures.h.
| virtual CSparseFeatures< ST >::~CSparseFeatures | ( | ) | [virtual] |
Definition at line 107 of file SparseFeatures.h.
| void CSparseFeatures< ST >::add_to_dense_vec | ( | ST | alpha, | |
| int32_t | num, | |||
| ST * | vec, | |||
| int32_t | dim, | |||
| bool | abs_val = false | |||
| ) |
add a sparse feature vector onto a dense one dense+=alpha*sparse
| 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 377 of file SparseFeatures.h.
| virtual bool CSparseFeatures< ST >::apply_preproc | ( | bool | force_preprocessing = false |
) | [virtual] |
apply preprocessor
| force_preprocessing | if preprocssing shall be forced |
Definition at line 663 of file SparseFeatures.h.
| void CSparseFeatures< ST >::clean_tsparse | ( | TSparse< ST > * | sfm, | |
| int32_t | num_vec | |||
| ) |
clean TSparse
| sfm | sparse feature matrix | |
| num_vec | number of vectors in matrix |
Definition at line 438 of file SparseFeatures.h.
| virtual TSparseEntry<ST>* CSparseFeatures< 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!
| num | num | |
| len | len | |
| target | target |
Definition at line 1092 of file SparseFeatures.h.
| float64_t* CSparseFeatures< ST >::compute_squared | ( | float64_t * | sq | ) |
compute a^2 on all feature vectors
| sq | the square for each vector is stored in here |
Definition at line 786 of file SparseFeatures.h.
| float64_t CSparseFeatures< ST >::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.
| 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 819 of file SparseFeatures.h.
| ST CSparseFeatures< 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
| 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 |
Definition at line 348 of file SparseFeatures.h.
| void CSparseFeatures< ST >::dense_dot_range | ( | ST * | output, | |
| int32_t | start, | |||
| int32_t | stop, | |||
| ST * | alphas, | |||
| ST * | vec, | |||
| int32_t | dim, | |||
| ST | b | |||
| ) |
compute the dot product for a range of vectors alphas[i] * sparse[i]^T * w + b
| 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 328 of file SparseFeatures.h.
| virtual CFeatures* CSparseFeatures< ST >::duplicate | ( | ) | const [virtual] |
duplicate feature object
Implements CFeatures.
Definition at line 137 of file SparseFeatures.h.
| void CSparseFeatures< ST >::free_feature_vector | ( | TSparseEntry< ST > * | feat_vec, | |
| int32_t | num, | |||
| bool | free | |||
| ) |
free feature vector
| feat_vec | feature vector to free | |
| num | index of vector in cache | |
| free | if vector really should be deleted |
Definition at line 759 of file SparseFeatures.h.
| void CSparseFeatures< ST >::free_sparse_feature_matrix | ( | ) |
free sparse feature matrix
Definition at line 115 of file SparseFeatures.h.
| void CSparseFeatures< ST >::free_sparse_feature_vector | ( | TSparseEntry< ST > * | feat_vec, | |
| int32_t | num, | |||
| bool | free | |||
| ) |
free sparse feature vector
| feat_vec | feature vector to free | |
| num | index of this vector in the cache | |
| free | if vector should be really deleted |
Definition at line 409 of file SparseFeatures.h.
| void CSparseFeatures< ST >::free_sparse_features | ( | ) |
free sparse feature matrix and cache
Definition at line 126 of file SparseFeatures.h.
| virtual EFeatureClass CSparseFeatures< ST >::get_feature_class | ( | ) | [virtual] |
get feature class
Implements CFeatures.
Definition at line 745 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< float128_t >::get_feature_type | ( | ) | [virtual] |
get feature type the LONGREAL feature can deal with
Implements CFeatures.
Definition at line 1208 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< float32_t >::get_feature_type | ( | ) | [virtual] |
get feature type the SHORTREAL feature can deal with
Implements CFeatures.
Definition at line 1199 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< uint64_t >::get_feature_type | ( | ) | [virtual] |
get feature type the ULONG feature can deal with
Implements CFeatures.
Definition at line 1181 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< int64_t >::get_feature_type | ( | ) | [virtual] |
get feature type the LONG feature can deal with
Implements CFeatures.
Definition at line 1172 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< uint32_t >::get_feature_type | ( | ) | [virtual] |
get feature type the UINT feature can deal with
Implements CFeatures.
Definition at line 1163 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< int32_t >::get_feature_type | ( | ) | [virtual] |
get feature type the INT feature can deal with
Implements CFeatures.
Definition at line 1154 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< uint16_t >::get_feature_type | ( | ) | [virtual] |
get feature type the WORD feature can deal with
Implements CFeatures.
Definition at line 1145 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< int16_t >::get_feature_type | ( | ) | [virtual] |
get feature type the SHORT feature can deal with
Implements CFeatures.
Definition at line 1136 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< uint8_t >::get_feature_type | ( | ) | [virtual] |
get feature type the BYTE feature can deal with
Implements CFeatures.
Definition at line 1127 of file SparseFeatures.h.
| EFeatureType CSparseFeatures< char >::get_feature_type | ( | ) | [virtual] |
get feature type the CHAR feature can deal with
Implements CFeatures.
Definition at line 1118 of file SparseFeatures.h.
| virtual EFeatureType CSparseFeatures< ST >::get_feature_type | ( | ) | [virtual] |
| ST* CSparseFeatures< 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_feat | number of features in matrix | |
| num_vec | number of vectors in matrix |
Definition at line 537 of file SparseFeatures.h.
| ST* CSparseFeatures< 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
| num | index of feature vector | |
| len | length is returned by reference |
Definition at line 150 of file SparseFeatures.h.
| int32_t CSparseFeatures< ST >::get_num_features | ( | ) |
| int64_t CSparseFeatures< ST >::get_num_nonzero_entries | ( | ) |
get number of non-zero entries in sparse feature matrix
Definition at line 772 of file SparseFeatures.h.
| int32_t CSparseFeatures< ST >::get_num_sparse_vec_features | ( | int32_t | num | ) |
get number of sparse features in vector
| num | which vector |
Definition at line 182 of file SparseFeatures.h.
| virtual int32_t CSparseFeatures< ST >::get_num_vectors | ( | ) | [virtual] |
get number of feature vectors
Implements CFeatures.
Definition at line 714 of file SparseFeatures.h.
| virtual int32_t CSparseFeatures< ST >::get_size | ( | ) | [virtual] |
get memory footprint of one feature
Implements CFeatures.
Definition at line 693 of file SparseFeatures.h.
| TSparse<ST>* CSparseFeatures< 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_feat | number of features in matrix | |
| num_vec | number of vectors in matrix |
Definition at line 425 of file SparseFeatures.h.
| TSparseEntry<ST>* CSparseFeatures< 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
| 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 |
Definition at line 201 of file SparseFeatures.h.
| TSparse<ST>* CSparseFeatures< 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_feat | number of features in matrix | |
| num_vec | number of vectors in matrix |
Definition at line 458 of file SparseFeatures.h.
| CLabels* CSparseFeatures< ST >::load_svmlight_file | ( | char * | fname | ) |
load features from file
| fname | filename to load from |
Definition at line 880 of file SparseFeatures.h.
| bool CSparseFeatures< ST >::obtain_from_simple | ( | CSimpleFeatures< ST > * | sf | ) |
obtain sparse features from simple features
| sf | simple features |
Definition at line 700 of file SparseFeatures.h.
| virtual bool CSparseFeatures< ST >::set_full_feature_matrix | ( | ST * | ffm, | |
| 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
| ffm | full feature matrix | |
| num_feat | number of features in matrix | |
| num_vec | number of vectors in matrix |
Definition at line 574 of file SparseFeatures.h.
| int32_t CSparseFeatures< ST >::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
| num | the number of features, must be larger than the current number of features |
Definition at line 733 of file SparseFeatures.h.
| virtual void CSparseFeatures< ST >::set_sparse_feature_matrix | ( | TSparse< ST > * | sfm, | |
| 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
| sfm | new sparse feature matrix | |
| num_feat | number of features in matrix | |
| num_vec | number of vectors in matrix |
Definition at line 521 of file SparseFeatures.h.
| ST CSparseFeatures< ST >::sparse_dot | ( | ST | alpha, | |
| TSparseEntry< ST > * | avec, | |||
| int32_t | alen, | |||
| TSparseEntry< ST > * | bvec, | |||
| int32_t | blen | |||
| ) |
compute the dot product between two sparse feature vectors alpha * vec^T * vec
| alpha | scalar to multiply with | |
| avec | first sparse feature vector | |
| alen | avec's length | |
| bvec | second sparse feature vector | |
| blen | bvec's length |
Definition at line 269 of file SparseFeatures.h.
| bool CSparseFeatures< ST >::write_svmlight_file | ( | char * | fname, | |
| CLabels * | label | |||
| ) |
write features to file using svm light format
| fname | filename to write to | |
| label | Label object (number of labels must correspond to number of features) |
Definition at line 1048 of file SparseFeatures.h.
CCache< TSparseEntry<ST> >* CSparseFeatures< ST >::feature_cache [protected] |
feature cache
Definition at line 1110 of file SparseFeatures.h.
int32_t CSparseFeatures< ST >::num_features [protected] |
int32_t CSparseFeatures< ST >::num_vectors [protected] |
TSparse<ST>* CSparseFeatures< ST >::sparse_feature_matrix [protected] |