From f08217505e37def3d29ab3c08bf45e22bb1db11f Mon Sep 17 00:00:00 2001 From: Quentin Grimonprez Date: Fri, 16 Oct 2020 11:37:36 +0200 Subject: [PATCH] set a minial epsilon proba values for probability of intervals for real model: Gaussian and Weibull #3 --- .../Simple/Gaussian/GaussianLikelihood.cpp | 17 +++++++++++++++-- .../Simple/Weibull/WeibullLikelihood.cpp | 13 +++++++++++-- MixtComp/src/lib/Various/Constants.cpp | 2 ++ MixtComp/src/lib/Various/Constants.h | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/MixtComp/src/lib/Mixture/Simple/Gaussian/GaussianLikelihood.cpp b/MixtComp/src/lib/Mixture/Simple/Gaussian/GaussianLikelihood.cpp index c44c6387f9..ccf3ce111c 100644 --- a/MixtComp/src/lib/Mixture/Simple/Gaussian/GaussianLikelihood.cpp +++ b/MixtComp/src/lib/Mixture/Simple/Gaussian/GaussianLikelihood.cpp @@ -71,7 +71,12 @@ Real GaussianLikelihood::lnObservedProbability(int i, int k) const { Real supCdf = normal_.cdf(supBound, mean, sd); - logProba = std::log(supCdf - infCdf); + + Real proba = supCdf - infCdf; + if(proba < epsilonProba) + proba = epsilonProba; + + logProba = std::log(proba); } break; @@ -80,6 +85,10 @@ Real GaussianLikelihood::lnObservedProbability(int i, int k) const { Real supCdf = normal_.cdf(supBound, mean, sd); + + if(supCdf < epsilonProba) + supCdf = epsilonProba; + logProba = std::log(supCdf); } break; @@ -89,7 +98,11 @@ Real GaussianLikelihood::lnObservedProbability(int i, int k) const { Real infCdf = normal_.cdf(infBound, mean, sd); - logProba = std::log(1. - infCdf); + Real proba = 1. - infCdf; + if(proba < epsilonProba) + proba = epsilonProba; + + logProba = std::log(proba); } break; diff --git a/MixtComp/src/lib/Mixture/Simple/Weibull/WeibullLikelihood.cpp b/MixtComp/src/lib/Mixture/Simple/Weibull/WeibullLikelihood.cpp index ccb45d7af7..e7bc7a3fa2 100644 --- a/MixtComp/src/lib/Mixture/Simple/Weibull/WeibullLikelihood.cpp +++ b/MixtComp/src/lib/Mixture/Simple/Weibull/WeibullLikelihood.cpp @@ -58,7 +58,11 @@ Real WeibullLikelihood::lnObservedProbability(Index i, Index k) const { case missingRUIntervals_: { Real infBound = augData_.misData_(i).second[0]; Real infCdf = weibull_.cdf(infBound, kParam, lambda); - logProba = std::log(1.0 - infCdf); + Real proba = 1. - infCdf; + if(proba < epsilonProba) + proba = epsilonProba; + + logProba = std::log(proba); } break; @@ -67,7 +71,12 @@ Real WeibullLikelihood::lnObservedProbability(Index i, Index k) const { Real supBound = augData_.misData_(i).second[1]; Real infCdf = weibull_.cdf(infBound, kParam, lambda); Real supCdf = weibull_.cdf(supBound, kParam, lambda); - logProba = std::log(supCdf - infCdf); + + Real proba = supCdf - infCdf; + if(proba < epsilonProba) + proba = epsilonProba; + + logProba = std::log(proba); } break; diff --git a/MixtComp/src/lib/Various/Constants.cpp b/MixtComp/src/lib/Various/Constants.cpp index a0eb0d3ab7..e2f73f1580 100644 --- a/MixtComp/src/lib/Various/Constants.cpp +++ b/MixtComp/src/lib/Various/Constants.cpp @@ -43,6 +43,8 @@ const Real epsilon = 1.e-8; const std::string epsilonStr = "1.e-8"; const Real logEpsilon = std::log(epsilon); +const Real epsilonProba = std::numeric_limits::epsilon(); + const int minModality = 1; const int minIndex = 1; const Real pi = boost::math::constants::pi(); diff --git a/MixtComp/src/lib/Various/Constants.h b/MixtComp/src/lib/Various/Constants.h index 57ec18934f..a39df3847d 100644 --- a/MixtComp/src/lib/Various/Constants.h +++ b/MixtComp/src/lib/Various/Constants.h @@ -40,6 +40,8 @@ extern const int nbSamplingAttempts; // number of sampling attempts, when not en extern const Real epsilon; // very small value of real to check for near zero values extern const std::string epsilonStr; // previous value, in scientific notation extern const Real logEpsilon; // log of very small value +extern const Real epsilonProba; // very small value of real to check for near zero values for probabilities + extern const int minModality; // minimal modality for categorical models (for example, 0-based or 1-based numbering) extern const int minIndex;