You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/10/09 13:15:23 UTC

[commons-statistics] branch master updated (c3b0df4 -> 8aa67ea)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git.


    from c3b0df4  STATISTICS-25: Correct use of the RegularizedBeta for T dist
     new 94a76bf  Simplify computation of z by a multiplication by degrees of freedom
     new 8aa67ea  Use Locale.ROOT for String.format

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/statistics/distribution/DistributionException.java    | 2 +-
 .../org/apache/commons/statistics/distribution/TDistribution.java | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

[commons-statistics] 02/02: Use Locale.ROOT for String.format

Posted by ah...@apache.org.
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

commit 8aa67ea888fee8f713935a033ef61358017b4d12
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Oct 9 14:15:21 2021 +0100

    Use Locale.ROOT for String.format
    
    This makes number formatting language/country neutral.
---
 .../apache/commons/statistics/distribution/DistributionException.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/DistributionException.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/DistributionException.java
index 46a7e2f..cc477bd 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/DistributionException.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/DistributionException.java
@@ -53,6 +53,6 @@ class DistributionException extends IllegalArgumentException {
      * @param formatArguments Arguments for formatting the message.
      */
     DistributionException(String message, Object... formatArguments) {
-        super(String.format((Locale) null, message, formatArguments));
+        super(String.format(Locale.ROOT, message, formatArguments));
     }
 }

[commons-statistics] 01/02: Simplify computation of z by a multiplication by degrees of freedom

Posted by ah...@apache.org.
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

commit 94a76bfdb12f7a290e7137026603a310782e14dd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Oct 9 14:12:10 2021 +0100

    Simplify computation of z by a multiplication by degrees of freedom
---
 .../org/apache/commons/statistics/distribution/TDistribution.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
index 6f74322..fe68c0e 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
@@ -102,8 +102,10 @@ public class TDistribution extends AbstractContinuousDistribution {
         if (degreesOfFreedom > DOF_THRESHOLD_NORMAL) {
             return 0.5 * (1 + Erf.value(x * ONE_OVER_SQRT_TWO));
         }
-        final double x2overDf = x * x / degreesOfFreedom;
-        final double z = 1 / (1 + x2overDf);
+        final double x2 = x * x;
+        // z = 1 / (1 + x^2/df)
+        // Simplify by multiplication by df
+        final double z = degreesOfFreedom / (degreesOfFreedom + x2);
 
         // The RegularizedBeta has the complement:
         //   I(z, a, b) = 1 - I(1 - z, a, b)
@@ -111,7 +113,7 @@ public class TDistribution extends AbstractContinuousDistribution {
         // Detect this condition and directly use the complement.
         if (z > (dofOver2 + 1) / (2.5 + dofOver2)) {
             // zc = 1 - z; pc = 1 - p
-            final double zc = x2overDf / (1 + x2overDf);
+            final double zc = x2 / (degreesOfFreedom + x2);
             final double pc = RegularizedBeta.value(zc, 0.5, dofOver2);
 
             return x < 0 ?