SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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/config.h>
18 
19 #include <shogun/lib/common.h>
20 #include <shogun/lib/Cache.h>
21 #include <shogun/io/File.h>
24 #include <shogun/lib/DataType.h>
25 
26 #include <shogun/lib/SGMatrix.h>
27 
28 namespace shogun {
29 template<class ST> class CStringFeatures;
30 template<class ST> class CDenseFeatures;
31 template<class ST> class SGMatrix;
32 class CDotFeatures;
33 
69 template<class ST> class CDenseFeatures: public CDotFeatures
70 {
71 public:
76  CDenseFeatures(int32_t size = 0);
77 
79  CDenseFeatures(const CDenseFeatures & orig);
80 
85  CDenseFeatures(SGMatrix<ST> matrix);
86 
93  CDenseFeatures(ST* src, int32_t num_feat, int32_t num_vec);
94 
99  CDenseFeatures(CFile* loader);
100 
105  virtual CFeatures* duplicate() const;
106 
107  virtual ~CDenseFeatures();
108 
113  void free_feature_matrix();
114 
119  void free_features();
120 
132  ST* get_feature_vector(int32_t num, int32_t& len, bool& dofree);
133 
141  void set_feature_vector(SGVector<ST> vector, int32_t num);
142 
150  SGVector<ST> get_feature_vector(int32_t num);
151 
160  void free_feature_vector(ST* feat_vec, int32_t num, bool dofree);
161 
169  void free_feature_vector(SGVector<ST> vec, int32_t num);
170 
184  void vector_subset(int32_t* idx, int32_t idx_len);
185 
199  void feature_subset(int32_t* idx, int32_t idx_len);
200 
208  SGMatrix<ST> get_feature_matrix();
209 
216  SGMatrix<ST> steal_feature_matrix();
217 
229  void set_feature_matrix(SGMatrix<ST> matrix);
230 
240  ST* get_feature_matrix(int32_t &num_feat, int32_t &num_vec);
241 
248  CDenseFeatures<ST>* get_transposed();
249 
261  ST* get_transposed(int32_t &num_feat, int32_t &num_vec);
262 
272  virtual void copy_feature_matrix(SGMatrix<ST> src);
273 
280  void obtain_from_dot(CDotFeatures* df);
281 
292  virtual bool apply_preprocessor(bool force_preprocessing = false);
293 
298  virtual int32_t get_num_vectors() const;
299 
304  int32_t get_num_features() const;
305 
310  void set_num_features(int32_t num);
311 
318  void set_num_vectors(int32_t num);
319 
324  void initialize_cache();
325 
330  virtual EFeatureClass get_feature_class() const;
331 
336  virtual EFeatureType get_feature_type() const;
337 
346  virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors);
347 
355  virtual int32_t get_dim_feature_space() const;
356 
366  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
367  int32_t vec_idx2);
368 
377  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
378  int32_t vec2_len);
379 
390  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
391  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
392 
398  virtual int32_t get_nnz_features_for_vector(int32_t num);
399 
404  virtual void load(CFile* loader);
405 
410  virtual void save(CFile* saver);
411 
412 #ifndef DOXYGEN_SHOULD_SKIP_THIS
413 
414  struct dense_feature_iterator
415  {
417  ST* vec;
419  int32_t vidx;
421  int32_t vlen;
423  bool vfree;
424 
426  int32_t index;
427  };
428 #endif
429 
441  virtual void* get_feature_iterator(int32_t vector_index);
442 
455  virtual bool get_next_feature(int32_t& index, float64_t& value,
456  void* iterator);
457 
463  virtual void free_feature_iterator(void* iterator);
464 
473  virtual CFeatures* copy_subset(SGVector<index_t> indices);
474 
485  virtual CFeatures* copy_dimension_subset(SGVector<index_t> dims);
486 
493  virtual bool is_equal(CDenseFeatures* rhs);
494 
503  CFeatures* create_merged_copy(CList* other);
504 
512 
516  static CDenseFeatures* obtain_from_generic(CFeatures* const base_features);
517 
519  virtual const char* get_name() const { return "DenseFeatures"; }
520 
521 protected:
533  virtual ST* compute_feature_vector(int32_t num, int32_t& len,
534  ST* target = NULL);
535 
536 private:
537  void init();
538 
539 protected:
541  int32_t num_vectors;
542 
544  int32_t num_features;
545 
551 
554 };
555 }
556 #endif // _DENSEFEATURES__H__
void set_feature_vector(SGVector< ST > vector, int32_t num)
virtual int32_t get_dim_feature_space() const
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
virtual void load(CFile *loader)
virtual void copy_feature_matrix(SGMatrix< ST > src)
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
int32_t get_num_features() const
virtual void free_feature_iterator(void *iterator)
CDenseFeatures(int32_t size=0)
CCache< ST > * feature_cache
virtual CFeatures * duplicate() const
CDotFeatures(int32_t size=0)
Definition: DotFeatures.cpp:42
SGMatrix< ST > get_feature_matrix()
void set_feature_matrix(SGMatrix< ST > matrix)
CFeatures(int32_t size=0)
Definition: Features.cpp:23
void vector_subset(int32_t *idx, int32_t idx_len)
virtual bool is_equal(CDenseFeatures *rhs)
virtual int32_t get_nnz_features_for_vector(int32_t num)
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
int32_t num_features
number of features in cache
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:38
virtual void * get_feature_iterator(int32_t vector_index)
virtual void save(CFile *saver)
virtual int32_t get_num_vectors() const
virtual ST * compute_feature_vector(int32_t num, int32_t &len, ST *target=NULL)
double float64_t
Definition: common.h:50
void set_num_vectors(int32_t num)
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
CDenseFeatures< ST > * get_transposed()
void set_num_features(int32_t num)
SGMatrix< ST > feature_matrix
CFeatures * create_merged_copy(CList *other)
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
virtual CFeatures * copy_dimension_subset(SGVector< index_t > dims)
void feature_subset(int32_t *idx, int32_t idx_len)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors)
virtual EFeatureClass get_feature_class() const
void obtain_from_dot(CDotFeatures *df)
int32_t num_vectors
number of vectors in cache
static CDenseFeatures * obtain_from_generic(CFeatures *const base_features)
virtual EFeatureType get_feature_type() const
virtual bool apply_preprocessor(bool force_preprocessing=false)
SGMatrix< ST > steal_feature_matrix()
virtual const char * get_name() const
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
virtual CFeatures * copy_subset(SGVector< index_t > indices)

SHOGUN Machine Learning Toolbox - Documentation