queso-0.56.1
GaussianLikelihoodFullCovarianceRandomCoefficient.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/GslVector.h>
26 #include <queso/GslMatrix.h>
27 #include <queso/VectorSet.h>
28 #include <queso/VectorSpace.h>
29 #include <queso/GaussianLikelihoodFullCovarianceRandomCoefficient.h>
30 
31 namespace QUESO {
32 
33 template<class V, class M>
35  const char * prefix, const VectorSet<V, M> & domainSet,
36  const V & observations, const M & covariance)
37  : BaseGaussianLikelihood<V, M>(prefix, domainSet, observations),
38  m_covariance(covariance)
39 {
40  if (covariance.numRowsLocal() != observations.sizeLocal()) {
41  queso_error_msg("Covariance matrix not same size as observation vector");
42  }
43 }
44 
45 template<class V, class M>
47 {
48 }
49 
50 template<class V, class M>
51 double
53  const V & domainVector, const V * domainDirection, V * gradVector,
54  M * hessianMatrix, V * hessianEffect) const
55 {
56  return std::exp(this->lnValue(domainVector, domainDirection, gradVector,
57  hessianMatrix, hessianEffect));
58 }
59 
60 template<class V, class M>
61 double
63  const V & domainVector, const V * domainDirection, V * gradVector,
64  M * hessianMatrix, V * hessianEffect) const
65 {
66  V modelOutput(this->m_observations, 0, 0); // At least it's not a copy
67  V weightedMisfit(this->m_observations, 0, 0); // At least it's not a copy
68 
69  this->evaluateModel(domainVector, domainDirection, modelOutput, gradVector,
70  hessianMatrix, hessianEffect);
71 
72  // Compute misfit G(x) - y
73  modelOutput -= this->m_observations;
74 
75  // Solve \Sigma u = G(x) - y for u
76  this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
77 
78  // Compute (G(x) - y)^T \Sigma^{-1} (G(x) - y)
79  modelOutput *= weightedMisfit;
80 
81  // This is square of 2-norm
82  double norm2_squared = modelOutput.sumOfComponents();
83 
84  // Get the determinant of the covariance matrix |\Sigma|
85  double deter_cov = this->m_covariance.determinant();
86 
87  deter_cov = std::sqrt(deter_cov);
88 
89  // Set the right hyperparameter coefficient
90  // The last element of domainVector is the multiplicative coefficient of the
91  // covariance matrix
92  double cov_coeff = domainVector[domainVector.sizeLocal()-1];
93  cov_coeff = std::pow(std::sqrt(cov_coeff), this->m_observations.sizeLocal());
94 
95  return -0.5 * norm2_squared / cov_coeff - std::log(cov_coeff * deter_cov);
96 }
97 
98 } // End namespace QUESO
99 
A class that represents a Gaussian likelihood with full covariance and random coefficient.
GaussianLikelihoodFullCovarianceRandomCoefficient(const char *prefix, const VectorSet< V, M > &domainSet, const V &observations, const M &covariance)
Default constructor.
virtual double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the scalar function.
A templated class for handling sets.
Definition: VectorSet.h:52
#define queso_error_msg(msg)
Definition: asserts.h:47
virtual double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the scalar function.
Base class for canned Gaussian likelihoods.

Generated on Thu Dec 15 2016 13:23:11 for queso-0.56.1 by  doxygen 1.8.5