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 2020/05/27 00:10:30 UTC

[commons-math] branch master updated (52b374d -> 31be9f1)

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

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


    from 52b374d  Renormalise EOL
     new 9f17f6d  MATH-1534: Use value that probably conforms to the original intent.
     new de70e01  MATH-1534: Add unit test.
     new 31be9f1  Stricter tolerance (unit test).

The 3 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/math4/fitting/GaussianCurveFitter.java |  5 ++-
 .../math4/fitting/GaussianCurveFitterTest.java     | 39 +++++++++++++++++++---
 2 files changed, 36 insertions(+), 8 deletions(-)


[commons-math] 02/03: MATH-1534: Add unit test.

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit de70e0170e62ec19ab05458f32441036fd80dd00
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Wed May 27 02:03:31 2020 +0200

    MATH-1534: Add unit test.
---
 .../math4/fitting/GaussianCurveFitterTest.java     | 33 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java b/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
index 261bd30..dcd0a36 100644
--- a/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
+++ b/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
@@ -191,6 +191,17 @@ public class GaussianCurveFitterTest {
     }
 
     @Test
+    public void testDataset1LargeXShift() {
+        final GaussianCurveFitter fitter = GaussianCurveFitter.create();
+        final double xShift = 1e8;
+        final double[] parameters = fitter.fit(createDataset(DATASET1, xShift, 0).toList());
+
+        Assert.assertEquals(1, parameters[0] / 3496978.1837704973, 1e-2);
+        Assert.assertEquals(1, parameters[1] / (xShift + 4.054933085999146), 1e-6);
+        Assert.assertEquals(1, parameters[2] / 0.015039355620304326, 1e-2);
+    }
+
+    @Test
     public void testWithMaxIterations1() {
         final int maxIter = 20;
         final double[] init = { 3.5e6, 4.2, 0.1 };
@@ -385,13 +396,31 @@ public class GaussianCurveFitterTest {
      *        second dimension is an array of length two representing the point
      *        with the first value corresponding to X and the second value
      *        corresponding to Y.
+     * @param xShift Offset added to the abscissae.
+     * @param yShift Offset added to the ordinates.
      * @return the collection of observed points.
      */
-    private static WeightedObservedPoints createDataset(double[][] points) {
+    private static WeightedObservedPoints createDataset(double[][] points,
+                                                        double xShift,
+                                                        double yShift) {
         final WeightedObservedPoints obs = new WeightedObservedPoints();
         for (int i = 0; i < points.length; i++) {
-            obs.add(points[i][0], points[i][1]);
+            obs.add(points[i][0] + xShift, points[i][1] + yShift);
         }
         return obs;
     }
+
+    /**
+     * Adds the specified points to specified <code>GaussianCurveFitter</code>
+     * instance.
+     *
+     * @param points Data points where first dimension is a point index and
+     *        second dimension is an array of length two representing the point
+     *        with the first value corresponding to X and the second value
+     *        corresponding to Y.
+     * @return the collection of observed points.
+     */
+    private static WeightedObservedPoints createDataset(double[][] points) {
+        return createDataset(points, 0, 0);
+    }
 }


[commons-math] 01/03: MATH-1534: Use value that probably conforms to the original intent.

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 9f17f6de64d5f8376bb0eda601d8c2d730e70d5e
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Wed May 27 01:52:14 2020 +0200

    MATH-1534: Use value that probably conforms to the original intent.
    
    Thanks to Christoph Läubrich.
---
 .../java/org/apache/commons/math4/fitting/GaussianCurveFitter.java   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java b/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java
index 711fc1d..4af1200 100644
--- a/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java
+++ b/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java
@@ -294,11 +294,10 @@ public class GaussianCurveFitter extends AbstractCurveFitter {
         private double[] basicGuess(WeightedObservedPoint[] points) {
             final int maxYIdx = findMaxY(points);
             final double n = points[maxYIdx].getY();
-            final double m = points[maxYIdx].getX();
 
             double fwhmApprox;
             try {
-                final double halfY = n + ((m - n) / 2);
+                final double halfY = 0.5 * n;
                 final double fwhmX1 = interpolateXAtY(points, maxYIdx, -1, halfY);
                 final double fwhmX2 = interpolateXAtY(points, maxYIdx, 1, halfY);
                 fwhmApprox = fwhmX2 - fwhmX1;
@@ -308,7 +307,7 @@ public class GaussianCurveFitter extends AbstractCurveFitter {
             }
             final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2)));
 
-            return new double[] { n, m, s };
+            return new double[] { n, points[maxYIdx].getX(), s };
         }
 
         /**


[commons-math] 03/03: Stricter tolerance (unit test).

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 31be9f198c846ecd3b16965fa2f3318c9539551f
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Wed May 27 02:09:02 2020 +0200

    Stricter tolerance (unit test).
---
 .../org/apache/commons/math4/fitting/GaussianCurveFitterTest.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java b/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
index dcd0a36..0624f9a 100644
--- a/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
+++ b/src/test/java/org/apache/commons/math4/fitting/GaussianCurveFitterTest.java
@@ -185,9 +185,9 @@ public class GaussianCurveFitterTest {
         GaussianCurveFitter fitter = GaussianCurveFitter.create();
         double[] parameters = fitter.fit(createDataset(DATASET1).toList());
 
-        Assert.assertEquals(3496978.1837704973, parameters[0], 1e-4);
-        Assert.assertEquals(4.054933085999146, parameters[1], 1e-4);
-        Assert.assertEquals(0.015039355620304326, parameters[2], 1e-4);
+        Assert.assertEquals(3496978.1837704973, parameters[0], 1e-7);
+        Assert.assertEquals(4.054933085999146, parameters[1], 1e-16);
+        Assert.assertEquals(0.015039355620304326, parameters[2], 1e-15);
     }
 
     @Test