SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HashedSparseFeatures.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_SPARSEFEATURES_H__
00012 #define _HASHED_SPARSEFEATURES_H__
00013 
00014 #include <shogun/features/SparseFeatures.h>
00015 #include <shogun/features/DotFeatures.h>
00016 #include <shogun/lib/SGSparseVector.h>
00017 
00018 namespace shogun
00019 {
00020 template <class ST> class CSparseFeatures;
00021 template <class ST> class SGSparseVector;
00022 class CDotFeatures;
00023 
00027 template <class ST> class CHashedSparseFeatures  : public CDotFeatures
00028 {
00029 public:
00030 
00037     CHashedSparseFeatures(int32_t size=0, bool use_quadr = false, bool keep_lin_terms = true);
00038 
00046     CHashedSparseFeatures(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr = false,
00047             bool keep_lin_terms = true);
00048 
00056     CHashedSparseFeatures(SGSparseMatrix<ST> matrix, int32_t d, bool use_quadr = false,
00057             bool keep_lin_terms = true);
00058 
00066     CHashedSparseFeatures(CFile* loader, int32_t d, bool use_quadr = false,
00067             bool keep_lin_terms = true);
00068 
00070     CHashedSparseFeatures(const CHashedSparseFeatures & orig);
00071 
00073     virtual CFeatures* duplicate() const;
00074 
00076     virtual ~CHashedSparseFeatures();
00077 
00085     virtual int32_t get_dim_feature_space() const;
00086 
00096     virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
00097             int32_t vec_idx2);
00098 
00107     virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2,
00108             int32_t vec2_len);
00109 
00120     virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
00121             float64_t* vec2, int32_t vec2_len, bool abs_val = false);
00122 
00128     virtual int32_t get_nnz_features_for_vector(int32_t num);
00129 
00141     virtual void* get_feature_iterator(int32_t vector_index);
00142 
00155     virtual bool get_next_feature(int32_t& index, float64_t& value,
00156             void* iterator);
00157 
00163     virtual void free_feature_iterator(void* iterator);
00164 
00166     virtual const char* get_name() const;
00167 
00172     virtual EFeatureType get_feature_type() const;
00173 
00178     virtual EFeatureClass get_feature_class() const;
00179 
00184     virtual int32_t get_num_vectors() const;
00185 
00190     SGSparseVector<ST> get_hashed_feature_vector(int32_t vec_idx) const;
00191 
00200     static SGSparseVector<ST> hash_vector(SGVector<ST> vec, int32_t dim,
00201         bool use_quadratic = false, bool keep_linear_terms = true);
00202 
00203 
00212     static SGSparseVector<ST> hash_vector(SGSparseVector<ST> vec, int32_t dim,
00213         bool use_quadratic = false, bool keep_linear_terms = true);
00214 
00215 private:
00216     void init(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr, bool keep_lin_terms);
00217 
00218 protected:
00219 
00221     CSparseFeatures<ST>* sparse_feats;
00222 
00224     int32_t dim;
00225 
00227     bool use_quadratic;
00228 
00230     bool keep_linear_terms;
00231 };
00232 }
00233 
00234 #endif // _HASHED_SPARSEFEATURES_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation