///
        public virtual void localMonotonicityClampedTest()
        {
//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 };
            double[] xValues = new double[] { -2.0, 3.0, 4.0, 8.0, 9.1, 10.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {0.0, 10.0, 9.5, 2.0, 1.1, -2.2, -2.6, 0.0 };
            double[] yValues = new double[] { 0.0, 10.0, 9.5, 2.0, 1.1, -2.2, -2.6, 0.0 };

            PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
            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);

            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;
            }
        }
            internal Bound(DoubleArray xValues, DoubleArray yValues) : base(xValues, yValues)
            {
                this.xValues    = xValues.toArrayUnsafe();
                this.yValues    = yValues.toArrayUnsafe();
                this.logYValues = getYLogValues(this.yValues);
                PiecewisePolynomialInterpolator underlying = new MonotonicityPreservingCubicSplineInterpolator(new LogNaturalSplineHelper());

                this.poly     = underlying.interpolate(xValues.toArray(), logYValues);
                this.polySens = Suppliers.memoize(() => underlying.interpolateWithSensitivity(xValues.toArray(), logYValues));
            }
        ///
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void nanYdataTest()
        public virtual void nanYdataTest()
        {
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0 };
            double[] yValues = new double[] { 0.0, 0.0, 0.1, 0.05, 0.2, Double.NaN };

            PiecewisePolynomialInterpolator interp    = new CubicSplineInterpolator();
            PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);

            interpPos.interpolate(xValues, yValues);
        }
            internal Bound(DoubleArray xValues, DoubleArray yValues) : base(xValues, yValues)
            {
                ArgChecker.isTrue(xValues.get(0) > 0d || xValues.get(xValues.size() - 1) < 0d, "xValues must have the same sign");
                this.xValues = xValues.toArrayUnsafe();
                this.yValues = yValues.toArrayUnsafe();
                PiecewisePolynomialInterpolator underlying = new MonotonicityPreservingCubicSplineInterpolator(new LogNaturalSplineHelper());

                this.poly     = underlying.interpolate(xValues.toArray(), getProduct(this.xValues, this.yValues));
                this.polySens = Suppliers.memoize(() => underlying.interpolateWithSensitivity(xValues.toArray(), getProduct(this.xValues, this.yValues)));
            }
Example #5
0
        static ProductPiecewisePolynomialInterpolatorTest()
        {
            PiecewisePolynomialInterpolator cubic   = new CubicSplineInterpolator();
            PiecewisePolynomialInterpolator natural = new NaturalSplineInterpolator();
            PiecewiseCubicHermiteSplineInterpolatorWithSensitivity pchip = new PiecewiseCubicHermiteSplineInterpolatorWithSensitivity();
            PiecewisePolynomialInterpolator hymanNat = new MonotonicityPreservingCubicSplineInterpolator(natural);

            INTERP       = new PiecewisePolynomialInterpolator[] { cubic, natural, hymanNat };
            INTERP_SENSE = new PiecewisePolynomialInterpolator[] { cubic, natural, pchip, hymanNat };
        }
        ///
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void infXdataMultiTest()
        public virtual void infXdataMultiTest()
        {
            double[]   xValues = new double[] { 1.0, 2.0, 3.0, INF };
            double[][] yValues = new double[][]
            {
                new double[] { 0.0, 0.1, 0.05, 0.2 },
                new double[] { 0.0, 0.1, 0.05, 0.2 }
            };

            PiecewisePolynomialInterpolator interp    = new CubicSplineInterpolator();
            PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);

            interpPos.interpolate(xValues, yValues);
        }
        ///
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void diffDataTest()
        public virtual void diffDataTest()
        {
//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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {0.0, 0.1, 0.05 };
            double[] yValues = new double[] { 0.0, 0.1, 0.05 };

            PiecewisePolynomialInterpolator interp    = new NaturalSplineInterpolator();
            PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);

            interpPos.interpolate(xValues, yValues);
        }
        ///
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void coincideDataMultiTest()
        public virtual void coincideDataMultiTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValues = new double[] {1.0, 2.0, 2.0 };
            double[] xValues = new double[] { 1.0, 2.0, 2.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] yValues = new double[][] { {2.0, 0.0, 0.1, 0.05, 2.0 }, {1.0, 0.0, 0.1, 1.05, 2.0 } };
            double[][] yValues = new double[][]
            {
                new double[] { 2.0, 0.0, 0.1, 0.05, 2.0 },
                new double[] { 1.0, 0.0, 0.1, 1.05, 2.0 }
            };

            PiecewisePolynomialInterpolator interp    = new CubicSplineInterpolator();
            PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);

            interpPos.interpolate(xValues, yValues);
        }
        /// <summary>
        /// local extrema are not necessarily at data-points
        /// </summary>
        public virtual void extremumTest()
        {
//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, 6.0, 7.0, 8 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] yValues = new double[][] { {1.0, 1.0, 2.0, 4.0, 4.0, 2.0, 1.0, 1.0 }, {10.0, 10.0, 6.0, 4.0, 4.0, 6.0, 10.0, 10.0 } };
            double[][] yValues = new double[][]
            {
                new double[] { 1.0, 1.0, 2.0, 4.0, 4.0, 2.0, 1.0, 1.0 },
                new double[] { 10.0, 10.0, 6.0, 4.0, 4.0, 6.0, 10.0, 10.0 }
            };

            PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
            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);

            assertTrue(function.evaluate(resultPos, 4.5).get(0) - function.evaluate(resultPos, 4).get(0) >= 0.0);
            assertTrue(function.evaluate(resultPos, 4.5).get(0) - function.evaluate(resultPos, 5).get(0) >= 0.0);
            assertTrue(function.evaluate(resultPos, 4.5).get(1) - function.evaluate(resultPos, 4).get(1) <= 0.0);
            assertTrue(function.evaluate(resultPos, 4.5).get(1) - function.evaluate(resultPos, 5).get(1) <= 0.0);

            const int nKeys = 41;
            double    key0  = 1.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 = 1.0 + 3.0 / (nKeys - 1) * i;
                double key = 1.0 + 3.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(resultPos, key).get(0) - function.evaluate(resultPos, key0).get(0) >= 0.0);

                key0 = 1.0 + 3.0 / (nKeys - 1) * i;
            }
            key0 = 1.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 = 1.0 + 3.0 / (nKeys - 1) * i;
                double key = 1.0 + 3.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(resultPos, key).get(1) - function.evaluate(resultPos, key0).get(1) <= 0.0);

                key0 = 1.0 + 3.0 / (nKeys - 1) * i;
            }
            key0 = 5.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 = 5.0 + 3.0 / (nKeys - 1) * i;
                double key = 5.0 + 3.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(resultPos, key).get(0) - function.evaluate(resultPos, key0).get(0) <= 0.0);

                key0 = 5.0 + 3.0 / (nKeys - 1) * i;
            }
            key0 = 5.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 = 5.0 + 3.0 / (nKeys - 1) * i;
                double key = 5.0 + 3.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(resultPos, key).get(1) - function.evaluate(resultPos, key0).get(1) >= 0.0);

                key0 = 5.0 + 3.0 / (nKeys - 1) * i;
            }
        }