SHOGUN  v3.1.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseFeatures.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2010 Soeren Sonnenburg
8  * Written (W) 1999-2008 Gunnar Raetsch
9  * Written (W) 2011-2013 Heiko Strathmann
10  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
11  * Copyright (C) 2010 Berlin Institute of Technology
12  */
13 
14 #ifndef _DENSEFEATURES__H__
15 #define _DENSEFEATURES__H__
16 
17 #include <shogun/lib/common.h>
18 #include <shogun/lib/Cache.h>
19 #include <shogun/io/File.h>
22 #include <shogun/lib/DataType.h>
23 
24 namespace shogun {
25 template<class ST> class CStringFeatures;
26 template<class ST> class CDenseFeatures;
27 template<class ST> class SGMatrix;
28 class CDotFeatures;
29 
65 template<class ST> class CDenseFeatures: public CDotFeatures
66 {
67 public:
72  CDenseFeatures(int32_t size = 0);
73 
75  CDenseFeatures(const CDenseFeatures & orig);
76 
82 
89  CDenseFeatures(ST* src, int32_t num_feat, int32_t num_vec);
90 
95  CDenseFeatures(CFile* loader);
96 
101  virtual CFeatures* duplicate() const;
102 
103  virtual ~CDenseFeatures();
104 
109  void free_feature_matrix();
110 
115  void free_features();
116 
128  ST* get_feature_vector(int32_t num, int32_t& len, bool& dofree);
129 
137  void set_feature_vector(SGVector<ST> vector, int32_t num);
138 
146  SGVector<ST> get_feature_vector(int32_t num);
147 
156  void free_feature_vector(ST* feat_vec, int32_t num, bool dofree);
157 
165  void free_feature_vector(SGVector<ST> vec, int32_t num);
166 
180  void vector_subset(int32_t* idx, int32_t idx_len);
181 
195  void feature_subset(int32_t* idx, int32_t idx_len);
196 
205 
213 
225  void set_feature_matrix(SGMatrix<ST> matrix);
226 
236  ST* get_feature_matrix(int32_t &num_feat, int32_t &num_vec);
237 
245 
257  ST* get_transposed(int32_t &num_feat, int32_t &num_vec);
258 
268  virtual void copy_feature_matrix(SGMatrix<ST> src);
269 
276  void obtain_from_dot(CDotFeatures* df);
277 
288  virtual bool apply_preprocessor(bool force_preprocessing = false);
289 
294  virtual int32_t get_num_vectors() const;
295 
300  int32_t get_num_features() const;
301 
306  void set_num_features(int32_t num);
307 
314  void set_num_vectors(int32_t num);
315 
320  void initialize_cache();
321 
326  virtual EFeatureClass get_feature_class() const;
327 
332  virtual EFeatureType get_feature_type() const;
333 
342  virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors);
343 
351  virtual int32_t get_dim_feature_space() const;
352 
362  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
363  int32_t vec_idx2);
364 
373  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
374  int32_t vec2_len);
375 
386  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
387  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
388 
394  virtual int32_t get_nnz_features_for_vector(int32_t num);
395 
400  virtual void load(CFile* loader);
401 
406  virtual void save(CFile* saver);
407 
408 #ifndef DOXYGEN_SHOULD_SKIP_THIS
409 
410  struct dense_feature_iterator
411  {
413  ST* vec;
415  int32_t vidx;
417  int32_t vlen;
419  bool vfree;
420 
422  int32_t index;
423  };
424 #endif
425 
437  virtual void* get_feature_iterator(int32_t vector_index);
438 
451  virtual bool get_next_feature(int32_t& index, float64_t& value,
452  void* iterator);
453 
459  virtual void free_feature_iterator(void* iterator);
460 
469  virtual CFeatures* copy_subset(SGVector<index_t> indices);
470 
477  virtual bool is_equal(CDenseFeatures* rhs);
478 
488 
496 
500  static CDenseFeatures* obtain_from_generic(CFeatures* const base_features);
501 
503  virtual const char* get_name() const { return "DenseFeatures"; }
504 
505 protected:
517  virtual ST* compute_feature_vector(int32_t num, int32_t& len,
518  ST* target = NULL);
519 
520 private:
521  void init();
522 
523 protected:
525  int32_t num_vectors;
526 
528  int32_t num_features;
529 
535 
538 };
539 }
540 #endif // _DENSEFEATURES__H__
virtual int32_t get_dim_feature_space() const
SGMatrix< ST > get_feature_matrix()
void set_feature_matrix(SGMatrix< ST > matrix)
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
virtual CFeatures * copy_subset(SGVector< index_t > indices)
void set_num_vectors(int32_t num)
int32_t num_features
number of features in cache
CDenseFeatures(int32_t size=0)
void set_feature_vector(SGVector< ST > vector, int32_t num)
void feature_subset(int32_t *idx, int32_t idx_len)
void obtain_from_dot(CDotFeatures *df)
virtual void * get_feature_iterator(int32_t vector_index)
virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors)
virtual EFeatureType get_feature_type() const
virtual bool is_equal(CDenseFeatures *rhs)
int32_t get_num_features() const
Features that support dot products among other operations.
Definition: DotFeatures.h:41
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:35
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
int32_t num_vectors
number of vectors in cache
SGMatrix< ST > feature_matrix
double float64_t
Definition: common.h:48
virtual const char * get_name() const
virtual void copy_feature_matrix(SGMatrix< ST > src)
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
A File access base class.
Definition: File.h:34
virtual bool apply_preprocessor(bool force_preprocessing=false)
CCache< ST > * feature_cache
CDenseFeatures< ST > * get_transposed()
SGMatrix< ST > steal_feature_matrix()
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
virtual CFeatures * duplicate() const
void set_num_features(int32_t num)
The class DenseFeatures implements dense feature matrices.
Definition: LDA.h:24
shogun matrix
Definition: DenseFeatures.h:27
virtual EFeatureClass get_feature_class() const
static CDenseFeatures * obtain_from_generic(CFeatures *const base_features)
void vector_subset(int32_t *idx, int32_t idx_len)
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual void save(CFile *saver)
virtual void load(CFile *loader)
virtual ST * compute_feature_vector(int32_t num, int32_t &len, ST *target=NULL)
virtual int32_t get_nnz_features_for_vector(int32_t num)
virtual int32_t get_num_vectors() const
CFeatures * create_merged_copy(CList *other)
Class List implements a doubly connected list for low-level-objects.
Definition: List.h:82
virtual void free_feature_iterator(void *iterator)

SHOGUN Machine Learning Toolbox - Documentation