queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
GaussianLikelihoodBlockDiagonalCovariance.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-2017 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 <cmath>
26 
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 #include <queso/VectorSet.h>
30 #include <queso/GaussianLikelihoodBlockDiagonalCovariance.h>
31 
32 namespace QUESO {
33 
34 template<class V, class M>
36  const char * prefix, const VectorSet<V, M> & domainSet,
37  const V & observations, const GslBlockMatrix & covariance)
38  : LikelihoodBase<V, M>(prefix, domainSet, observations),
39  m_covarianceCoefficients(covariance.numBlocks(), 1.0),
40  m_covariance(covariance)
41 {
42  unsigned int totalDim = 0;
43 
44  for (unsigned int i = 0; i < this->m_covariance.numBlocks(); i++) {
45  totalDim += this->m_covariance.getBlock(i).numRowsLocal();
46  }
47 
48  if (totalDim != observations.sizeLocal()) {
49  queso_error_msg("Covariance matrix not same dimension as observation vector");
50  }
51 }
52 
53 template<class V, class M>
55 {
56 }
57 
58 template<class V, class M>
59 double &
61  unsigned int i)
62 {
63  return this->m_covarianceCoefficients[i];
64 }
65 
66 template<class V, class M>
67 const double &
69  unsigned int i) const
70 {
71  return this->m_covarianceCoefficients[i];
72 }
73 
74 template<class V, class M>
75 double
77 {
78  V modelOutput(this->m_observations, 0, 0); // At least it's not a copy
79  V weightedMisfit(this->m_observations, 0, 0); // At least it's not a copy
80 
81  this->evaluateModel(domainVector, modelOutput);
82 
83  // Compute misfit G(x) - y
84  modelOutput -= this->m_observations;
85 
86  // Solve \Sigma u = G(x) - y for u
87  this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
88 
89  // Deal with the multiplicative coefficients for each of the blocks
90  unsigned int offset = 0;
91 
92  // For each block...
93  for (unsigned int i = 0; i < this->m_covariance.numBlocks(); i++) {
94  // ...divide the appropriate parts of the solution by the coefficient
95  unsigned int blockDim = this->m_covariance.getBlock(i).numRowsLocal();
96  for (unsigned int j = 0; j < blockDim; j++) {
97  // coefficient is a variance, so we divide by it
98  modelOutput[offset+j] /= this->m_covarianceCoefficients[i];
99  }
100  offset += blockDim;
101  }
102 
103  // Compute (G(x) - y)^T \Sigma^{-1} (G(x) - y)
104  modelOutput *= weightedMisfit;
105 
106  double norm2_squared = modelOutput.sumOfComponents(); // This is square of 2-norm
107 
108  return -0.5 * norm2_squared;
109 }
110 
111 } // End namespace QUESO
112 
double & blockCoefficient(unsigned int i)
Get (non-const) multiplicative coefficient for block i.
unsigned int numRowsLocal() const
Returns the local row dimension of this matrix.
Definition: GslMatrix.C:275
A templated class for handling sets.
Definition: VectorSet.h:52
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.
const double & getBlockCoefficient(unsigned int i) const
Get (const) multiplicative coefficient for block i.
Class for representing block matrices using GSL library.
GslMatrix & getBlock(unsigned int i) const
Return block i in the block diagonal matrix.
virtual double lnValue(const V &domainVector) const
Logarithm of the value of the scalar function.
GaussianLikelihoodBlockDiagonalCovariance(const char *prefix, const VectorSet< V, M > &domainSet, const V &observations, const GslBlockMatrix &covariance)
Default constructor.
A class representing a Gaussian likelihood with block-diagonal covariance matrix. ...
Base class for canned Gaussian likelihoods.

Generated on Tue Jun 5 2018 19:48:55 for queso-0.57.1 by  doxygen 1.8.5