BayesOpt
mean_functors.cpp
1 #include "log.hpp"
2 #include "parser.hpp"
3 #include "ublas_extra.hpp"
4 #include "mean_functors.hpp"
5 #include "mean_atomic.hpp"
6 #include "mean_combined.hpp"
7 
8 namespace bayesopt
9 {
10 
11  MeanFactory::MeanFactory()
12  {
13  registry["mZero"] = & create_func<ZeroFunction>;
14  registry["mOne"] = & create_func<OneFunction>;
15  registry["mConst"] = & create_func<ConstantFunction>;
16  registry["mLinear"] = & create_func<LinearFunction>;
17  registry["mSum"] = & create_func<SumFunction>;
18  }
19 
20 
31  ParametricFunction* MeanFactory::create(std::string name, size_t input_dim)
32  {
33  ParametricFunction *mFunc;
34  std::string os, os1, os2;
35  utils::parseExpresion(name,os,os1,os2);
36 
37  std::map<std::string,MeanFactory::create_func_definition>::iterator it = registry.find(os);
38  if (it == registry.end())
39  {
40  FILE_LOG(logERROR) << "Error: Fatal error while parsing mean function: "
41  << os << " not found" << std::endl;
42  return NULL;
43  }
44  mFunc = registry.find(os)->second();
45  if (os1.length() == 0 && os2.length() == 0)
46  {
47  mFunc->init(input_dim);
48  }
49  else
50  {
51  mFunc->init(input_dim, create(os1,input_dim),
52  create(os2,input_dim));
53  }
54  return mFunc;
55 
56  };
57 
59 
60  MeanModel::MeanModel(size_t dim, Parameters parameters)
61  {
62  setMean(parameters.mean,dim);
63  }
64 
65  void MeanModel::setMean (const vectord &muv,
66  const vectord &smu,
67  std::string m_name,
68  size_t dim)
69  {
70  MeanFactory mPFactory;
71 
72  mMean.reset(mPFactory.create(m_name,dim));
73 
74  if ("mZero" == m_name)
75  {
76  mMu = zvectord(1);
77  mS_Mu = svectord(1,1e-10);
78  }
79  else if("mOne" == m_name)
80  {
81  mMu = svectord(1,1.0);
82  mS_Mu = svectord(1,1e-10);
83  }
84  else
85  {
86  mMu = muv; mS_Mu = smu;
87  }
88 
89  mMean->setParameters(mMu);
90  }
91 
92  void MeanModel::setMean (MeanParameters mean, size_t dim)
93  {
94  size_t n_mu = mean.coef_mean.size();
95  vectord vmu = mean.coef_mean;
96  vectord smu = mean.coef_std;
97  setMean(vmu, smu, mean.name, dim);
98  };
99 
100 }//namespace bayesopt
101 
102 
103 
void setMean(const vectord &muv, const vectord &smu, std::string m_name, size_t dim)
Select the parametric part of the surrogate process.
Parametric functions that combine other functions.
std::string name
Name of the mean function.
Definition: parameters.hpp:53
vectord coef_std
Basis function coefficients (std)
Definition: parameters.hpp:55
MeanParameters mean
Mean (parametric function) parameters.
Definition: parameters.hpp:108
Namespace of the library interface.
Definition: using.dox:1
vectord coef_mean
Basis function coefficients (mean)
Definition: parameters.hpp:54
ParametricFunction * create(std::string name, size_t input_dim)
Factory model for kernel functions This function is based on the libgp library by Manuel Blum https:/...
Factory model for parametric functions This factory is based on the libgp library by Manuel Blum http...
Interface for mean functors.
Functions to parse strings.
Extra functions for Ublas library.
void parseExpresion(std::string input, std::string &parent, std::string &child1, std::string &child2)
Parse expresions of the form Parent(Child1, Child2).
Definition: parser.cpp:35
Modules and helper macros for logging.
Atomic (simple) parametric functions.
Mean (parametric) functions.