BayesOpt
dataset.cpp
1 /*
2 -------------------------------------------------------------------------
3  This file is part of BayesOpt, an efficient C++ library for
4  Bayesian optimization.
5 
6  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
7 
8  BayesOpt is free software: you can redistribute it and/or modify it
9  under the terms of the GNU Affero General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BayesOpt is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Affero General Public License for more details.
17 
18  You should have received a copy of the GNU Affero General Public License
19  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
20 ------------------------------------------------------------------------
21 */
22 
23 #include "dataset.hpp"
24 
25 #include <boost/numeric/ublas/matrix_proxy.hpp>
26 
27 namespace bayesopt
28 {
29 
30  Dataset::Dataset(): mMinIndex(0), mMaxIndex(0) {};
31 
32  Dataset::Dataset(const matrixd& x, const vectord& y):
33  mMinIndex(0), mMaxIndex(0)
34  {
35  setSamples(x,y);
36  };
37 
38  Dataset::~Dataset(){};
39 
40  void Dataset::setSamples(const matrixd &x, const vectord &y)
41  {
42  // WARNING: It assumes mX is empty
43  mY = y;
44  for (size_t i=0; i<x.size1(); ++i)
45  {
46  mX.push_back(row(x,i));
47  updateMinMax(i);
48  }
49  };
50 
51  void Dataset::setSamples(const vectord &y)
52  {
53  mY = y;
54  for (size_t i=0; i<y.size(); ++i)
55  {
56  updateMinMax(i);
57  }
58  };
59 
60 
61  void Dataset::setSamples(const matrixd &x)
62  {
63  for (size_t i=0; i<x.size1(); ++i)
64  {
65  mX.push_back(row(x,i));
66  }
67  };
68 
69  void Dataset::plotData(TLogLevel level)
70  {
71  // For logging purpose
72  FILE_LOG(level) << "Initial points:" ;
73  for(size_t i = 0; i < mY.size(); i++)
74  {
75  FILE_LOG(level) << "X:" << mX[i]
76  << "|Y:" << mY(i);
77  }
78  const double yPoint = getValueAtMinimum();
79  const vectord xPoint = getPointAtMinimum();
80  FILE_LOG(level) << "Best point so far:" ;
81  FILE_LOG(level) << "X:" << xPoint
82  << "|Y:" << yPoint;
83 
84  } // plotData
85 
86 
87 } //namespace bayesopt
Dataset model.
Namespace of the library interface.
Definition: using.dox:1