From 915b53ab9963f30926e70334a98cdff5d51fd674 Mon Sep 17 00:00:00 2001 From: Quentin Grimonprez Date: Fri, 16 Oct 2020 11:26:47 +0200 Subject: [PATCH] Manage the case when lambda = 0 for Poisson and there are some missing intervals --- .../lib/Mixture/Simple/Poisson/Poisson.cpp | 10 ------- .../Simple/Poisson/PoissonStatistic.cpp | 27 +++++++++++++------ RMixtCompIO/DESCRIPTION | 4 +-- RMixtCompIO/NEWS | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/MixtComp/src/lib/Mixture/Simple/Poisson/Poisson.cpp b/MixtComp/src/lib/Mixture/Simple/Poisson/Poisson.cpp index 85347f26fe..b558187d0e 100644 --- a/MixtComp/src/lib/Mixture/Simple/Poisson/Poisson.cpp +++ b/MixtComp/src/lib/Mixture/Simple/Poisson/Poisson.cpp @@ -64,16 +64,6 @@ std::string Poisson::mStep(const Vector>& classInd) { } param_(k) = sumClass / Real(classInd(k).size()); - - if (param_(k) < epsilon) { - warnLog += - "Poisson variables must have a minimum mean of " - + epsilonStr - + " in each class. It is not the case in class: " - + std::to_string(k) - + "." - + eol; - } } return warnLog; diff --git a/MixtComp/src/lib/Mixture/Simple/Poisson/PoissonStatistic.cpp b/MixtComp/src/lib/Mixture/Simple/Poisson/PoissonStatistic.cpp index 4b54c0b7d4..8dd5ac2112 100644 --- a/MixtComp/src/lib/Mixture/Simple/Poisson/PoissonStatistic.cpp +++ b/MixtComp/src/lib/Mixture/Simple/Poisson/PoissonStatistic.cpp @@ -53,9 +53,14 @@ Real PoissonStatistic::lpdf(int x, Real lambda) const { } Real PoissonStatistic::cdf(int x, Real lambda) const { - boost::math::poisson pois(lambda); - Real proba = boost::math::cdf(pois, x); - return proba; + if (0.0 < lambda) { + boost::math::poisson pois(lambda); + Real proba = boost::math::cdf(pois, x); + + return proba; + } else { + return 1.0; + } } @@ -103,11 +108,17 @@ int PoissonStatistic::quantile(Real lambda, Real p) const { * https://www.boost.org/doc/libs/1_69_0/libs/math/doc/html/math_toolkit/pol_tutorial/understand_dis_quant.html * */ - boost::math::poisson_distribution< - double, - boost::math::policies::policy > > pois(lambda); - int q = boost::math::quantile(pois, p); - return q; + if (0.0 < lambda) + { + boost::math::poisson_distribution< + double, + boost::math::policies::policy > > pois(lambda); + int q = boost::math::quantile(pois, p); + return q; + } else { + return 0.0; + } + } int PoissonStatistic::quantileIB(Real lambda, int infBound, Real p) const { diff --git a/RMixtCompIO/DESCRIPTION b/RMixtCompIO/DESCRIPTION index 4bd48e00b1..d8c6097a55 100644 --- a/RMixtCompIO/DESCRIPTION +++ b/RMixtCompIO/DESCRIPTION @@ -2,7 +2,7 @@ Package: RMixtCompIO Type: Package Title: Mixture Models with Heterogeneous and (Partially) Missing Data Version: 4.0.6 -Date: 2020-10-15 +Date: 2020-10-16 Authors@R: c(person("Vincent", "Kubicki", role = "aut"), person("Christophe", "Biernacki", role = "aut"), person("Quentin", "Grimonprez", role = c("aut", "cre"), email = "quentin.grimonprez@inria.fr"), @@ -22,5 +22,5 @@ BugReports: https://github.com/modal-inria/MixtComp/issues Imports: Rcpp, doParallel, foreach Suggests: Rmixmod, blockcluster, testthat, RInside, xml2 LinkingTo: Rcpp, RcppEigen, BH -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 Encoding: UTF-8 diff --git a/RMixtCompIO/NEWS b/RMixtCompIO/NEWS index ecc78a5e4f..41b757624b 100644 --- a/RMixtCompIO/NEWS +++ b/RMixtCompIO/NEWS @@ -2,7 +2,7 @@ v 4.0.6 - catch error "XXX object does not exit." - rename some C++ classes and files - remove useless files -- detect when the Poisson's parameter is estimated at 0 +- Manage the case when lambda = 0 for Poisson and there are some missing intervals v4.0.5 2020-06-15 - bug correction when z_class is in data but not in the model