BayesOpt
gridsampling.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 _GRIDSAMPLING_HPP_
25 #define _GRIDSAMPLING_HPP_
26 
27 #include "specialtypes.hpp"
28 
29 namespace bayesopt
30 {
31  namespace utils
32  {
33 
34  void deepenGrid(size_t comp, const vectori ndivs,
35  vectord& x, vecOfvec& result)
36  {
37  if (comp == x.size())
38  {
39  result.push_back(x);
40  }
41  else
42  {
43  for (size_t i = 0; i<ndivs(comp); ++i)
44  {
45  x(comp) = static_cast<double>(i);
46  deepenGrid(comp+1,ndivs, x, result);
47  }
48  }
49  };
50 
51  void buildGrid(const vectori& dims, vecOfvec& result)
52  {
53  if (result.size()){ result.clear(); }
54 
55  vectord x(dims.size());
56  deepenGrid(0,dims,x,result);
57  };
58 
59 
60  } //namespace utils
61 
62 } //namespace bayesopt
63 
64 #endif
Boost vector and matrix types.
Namespace of the library interface.
Definition: using.dox:1