SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GaussianProcessRegression.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  * Copyright (C) 2012 Jacob Walker
9  * Copyright (C) 2013 Roman Votyakov
10  *
11  * Code adapted from Gaussian Process Machine Learning Toolbox
12  * http://www.gaussianprocess.org/gpml/code/matlab/doc/
13  */
14 
16 
17 #ifdef HAVE_EIGEN3
18 
19 #include <shogun/io/SGIO.h>
21 
22 using namespace shogun;
23 
26 {
27 }
28 
30  : CGaussianProcessMachine(method)
31 {
32  // set labels
33  m_labels=method->get_labels();
34 }
35 
37 {
38 }
39 
41 {
42  // check whether given combination of inference method and likelihood
43  // function supports regression
44  REQUIRE(m_method, "Inference method should not be NULL\n")
46  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
47  "regression\n", m_method->get_name(), lik->get_name())
48  SG_UNREF(lik);
49 
50  CRegressionLabels* result;
51 
52  // if regression data equals to NULL, then apply regression on training
53  // features
54  if (!data)
55  {
56  CFeatures* feat;
57 
58  // use latent features for FITC inference method
60  {
61  CFITCInferenceMethod* fitc_method=
63  feat=fitc_method->get_latent_features();
64  SG_UNREF(fitc_method);
65  }
66  else
67  feat=m_method->get_features();
68 
69  result=new CRegressionLabels(get_mean_vector(feat));
70 
71  SG_UNREF(feat);
72  }
73  else
74  {
75  result=new CRegressionLabels(get_mean_vector(data));
76  }
77 
78  return result;
79 }
80 
82 {
83  // check whether given combination of inference method and likelihood
84  // function supports regression
85  REQUIRE(m_method, "Inference method should not be NULL\n")
87  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
88  "regression\n", m_method->get_name(), lik->get_name())
89  SG_UNREF(lik);
90 
91  if (data)
92  {
93  // set latent features for FITC inference method
95  {
96  CFITCInferenceMethod* fitc_method=
98  fitc_method->set_latent_features(data);
99  SG_UNREF(fitc_method);
100  }
101  else
102  m_method->set_features(data);
103  }
104 
105  // perform inference
106  m_method->update();
107 
108  return true;
109 }
110 
112 {
113  // check whether given combination of inference method and likelihood
114  // function supports regression
115  REQUIRE(m_method, "Inference method should not be NULL\n")
117  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
118  "regression\n", m_method->get_name(), lik->get_name())
119  SG_UNREF(lik);
120 
121  SG_REF(data);
124  SG_UNREF(data);
125 
126  // evaluate mean
127  lik=m_method->get_model();
128  mu=lik->get_predictive_means(mu, s2);
129  SG_UNREF(lik);
130 
131  return mu;
132 }
133 
135  CFeatures* data)
136 {
137  // check whether given combination of inference method and likelihood
138  // function supports regression
139  REQUIRE(m_method, "Inference method should not be NULL\n")
141  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
142  "regression\n", m_method->get_name(), lik->get_name())
143 
144  SG_REF(data);
147  SG_UNREF(data);
148 
149  // evaluate variance
150  s2=lik->get_predictive_variances(mu, s2);
151  SG_UNREF(lik);
152 
153  return s2;
154 }
155 
156 #endif

SHOGUN Machine Learning Toolbox - Documentation