SparsePolyFeatures.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) 2010 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 #ifndef _SPARSEPOLYFEATURES__H__
00011 #define _SPARSEPOLYFEATURES__H__
00012 
00013 #include <shogun/lib/common.h>
00014 #include <shogun/features/DotFeatures.h>
00015 #include <shogun/features/SparseFeatures.h>
00016 
00017 namespace shogun
00018 {
00024 class CSparsePolyFeatures : public CDotFeatures
00025 {
00026     public:
00028         CSparsePolyFeatures();
00029 
00038         CSparsePolyFeatures(CSparseFeatures<float64_t>* feat, int32_t degree, bool normalize, int32_t hash_bits);
00039 
00040         virtual ~CSparsePolyFeatures();
00041 
00048         CSparsePolyFeatures(const CSparsePolyFeatures & orig){ 
00049             SG_PRINT("CSparsePolyFeatures:\n");
00050             SG_NOTIMPLEMENTED;};
00051 
00056         inline virtual int32_t get_dim_feature_space() const
00057         {
00058             return m_output_dimensions;
00059         }
00060 
00066         virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00067         {
00068             int32_t vlen;
00069             SGSparseVector<float64_t> vec=m_feat->get_sparse_feature_vector(num);
00070             vlen=vec.num_feat_entries;
00071             m_feat->free_feature_vector(vec, num);
00072             return vlen*(vlen+1)/2;
00073         }
00074 
00079         inline virtual EFeatureType get_feature_type()
00080         {
00081             return F_UNKNOWN;
00082         }
00083 
00088         inline virtual EFeatureClass get_feature_class()
00089         {
00090             return C_POLY;
00091         }
00092 
00097         inline virtual int32_t get_num_vectors() const
00098         {
00099             if (m_feat)
00100                 return m_feat->get_num_vectors();
00101             else
00102                 return 0;
00103 
00104         }
00105 
00113         virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00114 
00119         inline virtual int32_t get_size()
00120         {
00121             return sizeof(float64_t);
00122         }
00123 
00124         #ifndef DOXYGEN_SHOULD_SKIP_THIS
00125 
00126         struct sparse_poly_feature_iterator
00127         {
00129             uint16_t* vec;
00131             int32_t vidx;
00133             int32_t vlen;
00135             bool vfree;
00136 
00138             int32_t index;
00139         };
00140         #endif
00141 
00151         virtual void* get_feature_iterator(int32_t vector_index)
00152         {
00153             SG_NOTIMPLEMENTED;
00154             return NULL;
00155         }
00156 
00167         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)
00168         {
00169             SG_NOTIMPLEMENTED;
00170             return NULL;
00171         }
00172 
00178         virtual void free_feature_iterator(void* iterator)
00179         {
00180             SG_NOTIMPLEMENTED;
00181         }
00182 
00187         CFeatures* duplicate() const;
00188 
00193         inline virtual const char* get_name() const { return "SparsePolyFeatures"; }
00194 
00202         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00203 
00212         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00213 
00214     protected: 
00216         void store_normalization_values();
00217 
00218     protected:
00220         CSparseFeatures<float64_t>* m_feat;
00222         int32_t m_degree;
00224         bool m_normalize;
00226         int32_t m_input_dimensions;
00228         int32_t m_output_dimensions;
00230         float64_t* m_normalization_values; 
00232         uint32_t mask;
00234         int32_t m_hash_bits;
00235     private:
00237         void init();
00238 
00239     private:
00241         int32_t m_normalization_values_len;
00242 
00243 };
00244 }
00245 #endif // _SPARSEPOLYFEATURES__H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation