BayesOpt
dataset.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 __DATASET_HPP__
27 #define __DATASET_HPP__
28 
29 #include "log.hpp"
30 #include "specialtypes.hpp"
31 #include "ublas_extra.hpp"
32 
33 namespace bayesopt
34 {
35 
40  class Dataset
41  {
42  public:
43  Dataset();
44  Dataset(const matrixd& x, const vectord& y);
45  virtual ~Dataset();
46 
47  void setSamples(const matrixd &x, const vectord &y);
48  void setSamples(const matrixd &x);
49  void setSamples(const vectord &y);
50  void addSample(const vectord &x, double y);
51  double getSampleY(size_t index) const;
52  vectord getSampleX(size_t index) const;
53  double getLastSampleY() const;
54  vectord getLastSampleX() const;
55 
56  void plotData(TLogLevel level);
57 
58  vectord getPointAtMinimum() const;
59  double getValueAtMinimum() const;
60  size_t getNSamples() const;
61  void updateMinMax( size_t i );
62 
63  vecOfvec mX;
64  vectord mY;
65 
66  private:
67  size_t mMinIndex, mMaxIndex;
68  };
69 
70 
72 
73  inline void Dataset::addSample(const vectord &x, double y)
74  {
75  mX.push_back(x); utils::append(mY,y);
76  updateMinMax(mY.size()-1);
77  }
78 
79  inline double Dataset::getSampleY(size_t index) const
80  { return mY(index); }
81 
82  inline vectord Dataset::getSampleX(size_t index) const
83  { return mX[index]; }
84 
85  inline double Dataset::getLastSampleY() const
86  { return mY(mY.size()-1); }
87 
88  inline vectord Dataset::getLastSampleX() const
89  { return mX[mX.size()-1]; }
90 
91 
92  inline vectord Dataset::getPointAtMinimum() const { return mX[mMinIndex]; };
93  inline double Dataset::getValueAtMinimum() const { return mY(mMinIndex); };
94  inline size_t Dataset::getNSamples() const { return mY.size(); };
95  inline void Dataset::updateMinMax( size_t i )
96  {
97  if ( mY(mMinIndex) > mY(i) ) mMinIndex = i;
98  else if ( mY(mMaxIndex) < mY(i) ) mMaxIndex = i;
99  };
100 
103 } //namespace bayesopt
104 
105 #endif
Boost vector and matrix types.
Namespace of the library interface.
Definition: using.dox:1
Dataset model to deal with the vector (real) based datasets.
Definition: dataset.hpp:40
Extra functions for Ublas library.
Modules and helper macros for logging.
vectord mY
Data values.
Definition: dataset.hpp:64
vecOfvec mX
Data inputs.
Definition: dataset.hpp:63