You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/05/08 10:18:27 UTC
[1/2] commons-numbers git commit: NUMBERS-33: Removed "static"
keyword.
Repository: commons-numbers
Updated Branches:
refs/heads/task_NUMBERS-33__Gamma 871bb759c -> 14f6f851b
NUMBERS-33: Removed "static" keyword.
Thanks to Stian Soiland-Reyes.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/f2710635
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/f2710635
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/f2710635
Branch: refs/heads/task_NUMBERS-33__Gamma
Commit: f271063539ca219a94b37e60cdc0022ea65563e5
Parents: 871bb75
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Mon May 8 11:57:40 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Mon May 8 11:57:40 2017 +0200
----------------------------------------------------------------------
.../apache/commons/numbers/gamma/Digamma.java | 5 +--
.../apache/commons/numbers/gamma/Trigamma.java | 5 +--
.../commons/numbers/gamma/DigammaTest.java | 34 +++++++++++---------
.../commons/numbers/gamma/TrigammaTest.java | 10 +++---
4 files changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
index 8b096d5..ddcee55 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
@@ -36,9 +36,6 @@ public class Digamma {
/** Fraction. */
private static final double F_1_252 = 1d / 252;
- /** Class only contains a static method. */
- private Digamma() {}
-
/**
* Computes the digamma function.
*
@@ -56,7 +53,7 @@ public class Digamma {
* @param x Argument.
* @return digamma(x) to within \( 10^{-8} \) relative or absolute error whichever is larger.
*/
- public static double value(double x) {
+ public double value(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) {
return x;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
index 9e45601..8b1c277 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Trigamma.java
@@ -34,16 +34,13 @@ public class Trigamma {
/** Fraction. */
private static final double F_1_42 = 1d / 42;
- /** Class only contains a static method. */
- private Trigamma() {}
-
/**
* Computes the trigamma function.
*
* @param x Argument.
* @return trigamma(x) to within \( 10^{-8} \) relative or absolute error whichever is larger.
*/
- public static double value(double x) {
+ public double value(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) {
return x;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
index 17b459a..af31ab6 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/DigammaTest.java
@@ -23,21 +23,23 @@ import org.junit.Test;
* Tests for {@link Digamma}.
*/
public class DigammaTest {
+ private static final Digamma FUNCTION = new Digamma();
+
@Test
public void testDigammaLargeArgs() {
double eps = 1e-8;
- Assert.assertEquals(4.6001618527380874002, Digamma.value(100), eps);
- Assert.assertEquals(3.9019896734278921970, Digamma.value(50), eps);
- Assert.assertEquals(2.9705239922421490509, Digamma.value(20), eps);
- Assert.assertEquals(2.9958363947076465821, Digamma.value(20.5), eps);
- Assert.assertEquals(2.2622143570941481605, Digamma.value(10.1), eps);
- Assert.assertEquals(2.1168588189004379233, Digamma.value(8.8), eps);
- Assert.assertEquals(1.8727843350984671394, Digamma.value(7), eps);
- Assert.assertEquals(0.42278433509846713939, Digamma.value(2), eps);
- Assert.assertEquals(-100.56088545786867450, Digamma.value(0.01), eps);
- Assert.assertEquals(-4.0390398965921882955, Digamma.value(-0.8), eps);
- Assert.assertEquals(4.2003210041401844726, Digamma.value(-6.3), eps);
- Assert.assertEquals(-3.110625123035E-5, Digamma.value(1.4616), eps);
+ Assert.assertEquals(4.6001618527380874002, FUNCTION.value(100), eps);
+ Assert.assertEquals(3.9019896734278921970, FUNCTION.value(50), eps);
+ Assert.assertEquals(2.9705239922421490509, FUNCTION.value(20), eps);
+ Assert.assertEquals(2.9958363947076465821, FUNCTION.value(20.5), eps);
+ Assert.assertEquals(2.2622143570941481605, FUNCTION.value(10.1), eps);
+ Assert.assertEquals(2.1168588189004379233, FUNCTION.value(8.8), eps);
+ Assert.assertEquals(1.8727843350984671394, FUNCTION.value(7), eps);
+ Assert.assertEquals(0.42278433509846713939, FUNCTION.value(2), eps);
+ Assert.assertEquals(-100.56088545786867450, FUNCTION.value(0.01), eps);
+ Assert.assertEquals(-4.0390398965921882955, FUNCTION.value(-0.8), eps);
+ Assert.assertEquals(4.2003210041401844726, FUNCTION.value(-6.3), eps);
+ Assert.assertEquals(-3.110625123035E-5, FUNCTION.value(1.4616), eps);
}
@Test
@@ -51,15 +53,15 @@ public class DigammaTest {
-1e+17, -1e+18, -1e+19, -1e+20, -1e+21, -1e+22, -1e+23, -1e+24, -1e+25, -1e+26,
-1e+27, -1e+28, -1e+29, -1e+30};
for (double n = 1; n < 30; n++) {
- checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)], Digamma.value(Math.pow(10.0, -n)), 1e-8);
+ checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)], FUNCTION.value(Math.pow(10.0, -n)), 1e-8);
}
}
@Test
public void testDigammaNonRealArgs() {
- Assert.assertTrue(Double.isNaN(Digamma.value(Double.NaN)));
- Assert.assertTrue(Double.isInfinite(Digamma.value(Double.POSITIVE_INFINITY)));
- Assert.assertTrue(Double.isInfinite(Digamma.value(Double.NEGATIVE_INFINITY)));
+ Assert.assertTrue(Double.isNaN(FUNCTION.value(Double.NaN)));
+ Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.POSITIVE_INFINITY)));
+ Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.NEGATIVE_INFINITY)));
}
private void checkRelativeError(String msg,
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f2710635/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
index 50caf0b..a341498 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/TrigammaTest.java
@@ -23,6 +23,8 @@ import org.junit.Test;
* Tests for {@link Trigamma}.
*/
public class TrigammaTest {
+ private static final Trigamma FUNCTION = new Trigamma();
+
@Test
public void testTrigamma() {
double eps = 1e-8;
@@ -45,15 +47,15 @@ public class TrigammaTest {
100, 0.010050166663333571395
};
for (int i = data.length - 2; i >= 0; i -= 2) {
- Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], Trigamma.value(data[i]), eps);
+ Assert.assertEquals(String.format("trigamma %.0f", data[i]), data[i + 1], FUNCTION.value(data[i]), eps);
}
}
@Test
public void testTrigammaNonRealArgs() {
- Assert.assertTrue(Double.isNaN(Trigamma.value(Double.NaN)));
- Assert.assertTrue(Double.isInfinite(Trigamma.value(Double.POSITIVE_INFINITY)));
- Assert.assertTrue(Double.isInfinite(Trigamma.value(Double.NEGATIVE_INFINITY)));
+ Assert.assertTrue(Double.isNaN(FUNCTION.value(Double.NaN)));
+ Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.POSITIVE_INFINITY)));
+ Assert.assertTrue(Double.isInfinite(FUNCTION.value(Double.NEGATIVE_INFINITY)));
}
}
[2/2] commons-numbers git commit: NUMBERS-35: Typo (sign error).
Posted by er...@apache.org.
NUMBERS-35: Typo (sign error).
Unit tests are missing (see JIRA issue).
Thanks to Stian Soiland-Reyes for spotting that the code did not
agree with the referenced formula.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/14f6f851
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/14f6f851
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/14f6f851
Branch: refs/heads/task_NUMBERS-33__Gamma
Commit: 14f6f851b179249cb74b6dfa5b3c8d193e607186
Parents: f271063
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Mon May 8 12:15:07 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Mon May 8 12:15:07 2017 +0200
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/gamma/Digamma.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/14f6f851/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
index ddcee55..a10f1df 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Digamma.java
@@ -30,11 +30,11 @@ public class Digamma {
/** S limit. */
private static final double S_LIMIT = 1e-5;
/** Fraction. */
- private static final double F_1_12 = 1d / 12;
+ private static final double F_M1_12 = -1d / 12;
/** Fraction. */
private static final double F_1_120 = 1d / 120;
/** Fraction. */
- private static final double F_1_252 = 1d / 252;
+ private static final double F_M1_252 = -1d / 252;
/**
* Computes the digamma function.
@@ -80,7 +80,7 @@ public class Digamma {
// 1 1 1 1
// log(x) - --- - ------ + ------- - -------
// 2 x 12 x^2 120 x^4 252 x^6
- digamma += Math.log(x) - 0.5 / x - inv * (F_1_12 + inv * (F_1_120 - F_1_252 * inv));
+ digamma += Math.log(x) - 0.5 / x + inv * (F_M1_12 + inv * (F_1_120 + F_M1_252 * inv));
return digamma;
}