BayesOpt
criteria_functors.hpp
Go to the documentation of this file.
1 
3 /*
4 -------------------------------------------------------------------------
5  This file is part of BayesOpt, an efficient C++ library for
6  Bayesian optimization.
7 
8  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
9 
10  BayesOpt is free software: you can redistribute it and/or modify it
11  under the terms of the GNU Affero General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  BayesOpt is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Affero General Public License for more details.
19 
20  You should have received a copy of the GNU Affero General Public License
21  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
22 ------------------------------------------------------------------------
23 */
24 
25 #ifndef _CRITERIA_FUNCTORS_HPP_
26 #define _CRITERIA_FUNCTORS_HPP_
27 
28 #include <map>
29 #include "nonparametricprocess.hpp"
30 
31 namespace bayesopt
32 {
33 
39 
43  class Criteria
44  {
45  public:
46  virtual ~Criteria() {};
47  virtual void init(NonParametricProcess *proc) { mProc = proc; };
48 
49  double evaluate(const vectord &x) {return (*this)(x);}
50  virtual double operator() (const vectord &x) = 0;
51 
52  virtual std::string name() = 0;
53  virtual void setParameters(const vectord &params) = 0;
54  virtual size_t nParameters() = 0;
55 
56  //Dummy functions. Not all criteria support these methods.
57  virtual void reset() { assert(false); };
58  void setRandomEngine(randEngine& eng){ mtRandom = &eng; }
59 
60  // In general, most criteria does not support comparisons!
61  // TODO: Consider throwing exception when incorrect calls
62  virtual void pushCriteria(Criteria* crit){};
63  virtual bool requireComparison(){ return false; };
64  virtual void initialCriteria(){};
65  virtual void update(const vectord &x){};
66  virtual bool rotateCriteria(){return false;};
67  virtual void pushResult(const vectord& prevResult){};
68  virtual std::string getBestCriteria(vectord& best)
69  { assert(false); return name(); };
70 
71  protected:
72  NonParametricProcess *mProc;
73  randEngine* mtRandom;
74  };
75 
76 
85  {
86  public:
87  CriteriaFactory ();
88  virtual ~CriteriaFactory () {};
89 
90  //Criteria* create(criterium_name name, NonParametricProcess* proc);
91  Criteria* create(std::string name, NonParametricProcess* proc);
92 
93  private:
94  typedef Criteria* (*create_func_definition)();
95  std::map<std::string , CriteriaFactory::create_func_definition> registry;
96  };
97 
98 
100 
101 } //namespace bayesopt
102 
103 
104 #endif
Factory model for criterion functions This factory is based on the libgp library by Manuel Blum https...
Namespace of the library interface.
Definition: using.dox:1
Abstract class to implement Bayesian regressors.
Abstract module for a Bayesian regressor.
Abstract interface for criteria functors.