SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GaussianProcessBinaryClassification.cpp
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) 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
72  m_method->update();
73 
74  return true;
75 }
76 
78  CFeatures* data)
79 {
80  // check whether given combination of inference method and likelihood
81  // function supports classification
82  REQUIRE(m_method, "Inference method should not be NULL\n")
84  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
85  "binary classification\n", m_method->get_name(), lik->get_name())
86 
87  SG_REF(data);
90  SG_UNREF(data);
91 
92  // evaluate mean
93  mu=lik->get_predictive_means(mu, s2);
94  SG_UNREF(lik);
95 
96  return mu;
97 }
98 
100  CFeatures* data)
101 {
102  // check whether given combination of inference method and
103  // likelihood function supports classification
104  REQUIRE(m_method, "Inference method should not be NULL\n")
106  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
107  "binary classification\n", m_method->get_name(), lik->get_name())
108 
109  SG_REF(data);
112  SG_UNREF(data);
113 
114  // evaluate variance
115  s2=lik->get_predictive_variances(mu, s2);
116  SG_UNREF(lik);
117 
118  return s2;
119 }
120 
122  CFeatures* data)
123 {
124  // check whether given combination of inference method and likelihood
125  // function supports classification
126  REQUIRE(m_method, "Inference method should not be NULL\n")
128  REQUIRE(m_method->supports_binary(), "%s with %s doesn't support "
129  "binary classification\n", m_method->get_name(), lik->get_name())
130 
131  SG_REF(data);
134  SG_UNREF(data);
135 
136  // evaluate log probabilities
138  SG_UNREF(lik);
139 
140  // evaluate probabilities
141  p.exp();
142 
143  return p;
144 }
145 
146 #endif /* HAVE_EIGEN3 */

SHOGUN Machine Learning Toolbox - Documentation