SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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;
00046 class CGaussianKernel: public CDotKernel
00047 {
00048     public:
00050         CGaussianKernel();
00051 
00057         CGaussianKernel(int32_t size, float64_t width);
00058 
00066         CGaussianKernel(CDotFeatures* l, CDotFeatures* r,
00067             float64_t width, int32_t size=10);
00068 
00069         virtual ~CGaussianKernel();
00070 
00075         static CGaussianKernel* obtain_from_generic(CKernel* kernel);
00076 
00078         virtual CSGObject* shallow_copy() const;
00079 
00086         virtual bool init(CFeatures* l, CFeatures* r);
00087 
00089         virtual void cleanup();
00090 
00095         virtual EKernelType get_kernel_type() { return K_GAUSSIAN; }
00096 
00101         virtual const char* get_name() const { return "GaussianKernel"; }
00102 
00107         virtual void set_width(float64_t w) { width=w; }
00108 
00113         virtual float64_t get_width() const { return width; }
00114 
00119         inline void set_compact_enabled(bool compact) { m_compact=compact; }
00120 
00125         inline bool get_compact_enabled() { return m_compact; }
00126 
00134         virtual SGMatrix<float64_t> get_parameter_gradient(
00135                 const TParameter* param, index_t index=-1);
00136 
00137     protected:
00146         virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00147 
00154         virtual void load_serializable_post() throw (ShogunException);
00155 
00156     private:
00160         void precompute_squared();
00161 
00168         void precompute_squared_helper(float64_t* &buf, CDotFeatures* df);
00169 
00170         void init();
00171 
00172     protected:
00174         float64_t width;
00176         float64_t* sq_lhs;
00178         float64_t* sq_rhs;
00180         bool m_compact;
00181 };
00182 }
00183 #endif /* _GAUSSIANKERNEL_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation