SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GaussianNaiveBayes.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Sergey Lisitsyn
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
11 #ifndef GAUSSIANNAIVEBAYES_H_
12 #define GAUSSIANNAIVEBAYES_H_
13 
14 #include <shogun/machine/Machine.h>
17 
18 namespace shogun {
19 
20 class CLabels;
21 class CDotFeatures;
22 class CFeatures;
23 
36 {
37 
38 public:
43 
48  CGaussianNaiveBayes(CFeatures* train_examples, CLabels* train_labels);
49 
53  virtual ~CGaussianNaiveBayes();
54 
58  virtual inline void set_features(CDotFeatures* features)
59  {
61  SG_REF(features);
62  m_features = features;
63  }
64 
68  virtual inline CDotFeatures* get_features()
69  {
71  return m_features;
72  }
73 
78  virtual bool train(CFeatures* data = NULL);
79 
83  virtual CLabels* apply();
84 
89  virtual CLabels* apply(CFeatures* data);
90 
95  virtual float64_t apply(int32_t idx);
96 
100  virtual inline const char* get_name() const { return "GaussianNaiveBayes"; };
101 
106 
107 protected:
108 
111 
113  int32_t m_min_label;
114 
116  int32_t m_num_classes;
117 
119  int32_t m_dim;
120 
123 
126 
129 
136  float64_t inline normal_exp(float64_t x, int32_t l_idx, int32_t f_idx)
137  {
138  return CMath::exp(-CMath::sq(x-m_means.vector[m_dim*l_idx+f_idx])/(2*m_variances.vector[m_dim*l_idx+f_idx]));
139  }
140 
143 };
144 
145 }
146 
147 #endif /* GAUSSIANNAIVEBAYES_H_ */

SHOGUN Machine Learning Toolbox - Documentation