Learning Curve Plus Plus (LCPP)
algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T > Class Template Reference

Public Member Functions

template<class... Ts>
 SemiParamKernelRidge (const arma::Mat< T > &inputs, const arma::Row< T > &labels, const T lambda, const size_t num_funcs, const Ts &... args)
 
template<class... Ts>
 SemiParamKernelRidge (const arma::Mat< T > &inputs, const arma::Row< T > &labels, const T lambda, const T perc, const Ts &... args)
 
template<typename... Ts>
 SemiParamKernelRidge (const Ts &... args)
 
void Train (const arma::Mat< T > &inputs, const arma::Row< T > &labels)
 
void Predict (const arma::Mat< T > &inputs, arma::Row< T > &labels)
 
ComputeError (const arma::Mat< T > &points, const arma::Row< T > &responses)
 
const arma::Row< T > & Parameters () const
 
arma::Row< T > & Parameters ()
 
Lambda () const
 
T & Lambda ()
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int)
 

Detailed Description

template<class KERNEL, class FUNC, class T = DTYPE>
class algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >

Definition at line 166 of file kernelridge.h.

Constructor & Destructor Documentation

◆ SemiParamKernelRidge() [1/2]

template<class KERNEL , class FUNC , class T >
template<class... Ts>
algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::SemiParamKernelRidge ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels,
const T  lambda,
const size_t  num_funcs,
const Ts &...  args 
)
Parameters
inputs: X
labels: y
lambda: regularization hyper-parameter
num_funcs: number of \psi
args: for the kernel hyper-parameters

Definition at line 130 of file kernelridge_impl.h.

135  :
136  cov_(args...), lambda_(lambda), M_(num_funcs), perc_(0.), func_(num_funcs)
137 {
138  Train(inputs, labels);
139 }
void Train(const arma::Mat< T > &inputs, const arma::Row< T > &labels)

References algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::Train().

+ Here is the call graph for this function:

◆ SemiParamKernelRidge() [2/2]

template<class KERNEL , class FUNC , class T = DTYPE>
template<typename... Ts>
algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::SemiParamKernelRidge ( const Ts &...  args)
inline

Non-working model

Definition at line 193 of file kernelridge.h.

193  : cov_(args...),
194  lambda_(0.0),
195  M_(size_t(0)),
196  perc_(T(0)),
197  func_(size_t(0)) { }

Member Function Documentation

◆ ComputeError()

template<class KERNEL , class FUNC , class T >
T algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::ComputeError ( const arma::Mat< T > &  points,
const arma::Row< T > &  responses 
)

Calculate the L2 squared error

Parameters
inputs
labels

Definition at line 199 of file kernelridge_impl.h.

202 {
203  arma::Row<T> temp;
204  Predict(inputs, temp);
205  const size_t n_points = inputs.n_cols;
206 
207  temp = labels - temp;
208 
209  const T cost = (arma::dot(temp, temp) / n_points);
210 
211  return cost;
212 }
void Predict(const arma::Mat< T > &inputs, arma::Row< T > &labels)

◆ Predict()

template<class KERNEL , class FUNC , class T >
void algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::Predict ( const arma::Mat< T > &  inputs,
arma::Row< T > &  labels 
)
Parameters
inputsX*
labelsy*

Definition at line 189 of file kernelridge_impl.h.

191 {
192  arma::Mat<T> K = cov_.GetMatrix(inputs,train_inp_);
193  arma::Mat<T> psi = func_.Predict(inputs);
194  arma::Mat<T> A = arma::join_rows(K, psi.t());
195  labels = (A * parameters_.t()).t() + func_.Mean(inputs);
196 }

◆ serialize()

template<class KERNEL , class FUNC , class T = DTYPE>
template<typename Archive >
void algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::serialize ( Archive &  ar,
const unsigned int   
)
inline

Serialize the model.

Definition at line 232 of file kernelridge.h.

233  {
234  ar ( cereal::make_nvp("parameters",parameters_),
235  cereal::make_nvp("M",M_),
236  cereal::make_nvp("N",N_),
237  cereal::make_nvp("lambda",lambda_),
238  cereal::make_nvp("cov",cov_),
239  cereal::make_nvp("func",func_),
240  cereal::make_nvp("perc",perc_),
241  cereal::make_nvp("train_inp",train_inp_) );
242  }

◆ Train()

template<class KERNEL , class FUNC , class T >
void algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::Train ( const arma::Mat< T > &  inputs,
const arma::Row< T > &  labels 
)
Parameters
inputsX
labelsy

Definition at line 161 of file kernelridge_impl.h.

163 {
164  train_inp_ = inputs;
165  N_ = train_inp_.n_cols;
166 
167  psi_ = func_.Predict(inputs);
168 
169  if (M_ == 0)
170  M_ = func_.GetM();
171 
172  arma::Mat<T> k_xx = cov_.GetMatrix(train_inp_,train_inp_);
173 
174  arma::Mat<T> K = k_xx +
175  (1.e-8) * arma::eye<arma::Mat<T>>(k_xx.n_rows, k_xx.n_rows);
176 
177  arma::Mat<T> A = arma::join_rows(K, psi_.t());
178  arma::Mat<T> B = arma::join_cols(arma::join_rows(K,
179  arma::zeros<arma::Mat<T>>(N_,M_)),
180  arma::zeros<arma::Mat<T>>(M_,N_+M_));
181 
182  parameters_ = arma::conv_to<arma::Row<T>>::from(
183  arma::solve(A.t() * A + lambda_ * B.t(), A.t() * (labels.t()-
184  func_.Mean(inputs).t())));
185 
186 }

Referenced by algo::regression::SemiParamKernelRidge< KERNEL, FUNC, T >::SemiParamKernelRidge().

+ Here is the caller graph for this function:

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