DenseFeatures.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2010 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Written (W) 2011-2012 Heiko Strathmann
00010  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00011  * Copyright (C) 2010 Berlin Institute of Technology
00012  */
00013 
00014 #ifndef _DENSEFEATURES__H__
00015 #define _DENSEFEATURES__H__
00016 
00017 #include <shogun/lib/common.h>
00018 #include <shogun/lib/Cache.h>
00019 #include <shogun/io/File.h>
00020 #include <shogun/features/DotFeatures.h>
00021 #include <shogun/features/StringFeatures.h>
00022 #include <shogun/lib/DataType.h>
00023 
00024 namespace shogun {
00025 template<class ST> class CStringFeatures;
00026 template<class ST> class CDenseFeatures;
00027 template<class ST> class SGMatrix;
00028 class CDotFeatures;
00029 
00065 template<class ST> class CDenseFeatures: public CDotFeatures
00066 {
00067 public:
00072     CDenseFeatures(int32_t size = 0);
00073 
00075     CDenseFeatures(const CDenseFeatures & orig);
00076 
00081     CDenseFeatures(SGMatrix<ST> matrix);
00082 
00089     CDenseFeatures(ST* src, int32_t num_feat, int32_t num_vec);
00090 
00095     CDenseFeatures(CFile* loader);
00096 
00101     virtual CFeatures* duplicate() const;
00102 
00103     virtual ~CDenseFeatures();
00104 
00109     void free_feature_matrix();
00110 
00115     void free_features();
00116 
00128     ST* get_feature_vector(int32_t num, int32_t& len, bool& dofree);
00129 
00137     void set_feature_vector(SGVector<ST> vector, int32_t num);
00138 
00146     SGVector<ST> get_feature_vector(int32_t num);
00147 
00156     void free_feature_vector(ST* feat_vec, int32_t num, bool dofree);
00157 
00165     void free_feature_vector(SGVector<ST> vec, int32_t num);
00166 
00180     void vector_subset(int32_t* idx, int32_t idx_len);
00181 
00195     void feature_subset(int32_t* idx, int32_t idx_len);
00196 
00204     SGMatrix<ST> get_feature_matrix();
00205 
00212     SGMatrix<ST> steal_feature_matrix();
00213 
00225     void set_feature_matrix(SGMatrix<ST> matrix);
00226 
00236     ST* get_feature_matrix(int32_t &num_feat, int32_t &num_vec);
00237 
00244     CDenseFeatures<ST>* get_transposed();
00245 
00257     ST* get_transposed(int32_t &num_feat, int32_t &num_vec);
00258 
00268     virtual void copy_feature_matrix(SGMatrix<ST> src);
00269 
00276     void obtain_from_dot(CDotFeatures* df);
00277 
00288     virtual bool apply_preprocessor(bool force_preprocessing = false);
00289 
00294     virtual int32_t get_size() const;
00295 
00300     virtual int32_t get_num_vectors() const;
00301 
00306     int32_t get_num_features();
00307 
00312     void set_num_features(int32_t num);
00313 
00320     void set_num_vectors(int32_t num);
00321 
00326     void initialize_cache();
00327 
00332     virtual EFeatureClass get_feature_class() const;
00333 
00338     virtual EFeatureType get_feature_type() const;
00339 
00348     virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors);
00349 
00357     virtual int32_t get_dim_feature_space() const;
00358 
00368     virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
00369             int32_t vec_idx2);
00370 
00379     virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
00380             int32_t vec2_len);
00381 
00392     virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
00393             float64_t* vec2, int32_t vec2_len, bool abs_val = false);
00394 
00400     virtual int32_t get_nnz_features_for_vector(int32_t num);
00401 
00406     virtual void load(CFile* loader);
00407 
00412     virtual void save(CFile* saver);
00413 
00414 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00415 
00416     struct dense_feature_iterator
00417     {
00419         ST* vec;
00421         int32_t vidx;
00423         int32_t vlen;
00425         bool vfree;
00426 
00428         int32_t index;
00429     };
00430 #endif
00431 
00443     virtual void* get_feature_iterator(int32_t vector_index);
00444 
00457     virtual bool get_next_feature(int32_t& index, float64_t& value,
00458             void* iterator);
00459 
00465     virtual void free_feature_iterator(void* iterator);
00466 
00475     virtual CFeatures* copy_subset(SGVector<index_t> indices);
00476 
00483     virtual bool is_equal(CDenseFeatures* rhs);
00484 
00493     CFeatures* create_merged_copy(CFeatures* other);
00494 
00496     virtual const char* get_name() const { return "DenseFeatures"; }
00497 
00498 protected:
00510     virtual ST* compute_feature_vector(int32_t num, int32_t& len,
00511             ST* target = NULL);
00512 
00513 private:
00514     void init();
00515 
00516 protected:
00518     int32_t num_vectors;
00519 
00521     int32_t num_features;
00522 
00527     SGMatrix<ST> feature_matrix;
00528 
00530     CCache<ST>* feature_cache;
00531 };
00532 }
00533 #endif // _DENSEFEATURES__H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation