From 1e88125ef4214ca8b349e431d054ea01da4ef83b Mon Sep 17 00:00:00 2001 From: regislebrun Date: Wed, 18 Dec 2024 19:34:26 +0100 Subject: [PATCH] Improved NormalCopula Now the entropy is computed more efficiently --- lib/src/Uncertainty/Distribution/Normal.cxx | 4 ++++ lib/src/Uncertainty/Distribution/NormalCopula.cxx | 7 ++++++- lib/src/Uncertainty/Distribution/openturns/Normal.hxx | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/src/Uncertainty/Distribution/Normal.cxx b/lib/src/Uncertainty/Distribution/Normal.cxx index 7064457394c..a667bf46f09 100644 --- a/lib/src/Uncertainty/Distribution/Normal.cxx +++ b/lib/src/Uncertainty/Distribution/Normal.cxx @@ -414,6 +414,10 @@ Scalar Normal::computeComplementaryCDF(const Point & point) const /* Compute the entropy of the distribution */ Scalar Normal::computeEntropy() const { + // The entropy is equal to (see https://statproofbook.github.io/P/mvn-dent): + // (dim/2)*(log(2pi))+(1/2)*log(det(Sigma))+(1/2)*dim + // We reuse the normalization factors to avoid the recomputation of + // the most costly parts: // EllipticalDistribution::normalizationFactor_ == 1/sqrt(det(Sigma)) // logNormalizationFactor_ == log(1/sqrt(2*Pi)^dim) return 0.5 * getDimension() - std::log(EllipticalDistribution::normalizationFactor_) - logNormalizationFactor_; diff --git a/lib/src/Uncertainty/Distribution/NormalCopula.cxx b/lib/src/Uncertainty/Distribution/NormalCopula.cxx index b4016679cb8..f2c0a20846b 100644 --- a/lib/src/Uncertainty/Distribution/NormalCopula.cxx +++ b/lib/src/Uncertainty/Distribution/NormalCopula.cxx @@ -363,7 +363,12 @@ CorrelationMatrix NormalCopula::getKendallTau() const /* Compute the entropy of the distribution */ Scalar NormalCopula::computeEntropy() const { - return normal_.computeEntropy() - getDimension() * (SpecFunc::LOGSQRT2PI + 0.5); + // The entroy of the normal copula is the entropy of + // the associated standard normal distribution minus + // dim times the entropy of a standard univariate normal + // distribution, thus it is equal to (1/2)*log(| + //return normal_.computeEntropy() - getDimension() * (SpecFunc::LOGSQRT2PI + 0.5); + return -std::log(normal_.EllipticalDistribution::normalizationFactor_); } /* Get the Shape matrix of the copula */ diff --git a/lib/src/Uncertainty/Distribution/openturns/Normal.hxx b/lib/src/Uncertainty/Distribution/openturns/Normal.hxx index aa6713b87e0..715e3c4ef18 100644 --- a/lib/src/Uncertainty/Distribution/openturns/Normal.hxx +++ b/lib/src/Uncertainty/Distribution/openturns/Normal.hxx @@ -36,6 +36,10 @@ class OT_API Normal { CLASSNAME + + /** The NormalCopula class is closely related with the Normal class */ + friend class NormalCopula; + public: /** Default constructor */