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>
58 const V & domainVector,
const V * domainDirection, V * gradVector,
59 M * hessianMatrix, V * hessianEffect)
const
61 return std::exp(this->lnValue(domainVector, domainDirection, gradVector,
62 hessianMatrix, hessianEffect));
65 template<
class V,
class M>
68 const V & domainVector,
const V * domainDirection, V * gradVector,
69 M * hessianMatrix, V * hessianEffect)
const
71 V modelOutput(this->m_observations, 0, 0);
72 V weightedMisfit(this->m_observations, 0, 0);
74 this->evaluateModel(domainVector, domainDirection, modelOutput, gradVector,
75 hessianMatrix, hessianEffect);
78 modelOutput -= this->m_observations;
81 this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
84 unsigned int numBlocks = this->m_covariance.numBlocks();
85 unsigned int offset = 0;
88 for (
unsigned int i = 0; i < this->m_covariance.numBlocks(); i++) {
91 unsigned int index = domainVector.sizeLocal() + (i - numBlocks);
92 double coefficient = domainVector[index];
95 unsigned int blockDim = this->m_covariance.getBlock(i).numRowsLocal();
96 for (
unsigned int j = 0; j < blockDim; j++) {
98 modelOutput[offset+j] /= coefficient;
104 modelOutput *= weightedMisfit;
106 double norm2_squared = modelOutput.sumOfComponents();
108 return -0.5 * norm2_squared;
virtual double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the scalar function.
A templated class for handling sets.
virtual ~GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients()
Destructor.
GaussianLikelihoodBlockDiagonalCovarianceRandomCoefficients(const char *prefix, const VectorSet< V, M > &domainSet, const V &observations, const GslBlockMatrix &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.
#define queso_error_msg(msg)
GslMatrix & getBlock(unsigned int i) const
Return block i in the block diagonal matrix.
Class for representing block matrices using GSL library.
unsigned int numRowsLocal() const
Returns the local row dimension of this matrix.
const GslBlockMatrix & m_covariance
Base class for canned Gaussian likelihoods.
A class representing a Gaussian likelihood with block-diagonal covariance matrix. ...
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.