BayesOpt
student_t_process_jef.cpp
1 /*
2 -----------------------------------------------------------------------------
3  Copyright (C) 2011 Ruben Martinez-Cantin <rmcantin@unizar.es>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Affero General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 -----------------------------------------------------------------------------
18 */
19 
20 #include "ublas_trace.hpp"
22 
23 namespace bayesopt
24 {
25 
26  namespace ublas = boost::numeric::ublas;
27 
28  StudentTProcessJeffreys::StudentTProcessJeffreys(size_t dim,
29  Parameters params,
30  const Dataset& data,
31  MeanModel& mean,
32  randEngine& eng):
33  HierarchicalGaussianProcess(dim, params, data, mean, eng)
34  {
35  d_ = new StudentTDistribution(eng);
36  } // Constructor
37 
38 
39 
40  StudentTProcessJeffreys::~StudentTProcessJeffreys()
41  {
42  delete d_;
43  } // Default destructor
44 
45 
46 
47 
49  {
50  /* In this case, they are equivalent */
51  return negativeTotalLogLikelihood();
52  }
53 
54 
56  StudentTProcessJeffreys::prediction(const vectord &query )
57  {
58  clock_t start = clock();
59  double kq = computeSelfCorrelation(query);
60  // vectord kn = computeCrossCorrelation(query);
61  mKernel.computeCrossCorrelation(mData.mX,query,mKn);
62  vectord phi = mMean.getFeatures(query);
63 
64  // vectord v(mKn);
65  inplace_solve(mL,mKn,ublas::lower_tag());
66 
67  vectord rho = phi - prod(mKn,mKF);
68 
69  // vectord rho(rq);
70  inplace_solve(mL2,rho,ublas::lower_tag());
71 
72  double yPred = inner_prod(phi,mWML) + inner_prod(mKn,mAlphaF);
73  double sPred = sqrt( mSigma * (kq - inner_prod(mKn,mKn)
74  + inner_prod(rho,rho)));
75 
76  d_->setMeanAndStd(yPred,sPred);
77  return d_;
78  }
79 
81  {
82  size_t n = mData.getNSamples();
83  size_t p = mMean.nFeatures();
84 
85  mKn.resize(n);
86 
87  mKF = trans(mMean.mFeatM);
88  inplace_solve(mL,mKF,ublas::lower_tag());
89 
90  matrixd FKF = prod(trans(mKF),mKF);
91  mL2 = FKF;
93 
94  vectord Ky(mData.mY);
95  inplace_solve(mL,Ky,ublas::lower_tag());
96 
97  mWML = prod(Ky,mKF);
98  utils::cholesky_solve(mL2,mWML,ublas::lower());
99 
100  mAlphaF = mData.mY - prod(mWML,mMean.mFeatM);
101  inplace_solve(mL,mAlphaF,ublas::lower_tag());
102  mSigma = inner_prod(mAlphaF,mAlphaF)/(n-p);
103 
104  d_->setDof(n-p);
105  }
106 
107 } //namespace bayesopt
Namespace of the library interface.
Definition: using.dox:1
Student T process with Jeffreys priors.
size_t cholesky_decompose(const MATRIX &A, TRIA &L)
decompose the symmetric positive definit matrix A into product L L^T.
ProbabilityDistribution * prediction(const vectord &query)
Function that returns the prediction of the GP for a query point in the hypercube [0...
void cholesky_solve(const TRIA &L, MATRIX &x, ublas::lower)
solve system L L^T x = b inplace
double negativeLogLikelihood()
Computes the negative log likelihood and its gradient of the data.
void precomputePrediction()
Precompute some values of the prediction that do not depends on the query.