24 #ifndef _KERNEL_FUNCTORS_HPP_ 25 #define _KERNEL_FUNCTORS_HPP_ 28 #include <boost/scoped_ptr.hpp> 29 #include <boost/math/distributions/normal.hpp> 47 virtual void init(
size_t input_dim) {};
48 virtual void init(
size_t input_dim,
Kernel* left,
Kernel* right) {};
50 virtual void setHyperParameters(
const vectord &theta) = 0;
51 virtual vectord getHyperParameters() = 0;
52 virtual size_t nHyperParameters() = 0;
54 virtual double operator()(
const vectord &x1,
const vectord &x2 ) = 0;
55 virtual double gradient(
const vectord &x1,
const vectord &x2,
56 size_t component ) = 0;
64 template <
typename KernelType>
Kernel * create_func()
66 return new KernelType();
82 Kernel* create(std::string name,
size_t input_dim);
85 typedef Kernel* (*create_func_definition)();
86 std::map<std::string , KernelFactory::create_func_definition> registry;
98 void setHyperParameters(
const vectord &theta);
99 vectord getHyperParameters();
100 size_t nHyperParameters();
109 void setKernel (
const vectord &thetav,
const vectord &stheta,
110 std::string k_name,
size_t dim);
115 void computeCorrMatrix(
const vecOfvec& XX, matrixd& corrMatrix,
double nugget);
116 void computeDerivativeCorrMatrix(
const vecOfvec& XX, matrixd& corrMatrix,
118 vectord computeCrossCorrelation(
const vecOfvec& XX,
const vectord &query);
119 void computeCrossCorrelation(
const vecOfvec& XX,
const vectord &query,
121 double computeSelfCorrelation(
const vectord& query);
122 double kernelLogPrior();
126 void setKernelPrior (
const vectord &theta,
const vectord &s_theta);
132 inline Kernel* KernelModel::getKernel()
133 {
return mKernel.get(); }
135 inline void KernelModel::setHyperParameters(
const vectord &theta)
136 { mKernel->setHyperParameters(theta); };
138 inline vectord KernelModel::getHyperParameters()
139 {
return mKernel->getHyperParameters();};
141 inline size_t KernelModel::nHyperParameters()
142 {
return mKernel->nHyperParameters();};
144 inline vectord KernelModel::computeCrossCorrelation(
const vecOfvec& XX,
145 const vectord &query)
147 vectord knx(XX.size());
148 computeCrossCorrelation(XX,query,knx);
152 inline void KernelModel::computeCrossCorrelation(
const vecOfvec& XX,
153 const vectord &query,
156 std::vector<vectord>::const_iterator x_it = XX.begin();
157 vectord::iterator k_it = knx.begin();
158 while(x_it != XX.end())
159 { *k_it++ = (*mKernel)(*x_it++, query); }
163 inline double KernelModel::computeSelfCorrelation(
const vectord& query)
164 {
return (*mKernel)(query,query); }
167 const vectord &s_theta)
169 for (
size_t i = 0; i<theta.size(); ++i)
171 boost::math::normal n(theta(i),s_theta(i));
172 priorKernel.push_back(n);
Boost vector and matrix types.
Namespace of the library interface.
Factory model for kernel functions This factory is based on the libgp library by Manuel Blum https://...
void setKernelPrior(const vectord &theta, const vectord &s_theta)
Set prior (Gaussian) for kernel hyperparameters.
boost::scoped_ptr< Kernel > mKernel
Pointer to kernel function.
Interface for kernel functors.
std::vector< boost::math::normal > priorKernel
Prior of kernel parameters.