mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/probability] Change geometric distribution definition
THe distribution now represents the number of trials neded before a
success, so is defined for k in {1, 2, 3, ...}
This commit is contained in:
@@ -15,8 +15,7 @@ float GeometricDistribution::xMax() const {
|
||||
}
|
||||
|
||||
float GeometricDistribution::yMax() const {
|
||||
int maxAbscissa = 0;
|
||||
float result = evaluateAtAbscissa(maxAbscissa);
|
||||
float result = evaluateAtAbscissa(1.0); // Tha probability is max for x == 1
|
||||
return result * (1.0f + k_displayTopMarginRatio);
|
||||
}
|
||||
|
||||
@@ -29,16 +28,18 @@ bool GeometricDistribution::authorizedValueAtIndex(float x, int index) const {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T GeometricDistribution::templatedApproximateAtAbscissa(T x) const {
|
||||
if (x < 0) {
|
||||
T GeometricDistribution::templatedApproximateAtAbscissa(T k) const {
|
||||
constexpr T castedOne = static_cast<T>(1.0);
|
||||
if (k < castedOne) {
|
||||
return static_cast<T>(0.0);
|
||||
}
|
||||
T p = static_cast<T>(m_parameter1);
|
||||
if (p == static_cast<T>(1.0)) {
|
||||
return static_cast<T>(x == 0 ? 1.0 : 0.0);
|
||||
if (p == castedOne) {
|
||||
return k == castedOne ? castedOne : static_cast<T>(0.0);
|
||||
}
|
||||
T lResult = x * std::log(static_cast<T>(1.0) - p);
|
||||
return p*std::exp(lResult);
|
||||
// The result is p * (1-p)^{k-1}
|
||||
T lResult = (k - castedOne) * std::log(castedOne - p);
|
||||
return p * std::exp(lResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ namespace Probability {
|
||||
|
||||
/* We chose the definition:
|
||||
* 0 < p <= 1 for success probability
|
||||
* k failures where k ∈ {0, 1, 2, ... }
|
||||
* The distribution follows the probability distribution of the number of failures before
|
||||
* the first success. */
|
||||
* k number of trials needed to get one success, where k ∈ {1, 2, 3, ...}. */
|
||||
|
||||
class GeometricDistribution final : public OneParameterDistribution {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user