SHOGUN  v3.2.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
GaussianProcessBinaryClassification.cpp
浏览该文件的文档.
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) 2013 Roman Votyakov
8  */
9 
10 #include <shogun/lib/config.h>
11 
12 #ifdef HAVE_EIGEN3
13 
15 
16 using namespace shogun;
17 
20 {
21 }
22 
24  CInferenceMethod* method) : CGaussianProcessMachine(method)
25 {
26  // set labels
27  m_labels=method->get_labels();
28 }
29 
31 {
32 }
33 
35  CFeatures* data)
36 {
37  // check whether given combination of inference method and likelihood
38  // function supports classification
39  REQUIRE(m_method, "Inference method should not be NULL\n")
41  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
42  "binary classification\n", m_method->get_name(), lik->get_name())
43  SG_UNREF(lik);
44 
45  // if regression data equals to NULL, then apply classification on training
46  // features
47  if (!data)
48  data=m_method->get_features();
49  else
50  SG_REF(data);
51 
52  CBinaryLabels* result=new CBinaryLabels(get_mean_vector(data));
53  SG_UNREF(data);
54 
55  return result;
56 }
57 
59 {
60  // check whether given combination of inference method and likelihood
61  // function supports classification
62  REQUIRE(m_method, "Inference method should not be NULL\n")
64  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
65  "binary classification\n", m_method->get_name(), lik->get_name())
66  SG_UNREF(lik);
67 
68  if (data)
69  m_method->set_features(data);
70 
71  // perform inference
73  m_method->update();
74 
75  return true;
76 }
77 
79  CFeatures* data)
80 {
81  // check whether given combination of inference method and likelihood
82  // function supports classification
83  REQUIRE(m_method, "Inference method should not be NULL\n")
85  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
86  "binary classification\n", m_method->get_name(), lik->get_name())
87 
88  SG_REF(data);
91  SG_UNREF(data);
92 
93  // evaluate mean
94  mu=lik->get_predictive_means(mu, s2);
95  SG_UNREF(lik);
96 
97  return mu;
98 }
99 
101  CFeatures* data)
102 {
103  // check whether given combination of inference method and
104  // likelihood function supports classification
105  REQUIRE(m_method, "Inference method should not be NULL\n")
107  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
108  "binary classification\n", m_method->get_name(), lik->get_name())
109 
110  SG_REF(data);
113  SG_UNREF(data);
114 
115  // evaluate variance
116  s2=lik->get_predictive_variances(mu, s2);
117  SG_UNREF(lik);
118 
119  return s2;
120 }
121 
123  CFeatures* data)
124 {
125  // check whether given combination of inference method and likelihood
126  // function supports classification
127  REQUIRE(m_method, "Inference method should not be NULL\n")
129  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
130  "binary classification\n", m_method->get_name(), lik->get_name())
131 
132  SG_REF(data);
135  SG_UNREF(data);
136 
137  // evaluate log probabilities
139  SG_UNREF(lik);
140 
141  // evaluate probabilities
142  p.exp();
143 
144  return p;
145 }
146 
147 #endif /* HAVE_EIGEN3 */
virtual const char * get_name() const =0
virtual CFeatures * get_features()
The Inference Method base class.
virtual void set_features(CFeatures *feat)
A base class for Gaussian Processes.
SGVector< float64_t > get_posterior_variances(CFeatures *data)
#define SG_UNREF(x)
Definition: SGRefObject.h:35
void exp()
exponential of vector elements
CLabels * m_labels
Definition: Machine.h:356
#define REQUIRE(x,...)
Definition: SGIO.h:208
SGVector< float64_t > get_posterior_means(CFeatures *data)
virtual SGVector< float64_t > get_predictive_variances(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const =0
virtual bool update_parameter_hash()
Definition: SGObject.cpp:187
virtual SGVector< float64_t > get_predictive_log_probabilities(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL)
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
#define SG_REF(x)
Definition: SGRefObject.h:34
virtual CLabels * get_labels()
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual SGVector< float64_t > get_predictive_means(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const =0
Binary Labels for binary classification.
Definition: BinaryLabels.h:36
virtual bool supports_binary() const
The Likelihood model base class.
CLikelihoodModel * get_model()

SHOGUN Machine Learning Toolbox - Documentation