SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleFeatures.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  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  * Copyright (C) 2010 Berlin Institute of Technology
11  */
12 
13 #ifndef _SIMPLEFEATURES__H__
14 #define _SIMPLEFEATURES__H__
15 
16 #include <shogun/lib/common.h>
17 #include <shogun/lib/Cache.h>
18 #include <shogun/io/File.h>
21 #include <shogun/lib/DataType.h>
22 
23 namespace shogun {
24 template<class ST> class CStringFeatures;
25 template<class ST> class CSimpleFeatures;
26 template<class ST> class SGMatrix;
27 class CDotFeatures;
28 
58 template<class ST> class CSimpleFeatures: public CDotFeatures
59 {
60 public:
65  CSimpleFeatures(int32_t size = 0);
66 
68  CSimpleFeatures(const CSimpleFeatures & orig);
69 
75 
82  CSimpleFeatures(ST* src, int32_t num_feat, int32_t num_vec);
83 
88  CSimpleFeatures(CFile* loader);
89 
94  virtual CFeatures* duplicate() const;
95 
96  virtual ~CSimpleFeatures();
97 
102  void free_feature_matrix();
103 
108  void free_features();
109 
121  ST* get_feature_vector(int32_t num, int32_t& len, bool& dofree);
122 
130  void set_feature_vector(SGVector<ST> vector, int32_t num);
131 
139  SGVector<ST> get_feature_vector(int32_t num);
140 
149  void free_feature_vector(ST* feat_vec, int32_t num, bool dofree);
150 
158  void free_feature_vector(SGVector<ST> vec, int32_t num);
159 
173  void vector_subset(int32_t* idx, int32_t idx_len);
174 
188  void feature_subset(int32_t* idx, int32_t idx_len);
189 
199  void get_feature_matrix(ST** dst, int32_t* num_feat, int32_t* num_vec);
200 
208 
216 
223  void set_feature_matrix(SGMatrix<ST> matrix);
224 
234  ST* get_feature_matrix(int32_t &num_feat, int32_t &num_vec);
235 
243 
255  ST* get_transposed(int32_t &num_feat, int32_t &num_vec);
256 
269  virtual void set_feature_matrix(ST* fm, int32_t num_feat, int32_t num_vec);
270 
280  virtual void copy_feature_matrix(SGMatrix<ST> src);
281 
288  void obtain_from_dot(CDotFeatures* df);
289 
300  virtual bool apply_preprocessor(bool force_preprocessing = false);
301 
306  virtual int32_t get_size();
307 
312  virtual int32_t get_num_vectors() const;
313 
318  int32_t get_num_features();
319 
324  void set_num_features(int32_t num);
325 
332  void set_num_vectors(int32_t num);
333 
338  void initialize_cache();
339 
345 
350  virtual EFeatureType get_feature_type();
351 
360  virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors);
361 
369  virtual int32_t get_dim_feature_space() const;
370 
380  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
381  int32_t vec_idx2);
382 
391  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
392  int32_t vec2_len);
393 
404  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
405  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
406 
412  virtual int32_t get_nnz_features_for_vector(int32_t num);
413 
422  CStringFeatures<char>* Ref, float64_t gapCost);
423 
428  virtual void load(CFile* loader);
429 
434  virtual void save(CFile* saver);
435 
436  #ifndef DOXYGEN_SHOULD_SKIP_THIS
437 
438  struct simple_feature_iterator
439  {
441  ST* vec;
443  int32_t vidx;
445  int32_t vlen;
447  bool vfree;
448 
450  int32_t index;
451  };
452  #endif
453 
465  virtual void* get_feature_iterator(int32_t vector_index);
466 
479  virtual bool get_next_feature(int32_t& index, float64_t& value,
480  void* iterator);
481 
487  virtual void free_feature_iterator(void* iterator);
488 
497  virtual CFeatures* copy_subset(SGVector<index_t> indices);
498 
500  inline virtual const char* get_name() const { return "SimpleFeatures"; }
501 
502 protected:
514  virtual ST* compute_feature_vector(int32_t num, int32_t& len,
515  ST* target = NULL);
516 
517 private:
518  void init();
519 
520 protected:
522  int32_t num_vectors;
523 
525  int32_t num_features;
526 
532 
535 
538 
541 };
542 }
543 #endif // _SIMPLEFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation