Skip to content

Commit

Permalink
Renamed NegativeBinomial in favor of Polya. Fixes openturns#2708
Browse files Browse the repository at this point in the history
  • Loading branch information
regislebrun committed Jul 29, 2024
1 parent 7ef3bea commit f9aa494
Show file tree
Hide file tree
Showing 32 changed files with 205 additions and 183 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Removed deprecated OptimizationResult.getEvaluationNumber
* Deprecated BayesDistribution in favor of JointByConditioningDistribution
* Deprecated ConditionalDistribution in favor of DeconditionedDistribution
* Deprecated NegativeBinomial in favor of Polya

=== Documentation ===
* Copy button for code blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#include "openturns/MeixnerFactory.hxx"
#include "openturns/PersistentObjectFactory.hxx"
#include "openturns/NegativeBinomial.hxx"
#include "openturns/Polya.hxx"
#include "openturns/Exception.hxx"

BEGIN_NAMESPACE_OPENTURNS
Expand All @@ -35,18 +35,18 @@ static const Factory<MeixnerFactory> Factory_MeixnerFactory;

/* Default constructor, associated with the default Negative Binomial distribution of parameter 1, 1/2. */
MeixnerFactory::MeixnerFactory()
: OrthogonalUniVariatePolynomialFactory(NegativeBinomial()),
: OrthogonalUniVariatePolynomialFactory(Polya()),
r_(1.0),
p_(0.5)
{
initializeCache();
}


