BayesOpt
gaussian_process_hierarchical.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 
24 #include "ublas_trace.hpp"
25 
26 namespace bayesopt
27 {
28  namespace ublas = boost::numeric::ublas;
29 
30  HierarchicalGaussianProcess::HierarchicalGaussianProcess(size_t dim,
31  Parameters params,
32  const Dataset& data,
33  MeanModel& mean,
34  randEngine& eng):
35  ConditionalBayesProcess(dim, params, data, mean, eng) {};
36 
38  {
39  /*This is the restricted version. For the unrestricted, make p=0
40  and remove the last term of loglik*/
41 
42  const matrixd K = computeCorrMatrix();
43  const size_t n = K.size1();
44  const size_t p = mMean.mFeatM.size1();
45  matrixd L(n,n);
47 
48  matrixd KF(ublas::trans(mMean.mFeatM));
49  inplace_solve(L,KF,ublas::lower_tag());
50 
51  matrixd FKF = prod(ublas::trans(KF),KF);
52  matrixd L2(p,p);
54 
55  vectord Ky(mData.mY);
56  inplace_solve(L,Ky,ublas::lower_tag());
57 
58  vectord wML = prod(Ky,KF);
59  utils::cholesky_solve(L2,wML,ublas::lower());
60 
61  vectord alpha = mData.mY - prod(wML,mMean.mFeatM);
62  inplace_solve(L,alpha,ublas::lower_tag());
63 
64  double loglik = .5*(n-p)*log(ublas::inner_prod(alpha,alpha))
65  + utils::log_trace(L) + utils::log_trace(L2);
66  return loglik;
67  }
68 }
69 
matrixd computeCorrMatrix()
Computes the Correlation (Kernel or Gram) matrix.
Hierarchical model for Gaussian process.
Namespace of the library interface.
Definition: using.dox:1
double negativeTotalLogLikelihood()
Computes the negative log likelihood of the data for all the parameters.
size_t cholesky_decompose(const MATRIX &A, TRIA &L)
decompose the symmetric positive definit matrix A into product L L^T.
void cholesky_solve(const TRIA &L, MATRIX &x, ublas::lower)
solve system L L^T x = b inplace
matrixd mFeatM
Value of the mean features at the input points.
vectord mY
Data values.
Definition: dataset.hpp:64