68 "get_feature(num=%d,index=%d): index exceeds [0;%d]\n",
97 "get_sparse_feature_vector(num=%d): num exceeds [0;%d]\n",
138 SG_FREE(tmp_feat_before);
139 tmp_feat_before=tmp_feat_after;
144 memcpy(result.
features, tmp_feat_after,
147 SG_FREE(tmp_feat_after);
159 ST result = sv.
dense_dot(alpha,vec,dim,b);
166 REQUIRE(vec,
"add_to_dense_vec(num=%d,dim=%d): vec must not be NULL\n",
169 "add_to_dense_vec(num=%d,dim=%d): dim should contain number of features %d\n",
199 int32_t num,
float64_t* vec, int32_t dim,
bool abs_val)
215 SG_ERROR(
"Not allowed with subset\n");
223 SG_ERROR(
"Not allowed with subset\n");
231 SG_ERROR(
"Not allowed with subset\n");
239 "sparse_matrix[%d] check failed (matrix features %d >= vector dimension %d)\n",
249 SG_INFO(
"converting sparse features to full feature matrix of %d x %d" 252 for (int32_t v=0; v<full.
num_cols; v++)
289 SG_INFO(
"force: %d\n", force_preprocessing)
314 SG_WARNING(
"no sparse feature matrix available or features already preprocessed - skipping.\n")
366 for (int32_t i=0; i<num_vec; i++)
377 for (int32_t i=0; i<num_vec; i++)
410 float64_t result=sq_lhs[idx_a]+sq_rhs[idx_b];
475 sf->free_sparse_feature_vector(vec_idx2);
489 REQUIRE(vec2,
"dense_dot(vec_idx1=%d,vec2_len=%d): vec2 must not be NULL\n",
492 "dense_dot(vec_idx1=%d,vec2_len=%d): vec2_len should contain number of features %d %d\n",
501 "sparse_matrix[%d] check failed (matrix features %d >= vector dimension %d)\n",
505 "sparse_matrix[%d] check failed (dense vector dimension %d >= vector dimension %d)\n",
528 SG_ERROR(
"Index out of bounds (number of vectors %d, you " 533 SG_ERROR(
"Requires a in-memory feature matrix\n")
535 sparse_feature_iterator* it=
new sparse_feature_iterator();
538 it->vector_index=vector_index;
545 sparse_feature_iterator* it=(sparse_feature_iterator*) iterator;
546 if (!it || it->index>=it->sv.num_feat_entries)
549 int32_t i=it->index++;
551 index=it->sv.features[i].feat_index;
552 value=(
float64_t) it->sv.features[i].entry;
569 delete ((sparse_feature_iterator*) iterator);
613 "sparse_feature_matrix",
614 "Array of sparse vectors.");
616 "Total number of features.");
619 #define GET_FEATURE_TYPE(sg_type, f_type) \ 620 template<> EFeatureType CSparseFeatures<sg_type>::get_feature_type() const \ 638 #undef GET_FEATURE_TYPE 659 SG_ERROR(
"Not allowed with subset\n");
667 SG_ERROR(
"Not allowed with subset\n");
T get_feature(int32_t index)
CSubsetStack * m_subset_stack
SGVector< float64_t > load_with_labels(CLibSVMFile *loader)
SGMatrix< ST > get_feature_matrix()
virtual EFeatureType get_feature_type() const =0
std::complex< float64_t > complex128_t
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
CCache< SGSparseVectorEntry< ST > > * feature_cache
virtual void set_full_feature_matrix(SGMatrix< ST > full)
virtual CFeatures * duplicate() const
int32_t get_num_dimensions()
virtual EFeatureClass get_feature_class() const
Template class SparsePreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CSp...
void set_preprocessed(int32_t num)
void save_with_labels(CLibSVMFile *saver, SGVector< float64_t > labels)
virtual ~CSparseFeatures()
Template class SparseFeatures implements sparse matrices.
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()
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
#define SG_NOTIMPLEMENTED
#define GET_FEATURE_TYPE(sg_type, f_type)
CPreprocessor * get_preprocessor(int32_t num) const
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)
T sparse_dot(const SGSparseVector< T > &v)
virtual void free_feature_iterator(void *iterator)
void save_with_labels(CLibSVMFile *writer, SGVector< float64_t > labels)
index_t num_vectors
total number of vectors
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)
Features that support dot products among other operations.
EFeatureClass
shogun feature class
void free_sparse_feature_matrix()
int32_t get_num_preprocessors() const
SGSparseMatrix< ST > get_sparse_feature_matrix()
void add(bool *param, const char *name, const char *description="")
virtual int32_t get_num_vectors() const
void free_feature_vector(int32_t num)
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)
bool is_preprocessed(int32_t num) const
SGMatrix< ST > get_full_feature_matrix()
A File access base class.
index_t num_features
total number of features
void from_dense(SGMatrix< T > full)
SGVector< T > get_dense(int32_t dimension)
index_t subset_idx_conversion(index_t idx) const
virtual SGSparseVector< ST > * apply_to_sparse_feature_matrix(CSparseFeatures< ST > *f)=0
void add_to_dense_vec(float64_t alpha, int32_t num, float64_t *vec, int32_t dim, bool abs_val=false)
int32_t get_num_features() const
virtual EFeatureClass get_feature_class() const =0
virtual bool apply_preprocessor(bool force_preprocessing=false)
The class DenseFeatures implements dense feature matrices.
float64_t * compute_squared(float64_t *sq)
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
all of classes and functions are contained in the shogun namespace
T dense_dot(T alpha, T *vec, int32_t dim, T b)
read sparse real valued features in svm light format e.g. -1 1:10.0 2:100.2 1000:1.3 with -1 == (optional) label and dim 1 - value 10.0 dim 2 - value 100.2 dim 1000 - value 1.3
The class Features is the base class of all feature objects.
ST get_feature(int32_t num, int32_t index)
int32_t set_num_features(int32_t num)
virtual bool has_subsets() const
virtual const char * get_name() const
return the name of the preprocessor
virtual CFeatures * copy_subset(SGVector< index_t > indices)
SGSparseMatrix< T > get_transposed()
SGVector< float64_t > load_with_labels(CLibSVMFile *libsvm_file, bool do_sort_features=true)
void obtain_from_simple(CDenseFeatures< ST > *sf)
virtual EFeatureType get_feature_type() const
SGSparseMatrix< ST > sparse_feature_matrix
array of sparse vectors of size num_vectors
SGSparseVector< ST > get_sparse_feature_vector(int32_t num)
SGVector< ST > get_full_feature_vector(int32_t num)
void free_sparse_feature_vector(int32_t num)
virtual void remove_all_subsets()
CSparseFeatures(int32_t size=0)
SGSparseVectorEntry< T > * features