14 #ifndef _SPARSEFEATURES__H__
15 #define _SPARSEFEATURES__H__
33 template <
class ST>
class CSimpleFeatures;
52 template <
class ST>
class CSparseFeatures :
public CDotFeatures
70 int32_t num_feat, int32_t num_vec,
bool copy=
false);
172 static ST
sparse_dot(ST alpha, SGSparseVectorEntry<ST>* avec, int32_t alen,
173 SGSparseVectorEntry<ST>* bvec, int32_t blen);
187 ST
dense_dot(ST alpha, int32_t num, ST* vec, int32_t dim, ST b);
201 float64_t* vec, int32_t dim,
bool abs_val=
false);
237 static void clean_tsparse(SGSparseVector<ST>* sfm, int32_t num_vec);
258 SGSparseVector<ST>*
get_transposed(int32_t &num_feat, int32_t &num_vec);
389 CSparseFeatures<float64_t>* rhs,
float64_t* sq_rhs,
398 void load(CFile* loader);
406 void save(CFile* writer);
466 #ifndef DOXYGEN_SHOULD_SKIP_THIS
468 struct sparse_feature_iterator
471 SGSparseVector<ST> sv;
479 SG_SPRINT(
"sv=%p, vidx=%d, num_feat_entries=%d, index=%d\n",
480 sv.features, sv.vec_index, sv.num_feat_entries, index);
526 inline virtual const char*
get_name()
const {
return "SparseFeatures"; }
int32_t get_num_features()
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
CCache< SGSparseVectorEntry< ST > > * feature_cache
virtual CFeatures * duplicate() const
void free_feature_vector(SGSparseVector< ST > vec, int32_t num)
static ST sparse_dot(ST alpha, SGSparseVectorEntry< ST > *avec, int32_t alen, SGSparseVectorEntry< ST > *bvec, int32_t blen)
CLabels * load_svmlight_file(char *fname, bool do_sort_features=true)
CDotFeatures(int32_t size=0)
virtual ~CSparseFeatures()
CFeatures(int32_t size=0)
int32_t num_vectors
total number of vectors
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
void set_sparse_feature_matrix(SGSparseMatrix< ST > sm)
int64_t get_num_nonzero_entries()
ST * get_full_feature_vector(int32_t num, int32_t &len)
virtual EFeatureType get_feature_type()
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)
virtual void free_feature_iterator(void *iterator)
virtual int32_t get_nnz_features_for_vector(int32_t num)
virtual int32_t get_dim_feature_space() const
ST dense_dot(ST alpha, int32_t num, ST *vec, int32_t dim, ST b)
bool obtain_from_simple(CSimpleFeatures< ST > *sf)
EFeatureClass
shogun feature class
void free_sparse_feature_matrix()
template class SGSparseVector
SGSparseMatrix< ST > get_sparse_feature_matrix()
virtual int32_t get_num_vectors() const
void free_sparse_features()
virtual void * get_feature_iterator(int32_t vector_index)
CSparseFeatures< ST > * get_transposed()
virtual SGSparseVectorEntry< ST > * compute_sparse_feature_vector(int32_t num, int32_t &len, SGSparseVectorEntry< ST > *target=NULL)
SGMatrix< ST > get_full_feature_matrix()
virtual bool set_full_feature_matrix(SGMatrix< ST > full)
SGSparseVector< ST > * sparse_feature_matrix
array of sparse vectors of size num_vectors
virtual EFeatureClass get_feature_class()
bool write_svmlight_file(char *fname, CLabels *label)
void add_to_dense_vec(float64_t alpha, int32_t num, float64_t *vec, int32_t dim, bool abs_val=false)
EFeatureType
shogun feature type
virtual bool apply_preprocessor(bool force_preprocessing=false)
float64_t * compute_squared(float64_t *sq)
ST get_feature(int32_t num, int32_t index)
int32_t set_num_features(int32_t num)
Template class Cache implements a simple cache.
virtual CFeatures * copy_subset(SGVector< index_t > indices)
virtual const char * get_name() const
void free_sparse_feature_vector(SGSparseVector< ST > vec, int32_t num)
int32_t num_features
total number of features
SGSparseVector< ST > get_sparse_feature_vector(int32_t num)
CSparseFeatures(int32_t size=0)
virtual int32_t get_size()
static void clean_tsparse(SGSparseVector< ST > *sfm, int32_t num_vec)