SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PolyFeatures.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) 2009 Jonas Behr
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 #ifndef _POLYFEATURES__H__
00011 #define _POLYFEATURES__H__
00012 
00013 #include <shogun/lib/common.h>
00014 #include <shogun/features/DotFeatures.h>
00015 #include <shogun/features/DenseFeatures.h>
00016 
00017 
00018 namespace shogun
00019 {
00025 class CPolyFeatures : public CDotFeatures
00026 {
00027     public:
00029         CPolyFeatures();
00030 
00037         CPolyFeatures(CDenseFeatures<float64_t>* feat, int32_t degree, bool normalize);
00038 
00039         virtual ~CPolyFeatures();
00040 
00047         CPolyFeatures(const CPolyFeatures & orig);
00048 
00053         virtual int32_t get_dim_feature_space() const;
00054 
00060         virtual int32_t get_nnz_features_for_vector(int32_t num);
00061 
00066         virtual EFeatureType get_feature_type() const;
00067 
00072         virtual EFeatureClass get_feature_class() const;
00073 
00078         virtual int32_t get_num_vectors() const;
00079 
00087         virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00088 
00093         CFeatures* duplicate() const;
00094 
00099         virtual const char* get_name() const { return "PolyFeatures"; }
00100 
00108         float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len);
00109 
00118         void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
00119 
00120         #ifndef DOXYGEN_SHOULD_SKIP_THIS
00121 
00122         struct poly_feature_iterator
00123         {
00125             uint16_t* vec;
00127             int32_t vidx;
00129             int32_t vlen;
00131             bool vfree;
00132 
00134             int32_t index;
00135 
00136         };
00137         #endif
00138 
00148         virtual void* get_feature_iterator(int32_t vector_index);
00149 
00160         virtual bool get_next_feature(int32_t& index, float64_t& value,
00161                 void* iterator);
00162 
00168         virtual void free_feature_iterator(void* iterator);
00169 
00170     protected:
00171 
00173         void store_normalization_values();
00174 
00176         void store_multi_index();
00177 
00180         void enumerate_multi_index(const int32_t feat_idx, uint16_t** index,
00181                 uint16_t* exponents, const int32_t degree);
00184         void store_multinomial_coefficients();
00185 
00189         int32_t bico2(int32_t n, int32_t k);
00190 
00193         int32_t  bico(int32_t n, int32_t k);
00194 
00201         int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
00202 
00204         int32_t multinomialcoef(int32_t* exps, int32_t len);
00205 
00207         float64_t gammln(float64_t xx);
00208 
00210         float64_t factln(int32_t n);
00211 
00212     protected:
00213 
00215         CDenseFeatures<float64_t>* m_feat;
00217         int32_t m_degree;
00219         bool m_normalize;
00221         int32_t m_input_dimensions;
00223         int32_t m_output_dimensions;
00226         uint16_t* m_multi_index;
00228         float64_t* m_multinomial_coefficients;
00230         float32_t* m_normalization_values;
00231     private:
00232         index_t multi_index_length;
00233         index_t multinomial_coefficients_length;
00234         index_t normalization_values_length;
00235 
00237         void register_parameters();
00238 };
00239 }
00240 #endif // _POLYFEATURES__H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation