27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 #include <queso/VectorSet.h>
30 #include <queso/GaussianLikelihoodFullCovariance.h>
34 template<
class V,
class M>
37 const V & observations,
const M & covariance,
double covarianceCoefficient)
39 m_covarianceCoefficient(covarianceCoefficient),
40 m_covariance(covariance)
42 if (covariance.numRowsLocal() != observations.sizeLocal()) {
43 queso_error_msg(
"Covariance matrix not same size as observation vector");
47 template<
class V,
class M>
52 template<
class V,
class M>
55 const V * domainDirection, V * gradVector, M * hessianMatrix,
56 V * hessianEffect)
const
58 return std::exp(this->lnValue(domainVector, domainDirection, gradVector,
59 hessianMatrix, hessianEffect));
62 template<
class V,
class M>
65 const V * domainDirection, V * gradVector, M * hessianMatrix,
66 V * hessianEffect)
const
68 V modelOutput(this->m_observations, 0, 0);
69 V weightedMisfit(this->m_observations, 0, 0);
71 this->evaluateModel(domainVector, domainDirection, modelOutput, gradVector,
72 hessianMatrix, hessianEffect);
75 modelOutput -= this->m_observations;
78 this->m_covariance.invertMultiply(modelOutput, weightedMisfit);
81 modelOutput *= weightedMisfit;
84 double norm2_squared = modelOutput.sumOfComponents();
86 return -0.5 * norm2_squared / (this->m_covarianceCoefficient);
A templated class for handling sets.
#define queso_error_msg(msg)
GaussianLikelihoodFullCovariance(const char *prefix, const VectorSet< V, M > &domainSet, const V &observations, const M &covariance, double covarianceCoefficient=1.0)
Default constructor.
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.
A class that represents a Gaussian likelihood with full covariance.
virtual double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the scalar function.
virtual ~GaussianLikelihoodFullCovariance()
Destructor.