SHOGUN  v2.0.0
 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-2012 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_size() const;
295 
300  virtual int32_t get_num_vectors() const;
301 
306  int32_t get_num_features();
307 
312  void set_num_features(int32_t num);
313 
320  void set_num_vectors(int32_t num);
321 
326  void initialize_cache();
327 
332  virtual EFeatureClass get_feature_class() const;
333 
338  virtual EFeatureType get_feature_type() const;
339 
348  virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors);
349 
357  virtual int32_t get_dim_feature_space() const;
358 
368  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
369  int32_t vec_idx2);
370 
379  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
380  int32_t vec2_len);
381 
392  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
393  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
394 
400  virtual int32_t get_nnz_features_for_vector(int32_t num);
401 
406  virtual void load(CFile* loader);
407 
412  virtual void save(CFile* saver);
413 
414 #ifndef DOXYGEN_SHOULD_SKIP_THIS
415 
416  struct dense_feature_iterator
417  {
419  ST* vec;
421  int32_t vidx;
423  int32_t vlen;
425  bool vfree;
426 
428  int32_t index;
429  };
430 #endif
431 
443  virtual void* get_feature_iterator(int32_t vector_index);
444 
457  virtual bool get_next_feature(int32_t& index, float64_t& value,
458  void* iterator);
459 
465  virtual void free_feature_iterator(void* iterator);
466 
475  virtual CFeatures* copy_subset(SGVector<index_t> indices);
476 
483  virtual bool is_equal(CDenseFeatures* rhs);
484 
494 
496  inline virtual const char* get_name() const { return "DenseFeatures"; }
497 
498 protected:
510  virtual ST* compute_feature_vector(int32_t num, int32_t& len,
511  ST* target = NULL);
512 
513 private:
514  void init();
515 
516 protected:
518  int32_t num_vectors;
519 
521  int32_t num_features;
522 
528 
531 };
532 }
533 #endif // _DENSEFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation