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_ */
SGVector< float64_t > m_label_prob
a priori probabilities of labels
EClassifierType
Definition: Machine.h:27
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
static T sq(T x)
x^2
Definition: Math.h:277
Features that support dot products among other operations.
Definition: DotFeatures.h:41
#define SG_REF(x)
Definition: SGObject.h:44
A generic learning machine interface.
Definition: Machine.h:96
SGVector< float64_t > m_rates
label rates
int32_t m_num_classes
number of different classes (labels)
SGVector< float64_t > m_means
means for normal distributions of features
double float64_t
Definition: common.h:56
int32_t m_min_label
minimal label
int32_t m_dim
dimensionality of feature space
float64_t normal_exp(float64_t x, int32_t l_idx, int32_t f_idx)
virtual const char * get_name() const
virtual EClassifierType get_classifier_type()
virtual void set_features(CDotFeatures *features)
#define SG_UNREF(x)
Definition: SGObject.h:45
Class GaussianNaiveBayes, a Gaussian Naive Bayes classifier.
virtual CDotFeatures * get_features()
virtual bool train(CFeatures *data=NULL)
The class Features is the base class of all feature objects.
Definition: Features.h:56
static float64_t exp(float64_t x)
Definition: Math.h:368
SGVector< float64_t > m_variances
variances for normal distributions of features
CDotFeatures * m_features
features for training or classifying

SHOGUN Machine Learning Toolbox - Documentation