BayesOpt
posterior_empirical.hpp
1 
2 /*
3 -------------------------------------------------------------------------
4  This file is part of BayesOpt, an efficient C++ library for
5  Bayesian optimization.
6 
7  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
8 
9  BayesOpt is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Affero General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  BayesOpt is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Affero General Public License for more details.
18 
19  You should have received a copy of the GNU Affero General Public License
20  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
21 ------------------------------------------------------------------------
22 */
23 
24 
25 #ifndef _EMPIRICALBAYES_HPP_
26 #define _EMPIRICALBAYES_HPP_
27 
28 #include <boost/scoped_ptr.hpp>
29 #include "criteria_functors.hpp"
30 #include "posteriormodel.hpp"
31 
32 namespace bayesopt {
33 
38 
39  class NLOPT_Optimization;
40 
46  {
47  public:
52  EmpiricalBayes(size_t dim, Parameters params, randEngine& eng);
53 
57  virtual ~EmpiricalBayes();
58 
59  void updateHyperParameters();
60  void fitSurrogateModel();
61  void updateSurrogateModel();
62 
63  double evaluateCriteria(const vectord& query);
64  void updateCriteria(const vectord& query);
65 
66  bool criteriaRequiresComparison();
67  void setFirstCriterium();
68  bool setNextCriterium(const vectord& prevResult);
69  std::string getBestCriteria(vectord& best);
70 
71  ProbabilityDistribution* getPrediction(const vectord& query);
72 
73  private:
75 
76  void setSurrogateModel(randEngine& eng);
77  void setCriteria(randEngine& eng);
78 
79  private: // Members
80  boost::scoped_ptr<NonParametricProcess> mGP;
81  boost::scoped_ptr<Criteria> mCrit;
82 
83  boost::scoped_ptr<NLOPT_Optimization> kOptimizer;
84  };
85 
88  inline void EmpiricalBayes::fitSurrogateModel()
89  { mGP->fitSurrogateModel(); };
90 
91  inline void EmpiricalBayes::updateSurrogateModel()
92  { mGP->updateSurrogateModel(); };
93 
94  inline double EmpiricalBayes::evaluateCriteria(const vectord& query)
95  { return (*mCrit)(query); };
96 
97  inline void EmpiricalBayes::updateCriteria(const vectord& query)
98  { return mCrit->update(query); };
99 
100  inline bool EmpiricalBayes::criteriaRequiresComparison()
101  {return mCrit->requireComparison(); };
102 
103  inline void EmpiricalBayes::setFirstCriterium()
104  { mCrit->initialCriteria(); };
105 
106  inline bool EmpiricalBayes::setNextCriterium(const vectord& prevResult)
107  {
108  mCrit->pushResult(prevResult);
109  return mCrit->rotateCriteria();
110  };
111 
112  inline std::string EmpiricalBayes::getBestCriteria(vectord& best)
113  { return mCrit->getBestCriteria(best); };
114 
115  inline ProbabilityDistribution* EmpiricalBayes::getPrediction(const vectord& query)
116  { return mGP->prediction(query); };
117 
118 
119 } //namespace bayesopt
120 
121 
122 #endif
Bayesian optimization using different non-parametric processes as distributions over surrogate functi...
virtual ~EmpiricalBayes()
Default destructor.
Namespace of the library interface.
Definition: using.dox:1
Abstract interface for posterior model/criteria.
boost::scoped_ptr< NonParametricProcess > mGP
Pointer to surrogate model.
Abstract and factory modules for criteria.
boost::scoped_ptr< Criteria > mCrit
Metacriteria model.
Bayesian optimization using different non-parametric processes as distributions over surrogate functi...