/* Parameter constructor: lambda is the order of the generalized Meixner polynomial, associated with the NegativeBinomial(r, p) distribution */
/* Parameter constructor: lambda is the order of the generalized Meixner polynomial, associated with the Polya(r, p) distribution */
MeixnerFactory::MeixnerFactory(const Scalar r,
const Scalar p)
: OrthogonalUniVariatePolynomialFactory( NegativeBinomial(r, p) ),
: OrthogonalUniVariatePolynomialFactory( Polya(r, p) ),
r_(r),
p_(p)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void StandardDistributionPolynomialFactory::checkSpecificFamily()
hasSpecificFamily_ = true;
return;
}
if (measureType == "NegativeBinomial")
if (measureType == "Polya")
{
specificFamily_ = MeixnerFactory(parameter[0], parameter[1]);
LOGDEBUG(OSS() << "measureType=" << measureType << ", specificFamily=" << specificFamily_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public:
/** Default constructor, associated with the default Negative Binomial distribution of parameter 1, 1/2. */
MeixnerFactory();

/** Parameter constructor: lambda is the order of the generalized Meixner polynomial, associated with the NegativeBinomial(r, p) distribution */
/** Parameter constructor: lambda is the order of the generalized Meixner polynomial, associated with the Polya(r, p) distribution */
MeixnerFactory(const Scalar r,
const Scalar p);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/Uncertainty/Distribution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ot_add_source_file (MixedHistogramUserDefined.cxx)
ot_add_source_file (Mixture.cxx)
ot_add_source_file (Multinomial.cxx)
ot_add_source_file (MultinomialFactory.cxx)
ot_add_source_file (NegativeBinomial.cxx)
ot_add_source_file (Polya.cxx)
ot_add_source_file (NegativeBinomialFactory.cxx)
ot_add_source_file (NonCentralChiSquare.cxx)
ot_add_source_file (NonCentralStudent.cxx)
Expand Down Expand Up @@ -293,7 +293,7 @@ ot_install_header_file (MixedHistogramUserDefined.hxx)
ot_install_header_file (Mixture.hxx)
ot_install_header_file (MultinomialFactory.hxx)
ot_install_header_file (Multinomial.hxx)
ot_install_header_file (NegativeBinomial.hxx)
ot_install_header_file (Polya.hxx)
ot_install_header_file (NegativeBinomialFactory.hxx)
ot_install_header_file (NonCentralChiSquare.hxx)
ot_install_header_file (NonCentralStudent.hxx)
Expand Down
24 changes: 12 additions & 12 deletions lib/src/Uncertainty/Distribution/NegativeBinomialFactory.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- C++ -*-
/**
* @brief Factory for NegativeBinomial distribution
* @brief Factory for Polya distribution
*
* Copyright 2005-2024 Airbus-EDF-IMACS-ONERA-Phimeca
*
Expand Down Expand Up @@ -91,21 +91,21 @@ Distribution NegativeBinomialFactory::build() const
return buildAsNegativeBinomial().clone();
}

NegativeBinomial NegativeBinomialFactory::buildAsNegativeBinomial(const Sample & sample) const
Polya NegativeBinomialFactory::buildAsNegativeBinomial(const Sample & sample) const
{
const UnsignedInteger size = sample.getSize();
if (size < 2) throw InvalidArgumentException(HERE) << "Error: cannot build a NegativeBinomial distribution from a sample of size < 2";
if (sample.getDimension() != 1) throw InvalidArgumentException(HERE) << "Error: can build a NegativeBinomial distribution only from a sample of dimension 1, here dimension=" << sample.getDimension();
if (size < 2) throw InvalidArgumentException(HERE) << "Error: cannot build a Polya distribution from a sample of size < 2";
if (sample.getDimension() != 1) throw InvalidArgumentException(HERE) << "Error: can build a Polya distribution only from a sample of dimension 1, here dimension=" << sample.getDimension();
Scalar mean = 0.0;
Scalar var = 0.0;
const Scalar supportEpsilon = ResourceMap::GetAsScalar("DiscreteDistribution-SupportEpsilon");
for (UnsignedInteger i = 0; i < size; ++i)
{
const Scalar x = sample(i, 0);
if (!SpecFunc::IsNormal(x)) throw InvalidArgumentException(HERE) << "Error: cannot build a NegativeBinomial distribution if data contains NaN or Inf";
if (!SpecFunc::IsNormal(x)) throw InvalidArgumentException(HERE) << "Error: cannot build a Polya distribution if data contains NaN or Inf";
const int iX(static_cast<int>(round(x)));
// The sample must be made of nonnegative integral values
if (std::abs(x - iX) > supportEpsilon || (iX < 0)) throw InvalidArgumentException(HERE) << "Error: can build a NegativeBinomial distribution only from a sample made of nonnegative integers, here x=" << x;
if (std::abs(x - iX) > supportEpsilon || (iX < 0)) throw InvalidArgumentException(HERE) << "Error: can build a Polya distribution only from a sample made of nonnegative integers, here x=" << x;
var = i * var / (i + 1.0) + (1.0 - 1.0 / (i + 1.0)) * (mean - x) * (mean - x) / (i + 1.0);
mean = (x + i * mean) / (i + 1.0);
}
Expand Down Expand Up @@ -139,28 +139,28 @@ NegativeBinomial NegativeBinomialFactory::buildAsNegativeBinomial(const Sample &
const Scalar r = solver.solve(f, 0.0, a, b, fA, fB);
// Corresponding p estimate
const Scalar p = 1.0 / (r / mean + 1.0);
NegativeBinomial result(r, p);
Polya result(r, p);
result.setDescription(sample.getDescription());
return result;
}

NegativeBinomial NegativeBinomialFactory::buildAsNegativeBinomial(const Point & parameters) const
Polya NegativeBinomialFactory::buildAsNegativeBinomial(const Point & parameters) const
{
try
{
NegativeBinomial distribution;
Polya distribution;
distribution.setParameter(parameters);
return distribution;
}
catch (const InvalidArgumentException &)
{
throw InvalidArgumentException(HERE) << "Error: cannot build a NegativeBinomial distribution from the given parameters";
throw InvalidArgumentException(HERE) << "Error: cannot build a Polya distribution from the given parameters";
}
}

NegativeBinomial NegativeBinomialFactory::buildAsNegativeBinomial() const
Polya NegativeBinomialFactory::buildAsNegativeBinomial() const
{
return NegativeBinomial();
return Polya();
}

END_NAMESPACE_OPENTURNS
Loading

0 comments on commit f9aa494

Please sign in to comment.