SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HashedDenseFeatures.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) 2013 Evangelos Anagnostopoulos
00008  * Copyright (C) 2013 Evangelos Anagnostopoulos
00009  */
00010 
00011 #ifndef _HASHED_DENSEFEATURES_H__
00012 #define _HASHED_DENSEFEATURES_H__
00013 
00014 #include <shogun/features/DenseFeatures.h>
00015 #include <shogun/features/DotFeatures.h>
00016 
00017 namespace shogun
00018 {
00019 template <class ST> class CDenseFeatures;
00020 class CDotFeatures;
00021 
00025 template <class ST> class CHashedDenseFeatures : public CDotFeatures
00026 {
00027 public:
00028 
00035     CHashedDenseFeatures(int32_t size=0, bool use_quadr = false, bool keep_lin_terms = true);
00036 
00044     CHashedDenseFeatures(CDenseFeatures<ST>* feats, int32_t d, bool use_quadr = false,
00045             bool keep_lin_terms = true);
00046 
00054     CHashedDenseFeatures(SGMatrix<ST> matrix, int32_t dm, bool use_quadr = false,
00055             bool keep_lin_terms = true);
00056 
00066     CHashedDenseFeatures(ST* src, int32_t num_feat, int32_t num_vec, int32_t d,
00067             bool use_quadr = false, bool keep_lin_terms = true);
00068 
00076     CHashedDenseFeatures(CFile* loader, int32_t d, bool use_quadr = false,
00077             bool keep_lin_terms = false);
00078 
00080     CHashedDenseFeatures(const CHashedDenseFeatures& orig);
00081 
00083     virtual CFeatures* duplicate() const;
00084 
00086     virtual ~CHashedDenseFeatures();
00087 
00095     virtual int32_t get_dim_feature_space() const;
00096 
00106     virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
00107             int32_t vec_idx2);
00108 
00117     virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2,
00118             int32_t vec2_len);
00119 
00130     virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
00131             float64_t* vec2, int32_t vec2_len, bool abs_val = false);
00132 
00138     virtual int32_t get_nnz_features_for_vector(int32_t num);
00139 
00151     virtual void* get_feature_iterator(int32_t vector_index);
00152 
00165     virtual bool get_next_feature(int32_t& index, float64_t& value,
00166             void* iterator);
00167 
00173     virtual void free_feature_iterator(void* iterator);
00174 
00176     virtual const char* get_name() const;
00177 
00182     virtual EFeatureType get_feature_type() const;
00183 
00188     virtual EFeatureClass get_feature_class() const;
00189 
00194     virtual int32_t get_num_vectors() const;
00195 
00201     SGSparseVector<ST> get_hashed_feature_vector(int32_t vec_idx);
00202 
00211     static SGSparseVector<ST> hash_vector(SGVector<ST> vec, int32_t dim, bool use_quadratic = false,
00212             bool keep_linear_terms = true);
00213 
00214 private:
00215     void init(CDenseFeatures<ST>* feats, int32_t d, bool use_quadr, bool keep_lin_terms);
00216 
00217 protected:
00218 
00220     CDenseFeatures<ST>* dense_feats;
00221 
00223     int32_t dim;
00224 
00226     bool use_quadratic;
00227 
00229     bool keep_linear_terms;
00230 };
00231 }
00232 
00233 #endif // _HASHED_DENSEFEATURES_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation