25 #include <queso/GslVector.h>
26 #include <queso/GslMatrix.h>
27 #include <queso/VectorSet.h>
28 #include <queso/GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients.h>
32 template<
class V,
class M>
37 m_covariance(covariance)
39 unsigned int totalDim = 0;
45 if (totalDim != observations.sizeLocal()) {
46 queso_error_msg(
"Covariance matrix not same dimension as observation vector");
50 template<
class V,
class M>
55 template<
class V,
class M>
59 V modelOutput(this->m_observations, 0, 0);
60 V weightedMisfit(this->m_observations, 0, 0);
62 this->evaluateModel(domainVector, modelOutput);
65 modelOutput -= this->m_observations;
68 this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
71 unsigned int numBlocks = this->m_covariance.numBlocks();
72 unsigned int offset = 0;
75 double cov_norm_factor = 0.0;
76 for (
unsigned int i = 0; i < this->m_covariance.numBlocks(); i++) {
79 unsigned int index = domainVector.sizeLocal() + (i - numBlocks);
80 double coefficient = domainVector[index];
83 unsigned int blockDim = this->m_covariance.getBlock(i).numRowsLocal();
84 for (
unsigned int j = 0; j < blockDim; j++) {
86 modelOutput[offset+j] /= coefficient;
91 double cov_determinant = this->m_covariance.getBlock(i).determinant();
92 cov_determinant = std::sqrt(cov_determinant);
94 coefficient = std::sqrt(coefficient);
95 cov_norm_factor += std::log(std::pow(coefficient, blockDim) * cov_determinant);
101 modelOutput *= weightedMisfit;
103 double norm2_squared = modelOutput.sumOfComponents();
105 return -0.5 * norm2_squared - cov_norm_factor;
A class representing a Gaussian likelihood with block-diagonal covariance matrix. ...
unsigned int numRowsLocal() const
Returns the local row dimension of this matrix.
A templated class for handling sets.
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.
Class for representing block matrices using GSL library.
GslMatrix & getBlock(unsigned int i) const
Return block i in the block diagonal matrix.
const GslBlockMatrix & m_covariance
virtual double lnValue(const V &domainVector) const
Logarithm of the value of the scalar function.
virtual ~GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients()
Destructor.
Base class for canned Gaussian likelihoods.
GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients(const char *prefix, const VectorSet< V, M > &domainSet, const V &observations, const GslBlockMatrix &covariance)
Default constructor.