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) 2012 Viktor Gal 00008 * Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 00009 */ 00010 00011 #ifndef _CHOMOGENEOUKERNELMAP__H__ 00012 #define _CHOMOGENEOUKERNELMAP__H__ 00013 00014 #include <shogun/preprocessor/DensePreprocessor.h> 00015 #include <shogun/features/Features.h> 00016 #include <shogun/lib/common.h> 00017 00018 #include <stdio.h> 00019 00020 namespace shogun 00021 { 00023 enum HomogeneousKernelType { 00024 HomogeneousKernelIntersection = 0, 00025 HomogeneousKernelChi2, 00026 HomogeneousKernelJS 00027 }; 00028 00030 enum HomogeneousKernelMapWindowType { 00031 HomogeneousKernelMapWindowUniform = 0, 00032 HomogeneousKernelMapWindowRectangular = 1, 00033 }; 00034 00054 class CHomogeneousKernelMap : public CDensePreprocessor<float64_t> 00055 { 00056 public: 00058 CHomogeneousKernelMap(); 00059 00068 CHomogeneousKernelMap(HomogeneousKernelType kernel, HomogeneousKernelMapWindowType wType, 00069 float64_t gamma = 1.0, uint64_t order = 1, float64_t period = -1); 00070 00072 virtual ~CHomogeneousKernelMap(); 00073 00075 virtual bool init(CFeatures* features); 00076 00078 virtual void cleanup(); 00079 00084 virtual SGMatrix<float64_t> apply_to_feature_matrix(CFeatures* features); 00085 00090 virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector); 00091 00093 virtual const char* get_name() const { return "HomogeneousKernelMap"; } 00094 00096 virtual EPreprocessorType get_type() const { return P_HOMOGENEOUSKERNELMAP; } 00097 00101 void set_kernel_type(HomogeneousKernelType k); 00105 HomogeneousKernelType get_kernel_type() const; 00106 00110 void set_window_type(HomogeneousKernelMapWindowType w); 00114 HomogeneousKernelMapWindowType get_window_type() const; 00115 00119 void set_gamma(float64_t g); 00123 float64_t get_gamma(float64_t g) const; 00124 00128 void set_order(uint64_t o); 00132 uint64_t get_order() const; 00133 00137 void set_period(float64_t p); 00141 float64_t get_period() const; 00142 00143 private: 00144 void init (); 00145 void register_params (); 00146 inline float64_t get_smooth_spectrum (float64_t omega) const; 00147 inline float64_t sinc (float64_t x) const; 00148 inline float64_t get_spectrum (float64_t omega) const; 00149 SGVector<float64_t> apply_to_vector(const SGVector<float64_t>& in_v) const; 00150 00151 private: 00152 HomogeneousKernelType m_kernel; 00153 HomogeneousKernelMapWindowType m_window; 00154 float64_t m_gamma; 00155 float64_t m_period; 00156 uint64_t m_numSubdivisions; 00157 float64_t m_subdivision; 00158 uint64_t m_order; 00159 int64_t m_minExponent; 00160 int64_t m_maxExponent; 00161 SGVector<float64_t> m_table; 00162 }; 00163 } 00164 #endif /* _CHOMOGENEOUKERNELMAP__H__ */