27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 #include <queso/VectorSet.h>
30 #include <queso/GaussianLikelihoodBlockDiagonalCovariance.h>
34 template<
class V,
class M>
39 m_covarianceCoefficients(covariance.numBlocks(), 1.0),
40 m_covariance(covariance)
42 unsigned int totalDim = 0;
48 if (totalDim != observations.sizeLocal()) {
49 queso_error_msg(
"Covariance matrix not same dimension as observation vector");
53 template<
class V,
class M>
58 template<
class V,
class M>
63 return this->m_covarianceCoefficients[i];
66 template<
class V,
class M>
71 return this->m_covarianceCoefficients[i];
74 template<
class V,
class M>
78 V modelOutput(this->m_observations, 0, 0);
79 V weightedMisfit(this->m_observations, 0, 0);
81 this->evaluateModel(domainVector, modelOutput);
84 modelOutput -= this->m_observations;
87 this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
90 unsigned int offset = 0;
93 for (
unsigned int i = 0; i < this->m_covariance.numBlocks(); i++) {
95 unsigned int blockDim = this->m_covariance.getBlock(i).numRowsLocal();
96 for (
unsigned int j = 0; j < blockDim; j++) {
98 modelOutput[offset+j] /= this->m_covarianceCoefficients[i];
104 modelOutput *= weightedMisfit;
106 double norm2_squared = modelOutput.sumOfComponents();
108 return -0.5 * norm2_squared;
virtual ~GaussianLikelihoodBlockDiagonalCovariance()
Destructor.
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.
A templated class for handling sets.
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.
const GslBlockMatrix & m_covariance
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.