24 #ifndef _MEAN_FUNCTORS_HPP_ 25 #define _MEAN_FUNCTORS_HPP_ 28 #include <boost/scoped_ptr.hpp> 29 #include <boost/numeric/ublas/matrix_proxy.hpp> 45 virtual int init(
size_t input_dim) {
return 0;};
49 virtual void setParameters(
const vectord& params) = 0;
50 virtual vectord getParameters() = 0;
51 virtual size_t nParameters() = 0;
53 virtual double getMean(
const vectord& x) = 0;
54 virtual vectord operator()(
const vecOfvec& x)
56 vectord result(x.size());
57 std::vector<vectord>::const_iterator x_it = x.begin();
58 std::vector<vectord>::const_iterator x_end = x.end();
59 vectord::iterator res_it = result.begin();
62 *res_it++ = getMean(*x_it++);
68 virtual size_t nFeatures() = 0;
69 virtual vectord getFeatures(
const vectord& x) = 0;
70 virtual matrixd getAllFeatures(
const vecOfvec& x)
72 size_t nf = nFeatures();
73 matrixd result(nf,x.size());
75 for(
size_t ii=0; ii< x.size(); ++ii)
77 column(result,ii) = getFeatures(x[ii]);
92 return new MeanType();
113 std::map<std::string , MeanFactory::create_func_definition> registry;
124 void setParameters(
const vectord &theta);
125 vectord getParameters();
126 size_t nParameters();
128 vectord getFeatures(
const vectord& x);
129 void getFeatures(
const vectord& x, vectord& kx);
132 void setPoints(
const vecOfvec &x);
133 void addNewPoint(
const vectord &x);
135 vectord muTimesFeat();
136 double muTimesFeat(
const vectord& x);
147 void setMean (
const vectord &muv,
const vectord &smu,
148 std::string m_name,
size_t dim);
159 boost::scoped_ptr<ParametricFunction>
mMean;
165 {
return mMean.get(); }
167 inline void MeanModel::setParameters(
const vectord &theta)
168 { mMean->setParameters(theta); };
170 inline vectord MeanModel::getParameters(){
return mMean->getParameters();};
171 inline size_t MeanModel::nParameters(){
return mMean->nParameters();};
173 inline vectord MeanModel::getFeatures(
const vectord& x)
174 {
return mMean->getFeatures(x); }
176 inline void MeanModel::getFeatures(
const vectord& x, vectord& kx)
177 { kx = mMean->getFeatures(x); }
179 inline size_t MeanModel::nFeatures()
180 {
return mMean->nFeatures(); }
182 inline void MeanModel::setPoints(
const vecOfvec &x)
183 { mFeatM = mMean->getAllFeatures(x); };
185 inline void MeanModel::addNewPoint(
const vectord &x)
187 using boost::numeric::ublas::column;
189 mFeatM.resize(mFeatM.size1(),mFeatM.size2()+1);
190 column(mFeatM,mFeatM.size2()-1) = mMean->getFeatures(x);
193 inline vectord MeanModel::muTimesFeat()
194 {
return boost::numeric::ublas::prod(mMu,mFeatM); }
196 inline double MeanModel::muTimesFeat(
const vectord& x)
197 {
return boost::numeric::ublas::inner_prod(mMu,mMean->getFeatures(x));}
Boost vector and matrix types.
Namespace of the library interface.
Factory model for parametric functions This factory is based on the libgp library by Manuel Blum http...
Interface for mean functors.
vectord mS_Mu
Variance of the params of the mean function W=mS_Mu*I.
boost::scoped_ptr< ParametricFunction > mMean
Pointer to mean function.
matrixd mFeatM
Value of the mean features at the input points.
vectord mMu
Mean of the parameters of the mean function.