BayesOpt
inneroptimization.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 
26 #ifndef __INNEROPTIMIZATION_HPP__
27 #define __INNEROPTIMIZATION_HPP__
28 
29 //#include "dll_stuff.h"
30 #include "optimizable.hpp"
31 //#include "optimization.hpp"
32 
33 namespace bayesopt {
34 
35  // We plan to add more in the future since nlopt actually support many of them
36  typedef enum {
42 
43 
44  class NLOPT_Optimization //: public Optimization
45  {
46  public:
47  NLOPT_Optimization(RBOptimizable* rbo, size_t dim);
48  NLOPT_Optimization(RGBOptimizable* rgbo, size_t dim);
49  virtual ~NLOPT_Optimization();
50 
52  void setAlgorithm(innerOptAlgorithms newAlg);
53 
56  void setMaxEvals(size_t meval);
57 
59  void setLimits(const vectord& down, const vectord& up);
60 
62  void setLimits(double down, double up);
63 
69  double run(vectord &Xnext);
70 
77  double localTrialAround(vectord& Xnext);
78 
89  static double evaluate_nlopt (unsigned int n, const double *x,
90  double *grad, void *my_func_data);
91 
102  static double evaluate_nlopt_grad (unsigned int n, const double *x,
103  double *grad, void *my_func_data);
104 
105  private:
106  RBOptimizableWrapper *rbobj;
107  RGBOptimizableWrapper *rgbobj;
108 
109  innerOptAlgorithms alg;
110  std::vector<double> mDown, mUp;
111  size_t maxEvals;
112 
113  private: //Forbidden
116  };
117 
118 
119  inline void NLOPT_Optimization::setAlgorithm(innerOptAlgorithms newAlg)
120  { alg = newAlg; }
121 
122  inline void NLOPT_Optimization::setMaxEvals(size_t meval)
123  { maxEvals = meval; }
124 
125  inline void NLOPT_Optimization::setLimits(const vectord& down, const vectord& up)
126  {
127  std::copy(down.begin(),down.end(),mDown.begin());
128  std::copy(up.begin(),up.end(),mUp.begin());
129  }
130 
131  inline void NLOPT_Optimization::setLimits(double down, double up)
132  {
133  for(size_t i = 0; i<mDown.size();++i)
134  {
135  mDown[i] = down; mUp[i] = up;
136  }
137  };
138 }//namespace bayesopt
139 
140 #endif
double localTrialAround(vectord &Xnext)
Try some local optimization around a point.
Namespace of the library interface.
Definition: using.dox:1
Local, derivative based.
Abstract class for optimizable objects.
Global exploration, local refinement (hand tuned)
void setAlgorithm(innerOptAlgorithms newAlg)
Sets the optimization algorithm.
double run(vectord &Xnext)
Launch the inner optimization algorithm.
Local, derivative free.
static double evaluate_nlopt_grad(unsigned int n, const double *x, double *grad, void *my_func_data)
Wrapper of inner optimization to be evaluated by NLOPT.
Global optimization.
void setLimits(const vectord &down, const vectord &up)
Limits of the hypercube.
static double evaluate_nlopt(unsigned int n, const double *x, double *grad, void *my_func_data)
Wrapper of inner optimization to be evaluated by NLOPT.
void setMaxEvals(size_t meval)
Sets the maximum number of function evaluations.