SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 inducing features for FITC inference method
60  {
61  CFITCInferenceMethod* fitc_method=
63  feat=fitc_method->get_inducing_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 inducing features for FITC inference method
95  {
96  CFITCInferenceMethod* fitc_method=
98  fitc_method->set_inducing_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
virtual const char * get_name() const =0
virtual CFeatures * get_features()
Real Labels are real-valued labels.
The Inference Method base class.
virtual void set_features(CFeatures *feat)
A base class for Gaussian Processes.
virtual void set_inducing_features(CFeatures *feat)
SGVector< float64_t > get_posterior_variances(CFeatures *data)
virtual bool train_machine(CFeatures *data=NULL)
CLabels * m_labels
Definition: Machine.h:361
#define REQUIRE(x,...)
Definition: SGIO.h:206
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
#define SG_REF(x)
Definition: SGObject.h:51
virtual bool supports_regression() const
SGVector< float64_t > get_variance_vector(CFeatures *data)
virtual CLabels * get_labels()
SGVector< float64_t > get_mean_vector(CFeatures *data)
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Fully Independent Conditional Training inference method class.
virtual EInferenceType get_inference_type() const
virtual SGVector< float64_t > get_predictive_means(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const =0
virtual CFeatures * get_inducing_features()
The Likelihood model base class.
CLikelihoodModel * get_model()
static CFITCInferenceMethod * obtain_from_generic(CInferenceMethod *inference)

SHOGUN Machine Learning Toolbox - Documentation