/// <summary>
        /// PiecewiseCubicHermiteSplineInterpolator is not modified for positive data
        /// </summary>
        public virtual void noModificationTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValues = new double[] {1.0, 2.0, 3.0, 4.0, 5.0 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] yValues = new double[][] { {0.1, 1.0, 1.0, 20.0, 5.0 }, {1.0, 2.0, 3.0, 0.0, 0.0 } };
            double[][] yValues = new double[][]
            {
                new double[] { 0.1, 1.0, 1.0, 20.0, 5.0 },
                new double[] { 1.0, 2.0, 3.0, 0.0, 0.0 }
            };

            PiecewisePolynomialInterpolator interp = new PiecewiseCubicHermiteSplineInterpolator();
            PiecewisePolynomialResult       result = interp.interpolate(xValues, yValues);

            PiecewisePolynomialInterpolator interpPos = new NonnegativityPreservingCubicSplineInterpolator(interp);
            PiecewisePolynomialResult       resultPos = interpPos.interpolate(xValues, yValues);

            assertEquals(resultPos.Dimensions, result.Dimensions);
            assertEquals(resultPos.NumberOfIntervals, result.NumberOfIntervals);
            assertEquals(resultPos.Order, result.Order);

            for (int i = 1; i < xValues.Length - 1; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = result.getCoefMatrix().get(i, j) == 0.0 ? 1.0 : Math.abs(result.getCoefMatrix().get(i, j));
                    double @ref = result.CoefMatrix.get(i, j) == 0.0 ? 1.0 : Math.Abs(result.CoefMatrix.get(i, j));
                    assertEquals(resultPos.CoefMatrix.get(i, j), result.CoefMatrix.get(i, j), @ref * EPS);
                }
            }
        }
        public virtual void baseInterpolationTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nExamples = Y.length;
            int nExamples = Y.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n = XX.length;
            int n = XX.Length;

            for (int example = 0; example < nExamples; example++)
            {
                PiecewisePolynomialResult pp = PCHIP.interpolate(X, Y[example]);
                for (int i = 0; i < n; i++)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double y = PPVAL.evaluate(pp, XX[i]).get(0);
                    double y = PPVAL.evaluate(pp, XX[i]).get(0);
                    assertEquals(YY[example][i], y, 1e-14);
                }
            }
        }
        /// <summary>
        /// PiecewiseCubicHermiteSplineInterpolator is not modified except the first 2 and last 2 intervals
        /// </summary>
        public virtual void localMonotonicityDec2Test()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValues = new double[] {-2.0, 3.0, 4.0, 8.0, 9.1, 10.0, 12.0, 14.0 };
            double[] xValues = new double[] { -2.0, 3.0, 4.0, 8.0, 9.1, 10.0, 12.0, 14.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {11.0, 9.5, 2.0, 1.1, -2.2, -2.6, 2.0, 2.0 };
            double[] yValues = new double[] { 11.0, 9.5, 2.0, 1.1, -2.2, -2.6, 2.0, 2.0 };

            PiecewisePolynomialInterpolator interp = new PiecewiseCubicHermiteSplineInterpolator();
            PiecewisePolynomialResult       result = interp.interpolate(xValues, yValues);

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

            PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);
            PiecewisePolynomialResult       resultPos = interpPos.interpolate(xValues, yValues);

            assertEquals(resultPos.Dimensions, result.Dimensions);
            assertEquals(resultPos.NumberOfIntervals, result.NumberOfIntervals);
            assertEquals(resultPos.Order, result.Order);

            for (int i = 2; i < resultPos.NumberOfIntervals - 2; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    assertEquals(resultPos.CoefMatrix.get(i, j), result.CoefMatrix.get(i, j), EPS);
                }
            }

            const int nKeys = 121;
            double    key0  = -2.0;

            for (int i = 1; i < nKeys; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double key = -2.0 + 12.0 / (nKeys - 1) * i;
                double key = -2.0 + 12.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(resultPos, key).get(0) - function.evaluate(resultPos, key0).get(0) <= 0.0);

                key0 = -2.0 + 11.0 / (nKeys - 1) * i;
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues)
        public override PiecewisePolynomialResult interpolate(double[] xValues, double[] yValues)
        {
            return(INTERP.interpolate(xValues, yValues));
        }