This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
The following commit(s) were added to refs/heads/master by this push:
new 716a4539 Implement the range probability(from, to) using a single sum
716a4539 is described below
commit 716a4539367956ac216dd459b0847d61a5c027ec
Author: Alex Herbert <[email protected]>
AuthorDate: Tue Sep 1 18:00:37 2026 +0100
Implement the range probability(from, to) using a single sum
---
.../statistics/distribution/ZipfDistribution.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git
a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ZipfDistribution.java
b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ZipfDistribution.java
index 315e76c8..713bba40 100644
---
a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ZipfDistribution.java
+++
b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ZipfDistribution.java
@@ -132,6 +132,29 @@ public final class ZipfDistribution extends
AbstractDiscreteDistribution {
return Math.pow(x, -exponent) / nthHarmonic;
}
+ /** {@inheritDoc} */
+ @Override
+ public double probability(int x0,
+ int x1) {
+ if (x0 > x1) {
+ throw new
DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH, x0, x1);
+ }
+ if (x0 == x1 || x1 < 1) {
+ // (x0, x1] does not overlap [1, n]
+ return 0;
+ }
+ // If the range is outside the bounds use the appropriate cumulative
probability
+ if (x0 < 1) {
+ return cumulativeProbability(x1);
+ }
+ if (x1 >= numberOfElements) {
+ return survivalProbability(x0);
+ }
+ // Here: 1 <= x0 < x1 < n:
+ // sum(pdf(x)) for x in (x0, x1]
+ return generalizedHarmonic(x0 + 1, x1, exponent) / nthHarmonic;
+ }
+
/** {@inheritDoc} */
@Override
public double logProbability(int x) {