BayesOpt
criteria_combined.hpp
Go to the documentation of this file.
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 #ifndef _CRITERIA_COMBINED_HPP_
25 #define _CRITERIA_COMBINED_HPP_
26 
27 #include <boost/ptr_container/ptr_vector.hpp>
28 #include <boost/numeric/ublas/vector_proxy.hpp>
29 #include "criteria_functors.hpp"
30 
31 
32 namespace bayesopt
33 {
36 
38  class CombinedCriteria: public Criteria
39  {
40  public:
41  virtual ~CombinedCriteria() {};
42  virtual void init(NonParametricProcess *proc)
43  {
44  mProc = proc;
45  };
46 
47  void pushCriteria(Criteria* crit)
48  {
49  mCriteriaList.push_back(crit);
50  };
51 
52  void setParameters(const vectord &theta)
53  {
54  using boost::numeric::ublas::subrange;
55  const size_t np = mCriteriaList.size();
56  vectori sizes(np);
57 
58  for (size_t i = 0; i < np; ++i)
59  {
60  sizes(i) = mCriteriaList[i].nParameters();
61  }
62 
63  if (theta.size() != norm_1(sizes))
64  {
65  FILE_LOG(logERROR) << "Wrong number of criteria parameters";
66  throw std::invalid_argument("Wrong number of criteria parameters");
67  }
68 
69  size_t start = 0;
70  for (size_t i = 0; i < np; ++i)
71  {
72  mCriteriaList[i].setParameters(subrange(theta,start,start+sizes(i)));
73  start += sizes(i);
74  }
75  };
76 
77  size_t nParameters()
78  {
79  size_t sum = 0;
80  for (size_t i = 0; i < mCriteriaList.size(); ++i)
81  {
82  sum += mCriteriaList[i].nParameters();
83  }
84  return sum;
85  };
86 
87  protected:
88  boost::ptr_vector<Criteria> mCriteriaList;
89  };
90 
92 
93 } //namespace bayesopt
94 
95 
96 #endif
Namespace of the library interface.
Definition: using.dox:1
Abstract class to implement Bayesian regressors.
Abstract class for combined criteria functions.
Abstract interface for criteria functors.
Abstract and factory modules for criteria.