BayesOpt
criteria_functors.cpp
1 /*
2 -------------------------------------------------------------------------
3  This file is part of BayesOpt, an efficient C++ library for
4  Bayesian optimization.
5 
6  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
7 
8  BayesOpt is free software: you can redistribute it and/or modify it
9  under the terms of the GNU Affero General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BayesOpt is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Affero General Public License for more details.
17 
18  You should have received a copy of the GNU Affero General Public License
19  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
20 ------------------------------------------------------------------------
21 */
22 #include <string>
23 #include "parser.hpp"
24 #include "criteria_functors.hpp"
25 
28 #include "criteria/criteria_ei.hpp"
29 #include "criteria/criteria_mi.hpp"
34 
39 
40 namespace bayesopt
41 {
42 
43  template <typename CriteriaType> Criteria * create_func()
44  {
45  return new CriteriaType();
46  }
47 
48 
49  CriteriaFactory::CriteriaFactory()
50  {
51  registry["cMI"] = & create_func<MutualInformation>;
52  registry["cEI"] = & create_func<ExpectedImprovement>;
53  registry["cBEI"] = & create_func<BiasedExpectedImprovement>;
54  registry["cEIa"] = & create_func<AnnealedExpectedImprovement>;
55  registry["cLCB"] = & create_func<LowerConfidenceBound>;
56  registry["cLCBa"] = & create_func<AnnealedLowerConfindenceBound>;
57  registry["cPOI"] = & create_func<ProbabilityOfImprovement>;
58  registry["cAopt"] = & create_func<GreedyAOptimality>;
59  registry["cExpReturn"] = & create_func<ExpectedReturn>;
60  registry["cOptimisticSampling"] = & create_func<OptimisticSampling>;
61  registry["cThompsonSampling"] = & create_func<ThompsonSampling>;
62  registry["cDistance"] = & create_func<InputDistance>;
63 
64  registry["cSum"] = & create_func<SumCriteria>;
65  registry["cProd"] = & create_func<ProdCriteria>;
66  registry["cHedge"] = & create_func<GP_Hedge>;
67  registry["cHedgeRandom"] = & create_func<GP_Hedge_Random>;
68  }
69 
70 
81  Criteria* CriteriaFactory::create(std::string name,
83  {
84  Criteria *cFunc;
85  std::string os;
86  std::vector<std::string> osc;
87  utils::parseExpresion(name,os,osc);
88 
89  std::map<std::string,CriteriaFactory::create_func_definition>::iterator it = registry.find(os);
90  if (it == registry.end())
91  {
92  throw std::invalid_argument("Parsing error: Criteria not found: " + os);
93  return NULL;
94  }
95  cFunc = it->second();
96  if (osc.size() == 0)
97  {
98  cFunc->init(proc);
99  }
100  else
101  {
102  for(size_t i = 0; i < osc.size(); ++i)
103  {
104  cFunc->pushCriteria(create(osc[i],proc));
105  }
106  cFunc->init(proc); //Requires to know the number of criteria
107  }
108  return cFunc;
109  };
110 
111 
112 } //namespace bayesopt
Sum of multiple criteria.
Thompson and optimistic sampling criteria.
Criterion based on the expected value of the function.
Portfolio selection of criteria based on Hedge algorithm.
Namespace of the library interface.
Definition: using.dox:1
Product of multiple criteria.
Abstract class to implement Bayesian regressors.
Probability of improvement.
Criteria * create(std::string name, NonParametricProcess *proc)
Factory model for criterion functions This function is based on the libgp library by Manuel Blum http...
Lower confidence bound based criteria.
Functions to parse strings.
Expected improvement based criteria.
Abstract interface for criteria functors.
Abstract and factory modules for criteria.
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
A-optimality (uncertainty) based criteria.
Cost for selecting distant points.
Abstract module for combined criteria.