SHOGUN  4.2.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 
15 
17 #include <shogun/io/SGIO.h>
19 
20 using namespace shogun;
21 
24 {
25 }
26 
28  : CGaussianProcessMachine(method)
29 {
30  // set labels
31  m_labels=method->get_labels();
32 }
33 
35 {
36 }
37 
39 {
40  // check whether given combination of inference method and likelihood
41  // function supports regression
42  REQUIRE(m_method, "Inference method should not be NULL\n")
44  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
45  "regression\n", m_method->get_name(), lik->get_name())
46  SG_UNREF(lik);
47 
48  CRegressionLabels* result;
49 
50  // if regression data equals to NULL, then apply regression on training
51  // features
52  if (!data)
53  {
54  CFeatures* feat;
55 
56  // use inducing features for FITC inference method
58  {
59  CFITCInferenceMethod* fitc_method=
61  feat=fitc_method->get_inducing_features();
62  SG_UNREF(fitc_method);
63  }
64  else
65  feat=m_method->get_features();
66 
67  result=new CRegressionLabels(get_mean_vector(feat));
68 
69  SG_UNREF(feat);
70  }
71  else
72  {
73  result=new CRegressionLabels(get_mean_vector(data));
74  }
75 
76  return result;
77 }
78 
80 {
81  // check whether given combination of inference method and likelihood
82  // function supports regression
83  REQUIRE(m_method, "Inference method should not be NULL\n")
85  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
86  "regression\n", m_method->get_name(), lik->get_name())
87  SG_UNREF(lik);
88 
89  if (data)
90  {
91  // set inducing features for FITC inference method
93  {
94  CFITCInferenceMethod* fitc_method=
96  fitc_method->set_inducing_features(data);
97  SG_UNREF(fitc_method);
98  }
99  else
100  m_method->set_features(data);
101  }
102 
103  // perform inference
104  m_method->update();
105 
106  return true;
107 }
108 
110 {
111  // check whether given combination of inference method and likelihood
112  // function supports regression
113  REQUIRE(m_method, "Inference method should not be NULL\n")
115  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
116  "regression\n", m_method->get_name(), lik->get_name())
117  SG_UNREF(lik);
118 
119  SG_REF(data);
122  SG_UNREF(data);
123 
124  // evaluate mean
125  lik=m_method->get_model();
126  mu=lik->get_predictive_means(mu, s2);
127  SG_UNREF(lik);
128 
129  return mu;
130 }
131 
133  CFeatures* data)
134 {
135  // check whether given combination of inference method and likelihood
136  // function supports regression
137  REQUIRE(m_method, "Inference method should not be NULL\n")
139  REQUIRE(m_method->supports_regression(), "%s with %s doesn't support "
140  "regression\n", m_method->get_name(), lik->get_name())
141 
142  SG_REF(data);
145  SG_UNREF(data);
146 
147  // evaluate variance
148  s2=lik->get_predictive_variances(mu, s2);
149  SG_UNREF(lik);
150 
151  return s2;
152 }
virtual const char * get_name() const =0
virtual void update()
Definition: Inference.cpp:314
virtual void set_inducing_features(CFeatures *feat)
Real Labels are real-valued labels.
A base class for Gaussian Processes.
virtual EInferenceType get_inference_type() const
Definition: Inference.h:104
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
virtual CLabels * get_labels()
Definition: Inference.h:317
virtual CFeatures * get_features()
Definition: Inference.h:266
#define SG_REF(x)
Definition: SGObject.h:51
static CFITCInferenceMethod * obtain_from_generic(CInference *inference)
virtual bool supports_regression() const
Definition: Inference.h:364
SGVector< float64_t > get_variance_vector(CFeatures *data)
virtual CFeatures * get_inducing_features()
CLikelihoodModel * get_model()
Definition: Inference.h:334
virtual void set_features(CFeatures *feat)
Definition: Inference.h:272
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
The Inference Method base class.
Definition: Inference.h:81
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 SGVector< float64_t > get_predictive_means(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL) const =0
The Likelihood model base class.

SHOGUN Machine Learning Toolbox - Documentation