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/04/05 12:16:25 UTC
[commons-math] branch master updated (8be7fa4 -> 00f4de0)
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 8be7fa4 Merge branch 'MATH-1524__ChenTao'
new e80f7cc Unused "import" statements.
new 13a084b MATH-1529: Modified Akima interpolator.
new 00f4de0 Track changes.
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:
src/changes/changes.xml | 3 ++
.../BaseAbstractUnivariateIntegrator.java | 8 ++---
.../IterativeLegendreGaussIntegrator.java | 13 ++++----
.../interpolation/AkimaSplineInterpolator.java | 38 ++++++++++++++++++++--
.../solvers/BaseAbstractUnivariateSolver.java | 25 +++++++-------
.../commons/math4/util/IterationManager.java | 14 ++++----
.../interpolation/AkimaSplineInterpolatorTest.java | 35 ++++++++++++++++++++
7 files changed, 102 insertions(+), 34 deletions(-)
[commons-math] 02/03: MATH-1529: Modified Akima interpolator.
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 13a084b3d9cda815f6b5b4d5044851b1227f4e90
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri Apr 3 22:11:13 2020 +0200
MATH-1529: Modified Akima interpolator.
---
.../interpolation/AkimaSplineInterpolator.java | 38 ++++++++++++++++++++--
.../interpolation/AkimaSplineInterpolatorTest.java | 35 ++++++++++++++++++++
2 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolator.java
index 089a7ac..0ab0b13 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolator.java
@@ -36,7 +36,13 @@ import org.apache.commons.numbers.core.Precision;
* <p>
* This implementation is based on the Akima implementation in the CubicSpline
* class in the Math.NET Numerics library. The method referenced is
- * CubicSpline.InterpolateAkimaSorted
+ * "CubicSpline.InterpolateAkimaSorted".
+ * </p>
+ * <p>
+ * When the {@link #AkimaSplineInterpolator(boolean) argument to the constructor}
+ * is {@code true}, the weights are modified in order to
+ * <a href="https://nl.mathworks.com/help/matlab/ref/makima.html">smooth out
+ * spurious oscillations</a>.
* </p>
* <p>
* The {@link #interpolate(double[], double[]) interpolate} method returns a
@@ -49,6 +55,24 @@ public class AkimaSplineInterpolator
implements UnivariateInterpolator {
/** The minimum number of points that are needed to compute the function. */
private static final int MINIMUM_NUMBER_POINTS = 5;
+ /** Whether to use the "modified Akima" interpolation. */
+ private final boolean useModified;
+
+ /**
+ * Uses the original Akima algorithm.
+ */
+ public AkimaSplineInterpolator() {
+ this(false);
+ }
+
+ /**
+ * @param useModified Whether to use the
+ * <a href="https://nl.mathworks.com/help/matlab/ref/makima.html">modified Akima</a>
+ * interpolation.
+ */
+ public AkimaSplineInterpolator(boolean useModified) {
+ this.useModified = useModified;
+ }
/**
* Computes an interpolating function for the data set.
@@ -95,8 +119,16 @@ public class AkimaSplineInterpolator
differences[i] = (yvals[i + 1] - yvals[i]) / (xvals[i + 1] - xvals[i]);
}
- for (int i = 1; i < weights.length; i++) {
- weights[i] = FastMath.abs(differences[i] - differences[i - 1]);
+ if (useModified) {
+ for (int i = 1; i < weights.length; i++) {
+ final double a = differences[i];
+ final double b = differences[i - 1];
+ weights[i] = FastMath.abs(a - b) + 0.5 * FastMath.abs(a + b);
+ }
+ } else {
+ for (int i = 1; i < weights.length; i++) {
+ weights[i] = FastMath.abs(differences[i] - differences[i - 1]);
+ }
}
// Prepare Hermite interpolation scheme.
diff --git a/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java b/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
index d559c4e..28a6e30 100644
--- a/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/interpolation/AkimaSplineInterpolatorTest.java
@@ -187,6 +187,41 @@ public class AkimaSplineInterpolatorTest
maxTolerance );
}
+ @Test
+ public void testOriginalVsModified() {
+ final UnivariateFunction f = new UnivariateFunction() {
+ @Override
+ public double value(double x) {
+ return x < -1 ? -1 :
+ x < 1 ? x : 1;
+ }
+ };
+
+ final double[] xS = new double[] {-1, 0, 1, 2, 3 };
+ final double[] yS = new double[xS.length];
+
+ for (int i = 0; i < xS.length; i++) {
+ yS[i] = f.value(xS[i]);
+ }
+
+ final UnivariateFunction iOriginal = new AkimaSplineInterpolator(false).interpolate(xS, yS);
+ final UnivariateFunction iModified = new AkimaSplineInterpolator(true).interpolate(xS, yS);
+
+ final int n = 100;
+ final double delta = 1d / n;
+ for (int i = 1; i < n - 1; i++) {
+ final double x = 2 - i * delta;
+
+ final double value = f.value(x);
+ final double diffOriginal = Math.abs(iOriginal.value(x) - value);
+ final double diffModified = Math.abs(iModified.value(x) - value);
+
+ // In interval (1, 2), the modified algorithm eliminates interpolation artefacts.
+ Assert.assertTrue(diffOriginal > 0);
+ Assert.assertEquals(0d, diffModified, 0d);
+ }
+ }
+
private void testInterpolation( double minimumX, double maximumX, int numberOfElements, int numberOfSamples,
UnivariateFunction f, double tolerance, double maxTolerance )
{
[commons-math] 01/03: Unused "import" statements.
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 e80f7cc29316d7ad749542392f8e32e1f2b31775
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Sat Apr 4 00:19:29 2020 +0200
Unused "import" statements.
---
.../BaseAbstractUnivariateIntegrator.java | 8 +++----
.../IterativeLegendreGaussIntegrator.java | 13 ++++++-----
.../solvers/BaseAbstractUnivariateSolver.java | 25 +++++++++++-----------
.../commons/math4/util/IterationManager.java | 14 ++++++------
4 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
index 1f89468..fadb1d0 100644
--- a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
@@ -18,10 +18,8 @@ package org.apache.commons.math4.analysis.integration;
import org.apache.commons.math4.analysis.UnivariateFunction;
import org.apache.commons.math4.analysis.solvers.UnivariateSolverUtils;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.math4.exception.TooManyEvaluationsException;
import org.apache.commons.math4.util.IntegerSequence;
@@ -227,8 +225,10 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
* @param f the integrand function
* @param lower the min bound for the interval
* @param upper the upper bound for the interval
- * @throws NullArgumentException if {@code f} is {@code null}.
- * @throws MathIllegalArgumentException if {@code min >= max}.
+ * @throws org.apache.commons.math4.exception.NullArgumentException
+ * if {@code f} is {@code null}.
+ * @throws org.apache.commons.math4.exception.MathIllegalArgumentException
+ * if {@code min >= max}.
*/
protected void setup(final int maxEval,
final UnivariateFunction f,
diff --git a/src/main/java/org/apache/commons/math4/analysis/integration/IterativeLegendreGaussIntegrator.java b/src/main/java/org/apache/commons/math4/analysis/integration/IterativeLegendreGaussIntegrator.java
index 310b290..332fc3e 100644
--- a/src/main/java/org/apache/commons/math4/analysis/integration/IterativeLegendreGaussIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/integration/IterativeLegendreGaussIntegrator.java
@@ -19,10 +19,7 @@ package org.apache.commons.math4.analysis.integration;
import org.apache.commons.math4.analysis.UnivariateFunction;
import org.apache.commons.math4.analysis.integration.gauss.GaussIntegrator;
import org.apache.commons.math4.analysis.integration.gauss.GaussIntegratorFactory;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.math4.exception.TooManyEvaluationsException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.util.FastMath;
@@ -62,8 +59,9 @@ public class IterativeLegendreGaussIntegrator
* @param maximalIterationCount Maximum number of iterations.
* @throws NotStrictlyPositiveException if minimal number of iterations
* or number of points are not strictly positive.
- * @throws NumberIsTooSmallException if maximal number of iterations
- * is smaller than or equal to the minimal number of iterations.
+ * @throws org.apache.commons.math4.exception.NumberIsTooSmallException
+ * if the maximal number of iterations is smaller than or equal to the
+ * minimal number of iterations.
*/
public IterativeLegendreGaussIntegrator(final int n,
final double relativeAccuracy,
@@ -100,8 +98,9 @@ public class IterativeLegendreGaussIntegrator
* @param maximalIterationCount Maximum number of iterations.
* @throws NotStrictlyPositiveException if minimal number of iterations
* is not strictly positive.
- * @throws NumberIsTooSmallException if maximal number of iterations
- * is smaller than or equal to the minimal number of iterations.
+ * @throws org.apache.commons.math4.exception.NumberIsTooSmallException
+ * if the maximal number of iterations is smaller than or equal to the
+ * minimal number of iterations.
* @throws NotStrictlyPositiveException if {@code n < 1}.
*/
public IterativeLegendreGaussIntegrator(final int n,
diff --git a/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java b/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
index 650a382..c08811e 100644
--- a/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
+++ b/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
@@ -19,9 +19,6 @@ package org.apache.commons.math4.analysis.solvers;
import org.apache.commons.math4.analysis.UnivariateFunction;
import org.apache.commons.math4.exception.MaxCountExceededException;
-import org.apache.commons.math4.exception.NoBracketingException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.TooManyEvaluationsException;
import org.apache.commons.math4.util.IntegerSequence;
import org.apache.commons.math4.util.MathUtils;
@@ -173,7 +170,8 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
* @param max Upper bound for the interval.
* @param startValue Start value to use.
* @param maxEval Maximum number of evaluations.
- * @exception NullArgumentException if f is null
+ * @throws org.apache.commons.math4.exception.NullArgumentException
+ * if {@code f} is {@code null}.
*/
protected void setup(int maxEval,
FUNC f,
@@ -220,8 +218,9 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
* @return the root.
* @throws TooManyEvaluationsException if the maximal number of evaluations
* is exceeded.
- * @throws NoBracketingException if the initial search interval does not bracket
- * a root and the solver requires it.
+ * @throws org.apache.commons.math4.exception.NoBracketingException
+ * if the initial search interval does not bracket a root and the
+ * solver requires it.
*/
protected abstract double doSolve();
@@ -257,7 +256,8 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
*
* @param lower Lower endpoint.
* @param upper Upper endpoint.
- * @throws NumberIsTooLargeException if {@code lower >= upper}.
+ * @throws org.apache.commons.math4.exception.NumberIsTooLargeException
+ * if {@code lower >= upper}.
*/
protected void verifyInterval(final double lower,
final double upper) {
@@ -270,8 +270,8 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
* @param lower Lower endpoint.
* @param initial Initial value.
* @param upper Upper endpoint.
- * @throws NumberIsTooLargeException if {@code lower >= initial} or
- * {@code initial >= upper}.
+ * @throws org.apache.commons.math4.exception.NumberIsTooLargeException
+ * if {@code lower >= initial} or {@code initial >= upper}.
*/
protected void verifySequence(final double lower,
final double initial,
@@ -285,9 +285,10 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
*
* @param lower Lower endpoint.
* @param upper Upper endpoint.
- * @throws NullArgumentException if the function has not been set.
- * @throws NoBracketingException if the function has the same sign at
- * the endpoints.
+ * @throws org.apache.commons.math4.exception.NullArgumentException
+ * if the function has not been set.
+ * @throws org.apache.commons.math4.exception.NoBracketingException
+ * if the function has the same sign at the endpoints.
*/
protected void verifyBracketing(final double lower,
final double upper) {
diff --git a/src/main/java/org/apache/commons/math4/util/IterationManager.java b/src/main/java/org/apache/commons/math4/util/IterationManager.java
index bd29ed7..91accb8 100644
--- a/src/main/java/org/apache/commons/math4/util/IterationManager.java
+++ b/src/main/java/org/apache/commons/math4/util/IterationManager.java
@@ -19,8 +19,6 @@ package org.apache.commons.math4.util;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArrayList;
-import org.apache.commons.math4.exception.MaxCountExceededException;
-
/**
* This abstract class provides a general framework for managing iterative
* algorithms. The maximum number of iterations can be set, and methods are
@@ -42,8 +40,8 @@ public class IterationManager {
* Creates a new instance of this class.
*
* @param maxIterations Maximum number of iterations.
- * {@link MaxCountExceededException} will be raised at
- * counter exhaustion.
+ * {@link org.apache.commons.math4.exception.MaxCountExceededException}
+ * will be raised at counter exhaustion.
*/
public IterationManager(final int maxIterations) {
this(maxIterations, null);
@@ -55,8 +53,8 @@ public class IterationManager {
* @param maxIterations the maximum number of iterations
* @param callback the function to be called when the maximum number of
* iterations has been reached.
- * If {@code null}, {@link MaxCountExceededException} will be raised at
- * counter exhaustion.
+ * If {@code null}, {@link org.apache.commons.math4.exception.MaxCountExceededException}
+ * will be raised at counter exhaustion.
*
* @since 3.1
*/
@@ -149,8 +147,8 @@ public class IterationManager {
* maximum number of iterations is reached. This method should be called at
* the beginning of a new iteration.
*
- * @throws MaxCountExceededException if the maximum number of iterations is
- * reached.
+ * @throws org.apache.commons.math4.exception.MaxCountExceededException
+ * if the maximum number of iterations is reached.
*/
public void incrementIterationCount() {
iterations.increment();
[commons-math] 03/03: Track changes.
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 00f4de04fb0452bcf29053842935c8ba7257e13c
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Sun Apr 5 03:07:25 2020 +0200
Track changes.
---
src/changes/changes.xml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 89e729d..e6c2c8a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
+ <action dev="erans" type="add" issue="MATH-1529">
+ "AkimaSplineInterpolator": Option to use alternative weights.
+ </action>
<action dev="erans" type="add" issue="MATH-1509" due-to="Chen Tao">
Add "MiniBatchKMeansClusterer" clustering algorithm.
</action>