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 "lib/common.h"
00014 #include "features/DotFeatures.h"
00015 #include "features/SimpleFeatures.h"
00016 
00017 
00018 namespace shogun
00019 {
00025 class CPolyFeatures : public CDotFeatures
00026 {
00027     public:
00029         CPolyFeatures(void);
00030 
00037         CPolyFeatures(CSimpleFeatures<float64_t>* feat, int32_t degree, bool normalize);
00038 
00039         virtual ~CPolyFeatures();
00040 
00047         CPolyFeatures(const CPolyFeatures & orig){ 
00048             SG_PRINT("CPolyFeatures:\n");
00049             SG_NOTIMPLEMENTED;};
00050 
00055         inline virtual int32_t get_dim_feature_space()
00056         {
00057             return m_output_dimensions;
00058         }
00059 
00065         virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00066         {
00067             return m_output_dimensions;
00068         }
00069 
00074         inline virtual EFeatureType get_feature_type()
00075         {
00076             return F_UNKNOWN;
00077         }
00078 
00083         inline virtual EFeatureClass get_feature_class()
00084         {
00085             return C_POLY;
00086         }
00087 
00092         inline virtual int32_t get_num_vectors()
00093         {
00094             if (m_feat)
00095                 return m_feat->get_num_vectors();
00096             else
00097                 return 0;
00098 
00099         }
00100 
00108         virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00109 
00114         inline virtual int32_t get_size()
00115         {
00116             return sizeof(float64_t);
00117         }
00118 
00123         CFeatures* duplicate() const;
00124 
00129         inline virtual const char* get_name() const { return "PolyFeatures"; }
00130 
00138         float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00139 
00148         void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
00149 
00151         struct poly_feature_iterator
00152         {
00154             uint16_t* vec;
00156             int32_t vidx;
00158             int32_t vlen;
00160             bool vfree;
00161 
00163             int32_t index;
00164 
00165         };
00166 
00176         virtual void* get_feature_iterator(int32_t vector_index)
00177         {
00178             SG_NOTIMPLEMENTED;
00179             return NULL;
00180         }
00181 
00192         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)
00193         {
00194             SG_NOTIMPLEMENTED;
00195             return NULL;
00196         }
00197 
00203         virtual void free_feature_iterator(void* iterator)
00204         {
00205             SG_NOTIMPLEMENTED;
00206         }
00207 
00208     protected: 
00209 
00211         void store_normalization_values();
00212 
00214         void store_multi_index();
00215 
00218         void enumerate_multi_index(const int32_t feat_idx, uint16_t** index, uint16_t* exponents, const int32_t degree);
00221         void store_multinomial_coefficients();
00222 
00226         int32_t bico2(int32_t n, int32_t k);
00227 
00230         int32_t  bico(int32_t n, int32_t k);
00231 
00238         int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
00239 
00241         int32_t multinomialcoef(int32_t* exps, int32_t len);
00242 
00244         float64_t gammln(float64_t xx);
00245 
00247         float64_t factln(int32_t n);
00248 
00249     protected:
00250 
00252         CSimpleFeatures<float64_t>* m_feat;
00254         int32_t m_degree;
00256         bool m_normalize;
00258         int32_t m_input_dimensions;
00260         int32_t m_output_dimensions;
00263         uint16_t* m_multi_index;
00265         float64_t* m_multinomial_coefficients; 
00267         float32_t* m_normalization_values; 
00268 
00269 };
00270 }
00271 #endif // _POLYFEATURES__H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation