Learning Curve Plus Plus (LCPP)
algo::regression::GaussianProcess< K, T > Class Template Reference

Public Member Functions

template<typename... Ts>
 GaussianProcess (const Ts &... args)
 
template<typename... Ts>
 GaussianProcess (const arma::Mat< T > &inputs, const arma::Row< T > &labels, const T lambda, const Ts &... args)
 
 GaussianProcess (const arma::Mat< T > &inputs, const arma::Row< T > &labels)
 
void Train (const arma::Mat< T > &inputs, const arma::Row< T > &labels)
 
void Predict (const arma::Mat< T > &inputs, arma::Row< T > &labels) const
 
void PredictVariance (const arma::Mat< T > &inputs, arma::Mat< T > &labels)
 
ComputeError (const arma::Mat< T > &inputs, const arma::Row< T > &labels) const
 
LogLikelihood (const arma::Mat< T > &inputs, const arma::Row< T > &labels) const
 
void SamplePrior (const size_t k, const arma::Mat< T > &inputs, arma::Mat< T > &labels) const
 
void SamplePosterior (const size_t k, const arma::Mat< T > &inputs, arma::Mat< T > &labels)
 
const arma::Col< T > & Parameters () const
 
arma::Col< T > & Parameters ()
 
void Lambda (const T &lambda)
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int)
 

Detailed Description

template<class K = mlpack::GaussianKernel, class T = DTYPE>
class algo::regression::GaussianProcess< K, T >

Definition at line 20 of file gp.h.

Constructor & Destructor Documentation

◆ GaussianProcess() [1/3]

template<class K = mlpack::GaussianKernel, class T = DTYPE>
template<typename... Ts>
algo::regression::GaussianProcess< K, T >::GaussianProcess ( const Ts &...  args)
inline

Non-working model

Parameters
args: kernel parameters

Definition at line 29 of file gp.h.

29 : cov_(args...), lambda_(0.0) { };

◆ GaussianProcess() [2/3]

template<class K , class T >
template<class... Ts>
algo::regression::GaussianProcess< K, T >::GaussianProcess ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels,
const T  lambda,
const Ts &...  args 
)
Parameters
X: inputs
y: labels
args: kernel parameters

Definition at line 19 of file gp_impl.h.

22  :
23  cov_(args...), lambda_(lambda)
24 {
25  Train(inputs, labels);
26 }
void Train(const arma::Mat< T > &inputs, const arma::Row< T > &labels)
Definition: gp_impl.h:37

References algo::regression::GaussianProcess< K, T >::Train().

+ Here is the call graph for this function:

◆ GaussianProcess() [3/3]

template<class K , class T >
algo::regression::GaussianProcess< K, T >::GaussianProcess ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels 
)
Parameters
X: inputs
y: labels

Definition at line 29 of file gp_impl.h.

30  :
31  cov_(), lambda_(0.)
32 {
33  Train(inputs, labels);
34 }

References algo::regression::GaussianProcess< K, T >::Train().

+ Here is the call graph for this function:

Member Function Documentation

◆ ComputeError()

template<class K , class T >
T algo::regression::GaussianProcess< K, T >::ComputeError ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels 
) const

Calculate the L2 squared error on the given predictors and responses using this linear regression model. This calculation returns

Parameters
X*: points*
y*: responses*

Definition at line 71 of file gp_impl.h.

73 {
74  arma::Row<T> temp;
75  Predict(inputs, temp);
76  const size_t n_points = inputs.n_cols;
77 
78  temp = labels - temp;
79 
80  const T cost = arma::dot(temp, temp) / n_points;
81 
82  return cost;
83 }
void Predict(const arma::Mat< T > &inputs, arma::Row< T > &labels) const
Definition: gp_impl.h:53

◆ Lambda()

template<class K = mlpack::GaussianKernel, class T = DTYPE>
void algo::regression::GaussianProcess< K, T >::Lambda ( const T &  lambda)
inline

Set Lambda

Parameters
lambda: lambda

Definition at line 118 of file gp.h.

118 { lambda_ = lambda; }

◆ LogLikelihood()

template<class K , class T >
T algo::regression::GaussianProcess< K, T >::LogLikelihood ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels 
) const

Calculate the Log Likelihood of the model given data

Parameters
X*: points*
y*: responses*

Definition at line 86 of file gp_impl.h.

88 {
89  return -0.5*arma::dot(labels,parameters_) - arma::trace(arma::log(L_))
90  - 0.5*T(N_)*std::log(2.*M_PI);
91 }

◆ Parameters()

template<class K = mlpack::GaussianKernel, class T = DTYPE>
const arma::Col<T>& algo::regression::GaussianProcess< K, T >::Parameters ( ) const
inline

Get Parameters

Definition at line 109 of file gp.h.

109 { return parameters_; }

◆ Predict()

template<class K , class T >
void algo::regression::GaussianProcess< K, T >::Predict ( const arma::Mat< T > &  inputs,
arma::Row< T > &  labels 
) const
Parameters
X*: inputs*
y*: labels*

Definition at line 53 of file gp_impl.h.

55 {
56  arma::Mat<T> k_xpx = cov_.GetMatrix(inputs,train_inp_);
57  labels = (k_xpx * parameters_).t();
58 }

◆ PredictVariance()

template<class K , class T >
void algo::regression::GaussianProcess< K, T >::PredictVariance ( const arma::Mat< T > &  inputs,
arma::Mat< T > &  labels 
)
Parameters
X*: inputs*
y*: labels*

Definition at line 61 of file gp_impl.h.

63 {
64  arma::Mat<T> k_xpx = cov_.GetMatrix(inputs,train_inp_);
65  arma::Mat<T> k_xpxp = cov_.GetMatrix(inputs,inputs);
66  arma::Mat<T> v = arma::solve(L_,k_xpx.t());
67  labels = arma::conv_to<arma::Mat<T>>::from((k_xpxp - v.t()*v));
68 }

◆ SamplePosterior()

template<class K , class T >
void algo::regression::GaussianProcess< K, T >::SamplePosterior ( const size_t  k,
const arma::Mat< T > &  inputs,
arma::Mat< T > &  labels 
)

Sample functions from the prior

Parameters
X: inputs
y: labels

Definition at line 94 of file gp_impl.h.

97 {
98  arma::Row<T> mean;
99  arma::Mat<T> cov;
100  Predict(inputs, mean);
101  PredictVariance(inputs, cov);
102  cov.diag() += 1e-6; // jitter addition
103  labels = arma::mvnrnd(mean.t(), cov, M).t();
104 }
void PredictVariance(const arma::Mat< T > &inputs, arma::Mat< T > &labels)
Definition: gp_impl.h:61

◆ SamplePrior()

template<class K , class T >
void algo::regression::GaussianProcess< K, T >::SamplePrior ( const size_t  k,
const arma::Mat< T > &  inputs,
arma::Mat< T > &  labels 
) const

Sample functions from the prior

Parameters
X: inputs
y: labels

Definition at line 107 of file gp_impl.h.

110 {
111  size_t N = inputs.n_cols;
112  arma::Mat<T> cov = cov_.GetMatrix(inputs,inputs);
113  cov.diag() += 1e-6 + lambda_; // jitter addition
114  arma::Col<T> mean(N);
115  labels = arma::mvnrnd(mean, cov, M).t();
116 }

◆ serialize()

template<class K = mlpack::GaussianKernel, class T = DTYPE>
template<typename Archive >
void algo::regression::GaussianProcess< K, T >::serialize ( Archive &  ar,
const unsigned int   
)
inline

Serialize the model.

Definition at line 124 of file gp.h.

125  {
126  ar ( cereal::make_nvp("parameters",parameters_),
127  cereal::make_nvp("train_inp",train_inp_),
128  cereal::make_nvp("lambda",lambda_),
129  cereal::make_nvp("cov",cov_),
130  cereal::make_nvp("N",N_),
131  cereal::make_nvp("L",L_) );
132  }

◆ Train()

template<class K , class T >
void algo::regression::GaussianProcess< K, T >::Train ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels 
)
Parameters
X: inputs
y: labels

Definition at line 37 of file gp_impl.h.

39 {
40  train_inp_ = inputs;
41  N_ = inputs.n_cols;
42 
43  arma::Mat<T> k_xx = cov_.GetMatrix(train_inp_,train_inp_);
44 
45  arma::Mat<T> KLambda = k_xx+
46  (lambda_ + 1.e-6) * arma::eye<arma::Mat<T>>(k_xx.n_rows, k_xx.n_rows);
47 
48  L_ = arma::chol(KLambda, "lower");
49  parameters_ = arma::solve(L_.t(), arma::solve(L_,labels.t()));
50 }

Referenced by algo::regression::GaussianProcess< K, T >::GaussianProcess().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: