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 {
42 {
47 };
48 
60 {
61 public :
72  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);
73 
76 
81  virtual const char* get_name() const { return "KernelDensity"; }
82 
88  virtual bool train(CFeatures* data=NULL);
89 
97 
103  virtual int32_t get_num_model_parameters();
104 
111  virtual float64_t get_log_model_parameter(int32_t num_param);
112 
120  virtual float64_t get_log_derivative(int32_t num_param, int32_t num_example);
121 
128  virtual float64_t get_log_likelihood_example(int32_t num_example);
129 
137  inline static float64_t log_norm(EKernelType kernel, float64_t width, int32_t dim)
138  {
139  switch(kernel)
140  {
141  case K_GAUSSIAN:
142  {
143  return -0.5*dim* CMath::log(2*CMath::PI)-dim*CMath::log(width);
144  break;
145  }
146  default:
147  SG_SPRINT("kernel type not recognized\n");
148  }
149 
150  return 0.0;
151  }
152 
160  inline static float64_t log_kernel(EKernelType kernel, float64_t dist, float64_t width)
161  {
162  switch(kernel)
163  {
164  case K_GAUSSIAN:
165  {
166  return -0.5*dist*dist/(width*width);
167  break;
168  }
169  default:
170  SG_SPRINT("kernel type not recognized\n");
171  }
172 
173  return 0.0;
174  }
175 
176 private:
178  void init();
179 
180 private :
182  float64_t m_bandwidth;
183 
185  int32_t m_leaf_size;
186 
188  float64_t m_atol;
189 
191  float64_t m_rtol;
192 
194  EEvaluationMode m_eval;
195 
197  EKernelType m_kernel_type;
198 
200  EDistanceType m_dist;
201 
203  CNbodyTree* tree;
204 };
205 } /* shogun */
206 
207 #endif /* _KERNELDENSITY_H__ */

SHOGUN Machine Learning Toolbox - Documentation