org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction Java Examples
The following examples show how to use
org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #2
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #3
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #4
Source File: ResultsDriftCorrection.java From thunderstorm with GNU General Public License v3.0 | 6 votes |
private DriftResults loadResultsFromFile(String path) throws IOException { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(path)); Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter( UnivariateFunction.class, new InstanceCreator<PolynomialSplineFunction>() { @Override public PolynomialSplineFunction createInstance(Type type) { return new PolynomialSplineFunction(new double[]{1, 2}, new PolynomialFunction[]{new PolynomialFunction(new double[1])}); } }).create(); return gson.fromJson(reader, DriftResults.class); } finally { if(reader != null) { reader.close(); } } }
Example #5
Source File: ModifiedLoess.java From thunderstorm with GNU General Public License v3.0 | 6 votes |
/** * Compute an interpolating function by performing a loess fit * on the data at the original abscissae and then building a cubic spline * with a * {@link org.apache.commons.math3.analysis.interpolation.SplineInterpolator} * on the resulting fit. * * @param xval the arguments for the interpolation points * @param yval the values for the interpolation points * @return A cubic spline built upon a loess fit to the data at the original abscissae * @throws NonMonotonicSequenceException if {@code xval} not sorted in * strictly increasing order. * @throws DimensionMismatchException if {@code xval} and {@code yval} have * different sizes. * @throws NoDataException if {@code xval} or {@code yval} has zero size. * @throws NotFiniteNumberException if any of the arguments and values are * not finite real numbers. * @throws NumberIsTooSmallException if the bandwidth is too small to * accomodate the size of the input data (i.e. the bandwidth must be * larger than 2/n). */ public final PolynomialSplineFunction interpolate(double[] xval, double[] yval) throws NonMonotonicSequenceException, DimensionMismatchException, NoDataException, NotFiniteNumberException, NumberIsTooSmallException { double[] smoothed = smooth(xval, yval); DoubleList newX = new ArrayDoubleList(); DoubleList newSmoothed = new ArrayDoubleList(); newX.add(xval[0]); newSmoothed.add(smoothed[0]); for(int i = 1; i < xval.length; i++){ if(xval[i] != xval[i-1]){ newX.add(xval[i]); newSmoothed.add(smoothed[i]); } } xval = newX.toArray(); smoothed = newSmoothed.toArray(); return new SplineInterpolator().interpolate(xval, smoothed); }
Example #6
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #7
Source File: DriftResults.java From thunderstorm with GNU General Public License v3.0 | 6 votes |
public DriftResults(PolynomialSplineFunction xFunction, PolynomialSplineFunction yFunction, double[] driftDataFrame, double[] driftDataX, double[] driftDataY, int minFrame, int maxFrame, MoleculeDescriptor.Units units) { this.xFunction = xFunction; this.yFunction = yFunction; this.driftDataFrame = driftDataFrame; this.driftDataX = driftDataX; this.driftDataY = driftDataY; this.minFrame = minFrame; this.maxFrame = maxFrame; this.units = units; }
Example #8
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double tolerance = 1e-15; double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), tolerance); Assert.assertEquals(0.4,f.value(0.4), tolerance); Assert.assertEquals(1.0,f.value(1.0), tolerance); }
Example #9
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double tolerance = 1e-15; double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), tolerance); Assert.assertEquals(1.4,f.value(1.4), tolerance); Assert.assertEquals(1.5,f.value(1.5), tolerance); }
Example #10
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }
Example #11
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }
Example #12
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double tolerance = 1e-15; double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), tolerance); Assert.assertEquals(1.4,f.value(1.4), tolerance); Assert.assertEquals(1.5,f.value(1.5), tolerance); }
Example #13
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #14
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }
Example #15
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #16
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #17
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #18
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }
Example #19
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #20
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #21
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #22
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #23
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #24
Source File: ExtremumComputer.java From RipplePower with Apache License 2.0 | 6 votes |
/** * 计算分段插值拟合的导数值 * * @param input * @return */ private double[] splineDerivatives(double[] input) { double xStep = 1.0 / input.length; double[] x = new double[input.length]; double[] y = new double[input.length]; for (int i = 0; i < input.length; i++) { x[i] = i * xStep; y[i] = input[i]; } SplineInterpolator fitter = new SplineInterpolator(); PolynomialSplineFunction func = fitter.interpolate(x, y); double[] derivatives = new double[input.length]; for (int i = 0; i < derivatives.length; i++) { derivatives[i] = func.derivative().value(x[i]); } return derivatives; }
Example #25
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() throws Exception { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #26
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() throws Exception { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #27
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() throws Exception { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }
Example #28
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateTwoSegment() throws Exception { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 1.0 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance); Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance); Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance); }
Example #29
Source File: LinearInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinearDegenerateThreeSegment() throws Exception { double x[] = { 0.0, 0.5, 1.0, 1.5 }; double y[] = { 0.0, 0.5, 1.0, 1.5 }; UnivariateInterpolator i = new LinearInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 1d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); target = new double[]{y[2], 1d}; TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance); // Check interpolation Assert.assertEquals(0,f.value(0), interpolationTolerance); Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance); Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance); }
Example #30
Source File: SplineInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInterpolateLinear() { double x[] = { 0.0, 0.5, 1.0 }; double y[] = { 0.0, 0.5, 0.0 }; UnivariateInterpolator i = new SplineInterpolator(); UnivariateFunction f = i.interpolate(x, y); verifyInterpolation(f, x, y); verifyConsistency((PolynomialSplineFunction) f, x); // Verify coefficients using analytical values PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials(); double target[] = {y[0], 1.5d, 0d, -2d}; TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance); target = new double[]{y[1], 0d, -3d, 2d}; TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance); }