GaussianKernel.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) 1999-2010 Soeren Sonnenburg
00008  * Written (W) 2011 Abhinav Maurya
00009  * Written (W) 2012 Heiko Strathmann
00010  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00011  * Copyright (C) 2010 Berlin Institute of Technology
00012  */
00013 
00014 #ifndef _GAUSSIANKERNEL_H___
00015 #define _GAUSSIANKERNEL_H___
00016 
00017 #include <shogun/lib/common.h>
00018 #include <shogun/kernel/Kernel.h>
00019 #include <shogun/kernel/DotKernel.h>
00020 #include <shogun/features/DotFeatures.h>
00021 
00022 namespace shogun
00023 {
00024     class CDotFeatures;
00045 class CGaussianKernel: public CDotKernel
00046 {
00047     public:
00051         CGaussianKernel();
00052 
00058         CGaussianKernel(int32_t size, float64_t width);
00059 
00067         CGaussianKernel(CDotFeatures* l, CDotFeatures* r,
00068             float64_t width, int32_t size=10);
00069 
00070         virtual ~CGaussianKernel();
00071 
00076         static CGaussianKernel* obtain_from_generic(CKernel* kernel);
00077 
00079         virtual CSGObject *shallow_copy() const;
00080 
00087         virtual bool init(CFeatures* l, CFeatures* r);
00088 
00090         virtual void cleanup();
00091 
00096         virtual EKernelType get_kernel_type() { return K_GAUSSIAN; }
00097 
00102         virtual const char* get_name() const { return "GaussianKernel"; }
00103 
00108         virtual void set_width(float64_t w)
00109         {
00110             width=w;
00111         }
00112 
00117         virtual float64_t get_width() const
00118         {
00119             return width;
00120         }
00121 
00126         inline void set_compact_enabled(bool compact)
00127         {
00128             m_compact = compact;
00129         }
00130 
00135         inline bool get_compact_enabled()
00136         {
00137             return m_compact;
00138         }
00139         
00148         virtual SGMatrix<float64_t> get_parameter_gradient(TParameter* param,
00149                 CSGObject* obj, index_t index = -1);
00150 
00151 
00152     protected:
00161         virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00162 
00171         virtual void load_serializable_post() throw (ShogunException);
00172 
00173     private:
00177         void precompute_squared();
00178 
00185         void precompute_squared_helper(float64_t* &buf, CDotFeatures* df);
00186 
00187         void init();
00188 
00189     protected:
00191         float64_t width;
00193         float64_t* sq_lhs;
00195         float64_t* sq_rhs;
00197         bool m_compact;
00198 };
00199 }
00200 #endif /* _GAUSSIANKERNEL_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation