SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KernelDensity.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Parijat Mazumdar
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  */
30 
31 #ifndef _KERNELDENSITY_H__
32 #define _KERNELDENSITY_H__
33 
34 #include <shogun/lib/config.h>
36 #include <shogun/kernel/Kernel.h>
38 
39 namespace shogun
40 {
41 
44 {
49 };
50 
62 {
63 public :
74  CKernelDensity(float64_t bandwidth=1.0, EKernelType kernel_type=K_GAUSSIAN, EDistanceType dist=D_EUCLIDEAN, EEvaluationMode eval=EM_BALLTREE_SINGLE, int32_t leaf_size=1, float64_t atol=0, float64_t rtol=0);
75 
78 
83  virtual const char* get_name() const { return "KernelDensity"; }
84 
90  virtual bool train(CFeatures* data=NULL);
91 
99 
105  virtual int32_t get_num_model_parameters();
106 
113  virtual float64_t get_log_model_parameter(int32_t num_param);
114 
122  virtual float64_t get_log_derivative(int32_t num_param, int32_t num_example);
123 
130  virtual float64_t get_log_likelihood_example(int32_t num_example);
131 
139  inline static float64_t log_norm(EKernelType kernel, float64_t width, int32_t dim)
140  {
141  switch(kernel)
142  {
143  case K_GAUSSIAN:
144  {
145  return -0.5*dim* CMath::log(2*CMath::PI)-dim*CMath::log(width);
146  break;
147  }
148  default:
149  SG_SPRINT("kernel type not recognized\n");
150  }
151 
152  return 0.0;
153  }
154 
162  inline static float64_t log_kernel(EKernelType kernel, float64_t dist, float64_t width)
163  {
164  switch(kernel)
165  {
166  case K_GAUSSIAN:
167  {
168  return -0.5*dist*dist/(width*width);
169  break;
170  }
171  default:
172  SG_SPRINT("kernel type not recognized\n");
173  }
174 
175  return 0.0;
176  }
177 
178 private:
180  void init();
181 
182 private :
184  float64_t m_bandwidth;
185 
187  int32_t m_leaf_size;
188 
190  float64_t m_atol;
191 
193  float64_t m_rtol;
194 
196  EEvaluationMode m_eval;
197 
199  EKernelType m_kernel_type;
200 
202  EDistanceType m_dist;
203 
205  CNbodyTree* tree;
206 };
207 } /* shogun */
208 
209 #endif /* _KERNELDENSITY_H__ */

SHOGUN Machine Learning Toolbox - Documentation