67 "get_feature(num=%d,index=%d): index exceeds [0;%d]\n",
96 "get_sparse_feature_vector(num=%d): num exceeds [0;%d]\n",
137 SG_FREE(tmp_feat_before);
138 tmp_feat_before=tmp_feat_after;
143 memcpy(result.
features, tmp_feat_after,
146 SG_FREE(tmp_feat_after);
158 ST result = sv.
dense_dot(alpha,vec,dim,b);
165 REQUIRE(vec,
"add_to_dense_vec(num=%d,dim=%d): vec must not be NULL\n",
168 "add_to_dense_vec(num=%d,dim=%d): dim should contain number of features %d\n",
198 int32_t num,
float64_t* vec, int32_t dim,
bool abs_val)
214 SG_ERROR(
"Not allowed with subset\n");
222 SG_ERROR(
"Not allowed with subset\n");
230 SG_ERROR(
"Not allowed with subset\n");
238 "sparse_matrix[%d] check failed (matrix features %d >= vector dimension %d)\n",
248 SG_INFO(
"converting sparse features to full feature matrix of %d x %d" 251 for (int32_t v=0; v<full.
num_cols; v++)
288 SG_INFO(
"force: %d\n", force_preprocessing)
307 SG_WARNING(
"no sparse feature matrix available or features already preprocessed - skipping.\n")
359 for (int32_t i=0; i<num_vec; i++)
370 for (int32_t i=0; i<num_vec; i++)
403 float64_t result=sq_lhs[idx_a]+sq_rhs[idx_b];
468 sf->free_sparse_feature_vector(vec_idx2);
482 REQUIRE(vec2,
"dense_dot(vec_idx1=%d,vec2_len=%d): vec2 must not be NULL\n",
485 "dense_dot(vec_idx1=%d,vec2_len=%d): vec2_len should contain number of features %d %d\n",
494 "sparse_matrix[%d] check failed (matrix features %d >= vector dimension %d)\n",
498 "sparse_matrix[%d] check failed (dense vector dimension %d >= vector dimension %d)\n",
521 SG_ERROR(
"Index out of bounds (number of vectors %d, you " 526 SG_ERROR(
"Requires a in-memory feature matrix\n")
528 sparse_feature_iterator* it=
new sparse_feature_iterator();
531 it->vector_index=vector_index;
538 sparse_feature_iterator* it=(sparse_feature_iterator*) iterator;
539 if (!it || it->index>=it->sv.num_feat_entries)
542 int32_t i=it->index++;
544 index=it->sv.features[i].feat_index;
545 value=(
float64_t) it->sv.features[i].entry;
562 delete ((sparse_feature_iterator*) iterator);
606 "sparse_feature_matrix",
607 "Array of sparse vectors.");
609 "Total number of features.");
612 #define GET_FEATURE_TYPE(sg_type, f_type) \ 613 template<> EFeatureType CSparseFeatures<sg_type>::get_feature_type() const \ 631 #undef GET_FEATURE_TYPE 652 SG_ERROR(
"Not allowed with subset\n");
660 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()
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 EFeatureClass get_feature_class() const =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 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 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 const char * get_name() const
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)
virtual EFeatureType get_feature_type() const =0
static T abs(T a)
return the absolute value of a number
SGSparseVectorEntry< T > * features