SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
classifier
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
>
15
#include <
shogun/mathematics/Math.h
>
16
#include <
shogun/features/DotFeatures.h
>
17
18
namespace
shogun {
19
20
class
CLabels;
21
class
CDotFeatures;
22
class
CFeatures;
23
35
class
CGaussianNaiveBayes
:
public
CMachine
36
{
37
38
public
:
42
CGaussianNaiveBayes
();
43
48
CGaussianNaiveBayes
(
CFeatures
* train_examples,
CLabels
* train_labels);
49
53
virtual
~CGaussianNaiveBayes
();
54
58
virtual
inline
void
set_features
(
CDotFeatures
* features)
59
{
60
SG_UNREF
(
m_features
);
61
SG_REF
(features);
62
m_features
= features;
63
}
64
68
virtual
inline
CDotFeatures
*
get_features
()
69
{
70
SG_REF
(
m_features
);
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
105
virtual
inline
EClassifierType
get_classifier_type
() {
return
CT_GAUSSIANNAIVEBAYES
; };
106
107
protected
:
108
110
CDotFeatures
*
m_features
;
111
113
int32_t
m_min_label
;
114
116
int32_t
m_num_classes
;
117
119
int32_t
m_dim
;
120
122
SGVector<float64_t>
m_means
;
123
125
SGVector<float64_t>
m_variances
;
126
128
SGVector<float64_t>
m_label_prob
;
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
142
SGVector<float64_t>
m_rates
;
143
};
144
145
}
146
147
#endif
/* GAUSSIANNAIVEBAYES_H_ */
SHOGUN
Machine Learning Toolbox - Documentation