BayesOpt
posteriormodel.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 "log.hpp"
24 #include "posteriormodel.hpp"
25 #include "posterior_fixed.hpp"
26 #include "posterior_empirical.hpp"
27 #include "posterior_mcmc.hpp"
28 
29 namespace bayesopt
30 {
31 
32  PosteriorModel* PosteriorModel::create(size_t dim, Parameters params, randEngine& eng)
33  {
34  switch (params.l_type)
35  {
36  case L_FIXED: return new PosteriorFixed(dim,params,eng);
37  case L_EMPIRICAL: return new EmpiricalBayes(dim,params,eng);
38  case L_DISCRETE: // TODO:return new
39  case L_MCMC: return new MCMCModel(dim,params,eng);
40  case L_ERROR:
41  default:
42  throw std::invalid_argument("Learning type not supported");
43  }
44  };
45 
46  PosteriorModel::PosteriorModel(size_t dim, Parameters parameters,
47  randEngine& eng):
48  mParameters(parameters), mDims(dim), mMean(dim, parameters)
49  {}
50 
52  { } // Default destructor
53 
54 
55  void PosteriorModel::setSamples(const matrixd &x, const vectord &y)
56  {
57  mData.setSamples(x,y);
58  mMean.setPoints(mData.mX); //Because it expects a vecOfvec instead of a matrixd
59  }
60 
61  void PosteriorModel::setSamples(const matrixd &x)
62  {
63  mData.setSamples(x);
64  mMean.setPoints(mData.mX); //Because it expects a vecOfvec instead of a matrixd
65  }
66 
67  void PosteriorModel::setSamples(const vectord &y)
68  {
69  mData.setSamples(y);
70  }
71 
72 
73  void PosteriorModel::setSample(const vectord &x, double y)
74  {
75  matrixd xx(1,x.size()); vectord yy(1);
76  row(xx,0) = x; yy(0) = y;
77  mData.setSamples(xx,yy);
78  mMean.setPoints(mData.mX); //Because it expects a vecOfvec instead of a matrixd
79  }
80 
81  void PosteriorModel::addSample(const vectord &x, double y)
82  { mData.addSample(x,y); mMean.addNewPoint(x); };
83 
84 
85 } //namespace bayesopt
86 
Posterior distribution on GPs based on MCMC over kernel parameters.
Namespace of the library interface.
Definition: using.dox:1
Parameters mParameters
Configuration parameters.
size_t mDims
Number of dimensions.
Posterior model based on fixed kernel parameters.
Abstract interface for posterior model/criteria.
Modules and helper macros for logging.
Dataset mData
Dataset (x-> inputs, y-> labels/output)
vecOfvec mX
Data inputs.
Definition: dataset.hpp:63
virtual ~PosteriorModel()
Default destructor.