///
        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;
            }
        }
        /// <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 override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is PiecewisePolynomialResult))
            {
                return(false);
            }
            PiecewisePolynomialResult other = (PiecewisePolynomialResult)obj;

            if (!_coefMatrix.Equals(other._coefMatrix))
            {
                return(false);
            }
            if (_dim != other._dim)
            {
                return(false);
            }
            if (!_knots.Equals(other._knots))
            {
                return(false);
            }
            if (_order != other._order)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Test linear extrapolation without clamped points
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void linearExtrapolationNoClampedTest()
        public virtual void linearExtrapolationNoClampedTest()
        {
            double[] xValues  = new double[] { -5.0, -1.4, 3.2, 3.5, 7.6 };
            double[] yValues  = new double[] { -2.2, 1.1, 1.9, 2.3, -0.1 };
            int      nData    = xValues.Length;
            int      nKeys    = 20;
            double   interval = (3.0 * xValues[nData - 1] - xValues[nData - 1]) / (nKeys - 1);

            double[] keys = new double[nKeys];
            int      n    = INTERP.Length;

            for (int i = 0; i < n; ++i)
            {
                ProductPiecewisePolynomialInterpolator interp = new ProductPiecewisePolynomialInterpolator(INTERP[i]);
                PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);
                for (int j = 0; j < nKeys; ++j)
                {
                    keys[j] = xValues[nData - 1] + j * interval;
                }
                double[] values = FUNC.evaluate(result, keys).row(0).toArray();
                for (int j = 2; j < nKeys; ++j)
                {
                    InterpolatorTestUtil.assertRelative("linearExtrapolationTest", values[j - 1] - values[j - 2], values[j - 1] - values[j - 2], EPS);
                }
            }
            n = INTERP_SENSE.Length;
            for (int i = 0; i < n; ++i)
            {
                ProductPiecewisePolynomialInterpolator    interp = new ProductPiecewisePolynomialInterpolator(INTERP_SENSE[i]);
                PiecewisePolynomialResultsWithSensitivity result = interp.interpolateWithSensitivity(xValues, yValues);
                for (int j = 0; j < nKeys; ++j)
                {
                    keys[j] = xValues[nData - 1] + j * interval;
                }
                double[] values = FUNC.evaluate(result, keys).row(0).toArray();
                for (int j = 2; j < nKeys; ++j)
                {
                    InterpolatorTestUtil.assertRelative("linearExtrapolationTest", values[j - 1] - values[j - 2], values[j - 1] - values[j - 2], EPS);
                }
                DoubleArray[] sense = FUNC.nodeSensitivity(result, keys);
                for (int k = 0; k < nData; ++k)
                {
                    double[] yValuesUp = Arrays.copyOf(yValues, nData);
                    double[] yValuesDw = Arrays.copyOf(yValues, nData);
                    yValuesUp[k] += DELTA / xValues[k];
                    yValuesDw[k] -= DELTA / xValues[k];
                    PiecewisePolynomialResultsWithSensitivity resultUp = interp.interpolateWithSensitivity(xValues, yValuesUp);
                    PiecewisePolynomialResultsWithSensitivity resultDw = interp.interpolateWithSensitivity(xValues, yValuesDw);
                    double[] tmpUp = FUNC.evaluate(resultUp, keys).rowArray(0);
                    double[] tmpDw = FUNC.evaluate(resultDw, keys).rowArray(0);
                    for (int l = 0; l < nKeys; ++l)
                    {
                        double res = 0.5 * (tmpUp[l] - tmpDw[l]) / DELTA;   // lk
                        InterpolatorTestUtil.assertRelative("linearExtrapolationTest", sense[l].get(k), res, DELTA);
                    }
                }
            }
        }
        /// <summary>
        /// Interpolate.
        /// </summary>
        /// <param name="xValues"> X values of data </param>
        /// <param name="yValues"> Y values of data </param>
        /// <param name="xKeys">  the keys </param>
        /// <returns> Values of the underlying cubic spline function at the values of x </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public com.opengamma.strata.collect.array.DoubleArray interpolate(final double[] xValues, final double[] yValues, final double[] xKeys)
        public virtual DoubleArray interpolate(double[] xValues, double[] yValues, double[] xKeys)
        {
            ArgChecker.notNull(xKeys, "xKeys");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int keyLength = xKeys.length;
            int keyLength = xKeys.Length;

            for (int i = 0; i < keyLength; ++i)
            {
                ArgChecker.isFalse(double.IsNaN(xKeys[i]), "xKeys containing NaN");
                ArgChecker.isFalse(double.IsInfinity(xKeys[i]), "xKeys containing Infinity");
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult result = this.interpolate(xValues, yValues);
            PiecewisePolynomialResult result = this.interpolate(xValues, yValues);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray knots = result.getKnots();
            DoubleArray knots = result.Knots;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nKnots = knots.size();
            int nKnots = knots.size();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix coefMatrix = result.getCoefMatrix();
            DoubleMatrix coefMatrix = result.CoefMatrix;

            double[] res = new double[keyLength];

            for (int j = 0; j < keyLength; ++j)
            {
                int indicator = 0;
                if (xKeys[j] < knots.get(1))
                {
                    indicator = 0;
                }
                else
                {
                    for (int i = 1; i < nKnots - 1; ++i)
                    {
                        if (knots.get(i) <= xKeys[j])
                        {
                            indicator = i;
                        }
                    }
                }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray coefs = coefMatrix.row(indicator);
                DoubleArray coefs = coefMatrix.row(indicator);
                res[j] = getValue(coefs, xKeys[j], knots.get(indicator));
                ArgChecker.isFalse(double.IsInfinity(res[j]), "Too large input");
                ArgChecker.isFalse(double.IsNaN(res[j]), "Too large input");
            }

            return(DoubleArray.copyOf(res));
        }
 public virtual void testInterpolate()
 {
     foreach (PiecewisePolynomialInterpolator baseInterp in BASE_INTERP)
     {
         ClampedPiecewisePolynomialInterpolator interp = new ClampedPiecewisePolynomialInterpolator(baseInterp, X_CLAMPED, Y_CLAMPED);
         PiecewisePolynomialResult computed            = interp.interpolate(X_VALUES, Y_VALUES);
         PiecewisePolynomialResult expected            = baseInterp.interpolate(X_VALUES_TOTAL, Y_VALUES_TOTAL);
         assertEquals(computed, expected);
         assertEquals(interp.PrimaryMethod, baseInterp);
     }
 }
Exemplo n.º 7
0
        ///
        public virtual void recov4ptsMultiTest()
        {
//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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] yValues = new double[][] { {6.0, 25.0 / 6.0, 10.0 / 3.0, 4.0 }, {6.0, 1.0, 0.0, 0.0 } };
            double[][] yValues = new double[][]
            {
                new double[] { 6.0, 25.0 / 6.0, 10.0 / 3.0, 4.0 },
                new double[] { 6.0, 1.0, 0.0, 0.0 }
            };

            const int nIntervalsExp = 3;
            const int orderExp      = 4;
            const int dimExp        = 2;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefsMatExp = new double[][] { {1.0 / 6.0, 0.0, -2.0, 6.0 }, {1.0, 0.0, -6.0, 6.0 }, {1.0 / 6.0, 1.0 / 2.0, -3.0 / 2.0, 25.0 / 6.0 }, {-1.0, 3.0, -3.0, 1.0 }, {-1.0 / 3.0, 1.0, 0.0, 10.0 / 3.0 }, {0.0, 0.0, 0.0, 0 } };
            double[][] coefsMatExp = new double[][]
            {
                new double[] { 1.0 / 6.0, 0.0, -2.0, 6.0 },
                new double[] { 1.0, 0.0, -6.0, 6.0 },
                new double[] { 1.0 / 6.0, 1.0 / 2.0, -3.0 / 2.0, 25.0 / 6.0 },
                new double[] { -1.0, 3.0, -3.0, 1.0 },
                new double[] { -1.0 / 3.0, 1.0, 0.0, 10.0 / 3.0 },
                new double[] { 0.0, 0.0, 0.0, 0 }
            };

            NaturalSplineInterpolator interpMatrix = new NaturalSplineInterpolator();

            PiecewisePolynomialResult result = interpMatrix.interpolate(xValues, yValues);

            assertEquals(result.Dimensions, dimExp);
            assertEquals(result.NumberOfIntervals, nIntervalsExp);
            assertEquals(result.Dimensions, dimExp);

            for (int i = 0; i < nIntervalsExp * dimExp; ++i)
            {
                for (int j = 0; j < orderExp; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = coefsMatExp[i][j] == 0.0 ? 1.0 : Math.abs(coefsMatExp[i][j]);
                    double @ref = coefsMatExp[i][j] == 0.0 ? 1.0 : Math.Abs(coefsMatExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatExp[i][j], @ref * EPS);
                }
            }

            for (int j = 0; j < nIntervalsExp + 1; ++j)
            {
                assertEquals(result.Knots.get(j), xValues[j]);
            }
        }
        ///
        public virtual void flipTest()
        {
//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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {3.0, 0.1, 0.01, 0.01, 0.1, 3.0 };
            double[] yValues = new double[] { 3.0, 0.1, 0.01, 0.01, 0.1, 3.0 };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValuesFlip = new double[] {6.0, 2.0, 3.0, 5.0, 4.0, 1.0 };
            double[] xValuesFlip = new double[] { 6.0, 2.0, 3.0, 5.0, 4.0, 1.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValuesFlip = new double[] {3.0, 0.1, 0.01, 0.1, 0.01, 3.0 };
            double[] yValuesFlip = new double[] { 3.0, 0.1, 0.01, 0.1, 0.01, 3.0 };

            PiecewisePolynomialInterpolator interp = new NaturalSplineInterpolator();

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

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

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

            const int nPts = 101;

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

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData = xValues.length;
            int nData = xValues.Length;

            for (int i = 0; i < nData - 1; ++i)
            {
                for (int k = 0; k < 4; ++k)
                {
                    assertEquals(resultPos.CoefMatrix.get(i, k), resultPosFlip.CoefMatrix.get(i, k));
                }
            }
        }
        ///
        public virtual void positivityClampedMultiTest()
        {
//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.0, 0.1, 1.0, 1.0, 20.0, 5.0, 0.0 }, {-10.0, 0.1, 1.0, 1.0, 20.0, 5.0, 0.0 } };
            double[][] yValues = new double[][]
            {
                new double[] { 0.0, 0.1, 1.0, 1.0, 20.0, 5.0, 0.0 },
                new double[] { -10.0, 0.1, 1.0, 1.0, 20.0, 5.0, 0.0 }
            };

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

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

            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);

            const int nPts = 101;

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

            int dim   = yValues.Length;
            int nData = xValues.Length;

            for (int j = 0; j < dim; ++j)
            {
                for (int i = 1; i < nData - 2; ++i)
                {
                    DoubleMatrix coefMatrix = resultPos.CoefMatrix;
                    double       tau        = Math.Sign(coefMatrix.get(dim * i + j, 3));
                    assertTrue(coefMatrix.get(dim * i + j, 2) * tau >= -3.0 * yValues[j][i + 1] * tau / (xValues[i + 1] - xValues[i]));
                    assertTrue(coefMatrix.get(dim * i + j, 2) * tau <= 3.0 * yValues[j][i + 1] * tau / (xValues[i] - xValues[i - 1]));
                }
            }
        }
        /// <summary>
        /// Interpolate.
        /// </summary>
        /// <param name="xValues"> X values of data </param>
        /// <param name="yValues"> Y values of data </param>
        /// <param name="xKey">  the key </param>
        /// <returns> value of the underlying cubic spline function at the value of x </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public double interpolate(final double[] xValues, final double[] yValues, final double xKey)
        public virtual double interpolate(double[] xValues, double[] yValues, double xKey)
        {
            ArgChecker.isFalse(double.IsNaN(xKey), "xKey containing NaN");
            ArgChecker.isFalse(double.IsInfinity(xKey), "xKey containing Infinity");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult result = this.interpolate(xValues, yValues);
            PiecewisePolynomialResult result = this.interpolate(xValues, yValues);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray knots = result.getKnots();
            DoubleArray knots = result.Knots;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nKnots = knots.size();
            int nKnots = knots.size();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix coefMatrix = result.getCoefMatrix();
            DoubleMatrix coefMatrix = result.CoefMatrix;

            double res = 0.0;

            int indicator = 0;

            if (xKey < knots.get(1))
            {
                indicator = 0;
            }
            else
            {
                for (int i = 1; i < nKnots - 1; ++i)
                {
                    if (knots.get(i) <= xKey)
                    {
                        indicator = i;
                    }
                }
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray coefs = coefMatrix.row(indicator);
            DoubleArray coefs = coefMatrix.row(indicator);

            res = getValue(coefs, xKey, knots.get(indicator));
            ArgChecker.isFalse(double.IsInfinity(res), "Too large input");
            ArgChecker.isFalse(double.IsNaN(res), "Too large input");

            return(res);
        }
        /// <summary>
        /// Sample data
        /// </summary>
        public virtual void sampleDataTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValues = new double[] {0.0, 10.0, 30.0, 50.0, 70.0, 90.0, 100.0 };
            double[] xValues = new double[] { 0.0, 10.0, 30.0, 50.0, 70.0, 90.0, 100.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {30.0, 130.0, 150.0, 150.0, 170.0, 220.0, 320.0 };
            double[] yValues = new double[] { 30.0, 130.0, 150.0, 150.0, 170.0, 220.0, 320.0 };

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

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefsMatPartExp = new double[][] { {-9.0 / 220.0, 0.0, 155.0 / 11.0, 30.0 }, {-1.0 / 2200.0, -7.0 / 220.0, 20.0 / 11.0, 130.0 }, {0.0, 0.0, 0.0, 150.0 } };
            double[][] coefsMatPartExp = new double[][]
            {
                new double[] { -9.0 / 220.0, 0.0, 155.0 / 11.0, 30.0 },
                new double[] { -1.0 / 2200.0, -7.0 / 220.0, 20.0 / 11.0, 130.0 },
                new double[] { 0.0, 0.0, 0.0, 150.0 }
            };
            for (int i = 0; i < 3; ++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 = Math.abs(coefsMatPartExp[i][j]) == 0.0 ? 1.0 : Math.abs(coefsMatPartExp[i][j]);
                    double @ref = Math.Abs(coefsMatPartExp[i][j]) == 0.0 ? 1.0 : Math.Abs(coefsMatPartExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatPartExp[i][j], @ref * EPS);
                }
            }

            int    nKeys = 101;
            double key0  = 0.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 = 0.0 + 100.0 / (nKeys - 1) * i;
                double key = 0.0 + 100.0 / (nKeys - 1) * i;

                assertTrue(function.evaluate(result, key).get(0) - function.evaluate(result, key0).get(0) >= -EPS);
                key0 = 0.0 + 100.0 / (nKeys - 1) * i;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Left extrapolation by linear function unless extra node is added on the left
        /// </summary>
        private PiecewisePolynomialResult extrapolateByLinearFunction(PiecewisePolynomialResult result, double[] xValues)
        {
            int nIntervalsAll = result.NumberOfIntervals;

            double[] nodes = result.Knots.toArray();
            if (Math.Abs(xValues[xValues.Length - 1] - nodes[nIntervalsAll]) < EPS)
            {
                double   lastNodeX       = nodes[nIntervalsAll];
                double   lastNodeY       = FUNC.evaluate(result, lastNodeX).get(0);
                double   extraNode       = 2.0 * nodes[nIntervalsAll] - nodes[nIntervalsAll - 1];
                double   extraDerivative = FUNC.differentiate(result, lastNodeX).get(0);
                double[] newKnots        = new double[nIntervalsAll + 2];
                Array.Copy(nodes, 0, newKnots, 0, nIntervalsAll + 1);
                newKnots[nIntervalsAll + 1] = extraNode;   // dummy node, outside the data range
                double[][] newCoefMatrix = new double[nIntervalsAll + 1][];
                for (int i = 0; i < nIntervalsAll; ++i)
                {
                    newCoefMatrix[i] = Arrays.copyOf(result.CoefMatrix.row(i).toArray(), result.Order);
                }
                newCoefMatrix[nIntervalsAll] = new double[result.Order];
                newCoefMatrix[nIntervalsAll][result.Order - 1] = lastNodeY;
                newCoefMatrix[nIntervalsAll][result.Order - 2] = extraDerivative;
                if (result is PiecewisePolynomialResultsWithSensitivity)
                {
                    PiecewisePolynomialResultsWithSensitivity resultCast = (PiecewisePolynomialResultsWithSensitivity)result;
                    double[]       extraSense    = FUNC.nodeSensitivity(resultCast, lastNodeX).toArray();
                    double[]       extraSenseDer = FUNC.differentiateNodeSensitivity(resultCast, lastNodeX).toArray();
                    DoubleMatrix[] newCoefSense  = new DoubleMatrix[nIntervalsAll + 1];
                    for (int i = 0; i < nIntervalsAll; ++i)
                    {
                        newCoefSense[i] = resultCast.getCoefficientSensitivity(i);
                    }
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] extraCoefSense = new double[resultCast.Order][extraSense.Length];
                    double[][] extraCoefSense = RectangularArrays.ReturnRectangularDoubleArray(resultCast.Order, extraSense.Length);
                    extraCoefSense[resultCast.Order - 1] = Arrays.copyOf(extraSense, extraSense.Length);
                    extraCoefSense[resultCast.Order - 2] = Arrays.copyOf(extraSenseDer, extraSenseDer.Length);
                    newCoefSense[nIntervalsAll]          = DoubleMatrix.copyOf(extraCoefSense);
                    return(new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(newKnots), DoubleMatrix.copyOf(newCoefMatrix), resultCast.Order, 1, newCoefSense));
                }
                return(new PiecewisePolynomialResult(DoubleArray.copyOf(newKnots), DoubleMatrix.copyOf(newCoefMatrix), result.Order, 1));
            }
            return(result);
        }
Exemplo n.º 13
0
        ///
        public virtual void recov4ptsTest()
        {
            double[] xValues = new double[] { 1.0, 2.0, 4.0, 7.0 };
            double[] yValues = new double[] { 6.0, 1.0, 8.0, -2.0 };

            int nIntervalsExp = 3;
            int orderExp      = 2;
            int dimExp        = 1;

            double[][] coefsMatExp = new double[][]
            {
                new double[] { -5.0, 6.0 },
                new double[] { 7.0 / 2.0, 1.0 },
                new double[] { -10.0 / 3.0, 8.0 }
            };
            LinearInterpolator        interpMatrix = new LinearInterpolator();
            PiecewisePolynomialResult result       = interpMatrix.interpolate(xValues, yValues);

            assertEquals(result.Dimensions, dimExp);
            assertEquals(result.NumberOfIntervals, nIntervalsExp);
            assertEquals(result.Dimensions, dimExp);

            for (int i = 0; i < nIntervalsExp; ++i)
            {
                for (int j = 0; j < orderExp; ++j)
                {
                    double @ref = coefsMatExp[i][j] == 0.0 ? 1.0 : Math.Abs(coefsMatExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatExp[i][j], @ref * EPS);
                }
            }
            for (int j = 0; j < nIntervalsExp + 1; ++j)
            {
                assertEquals(result.Knots.get(j), xValues[j]);
            }

            // sensitivity
            double delta = 1.0e-6;

            double[] keys = new double[] { -1.5, 2.43, 4.0, 7.0, 12.7 };
            testSensitivity(xValues, yValues, keys, delta);
        }
        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);
                }
            }
        }
Exemplo n.º 15
0
        //-------------------------------------------------------------------------
        private void testSensitivity(double[] xValues, double[] yValues, double[] keys, double delta)
        {
            PiecewisePolynomialWithSensitivityFunction1D func        = new PiecewisePolynomialWithSensitivityFunction1D();
            PiecewisePolynomialResultsWithSensitivity    resultSensi = INTERP.interpolateWithSensitivity(xValues, yValues);

            DoubleArray[] computedArray = func.nodeSensitivity(resultSensi, keys);
            for (int i = 0; i < keys.Length; ++i)
            {
                double      @base    = func.evaluate(resultSensi, keys[i]).get(0);
                DoubleArray computed = func.nodeSensitivity(resultSensi, keys[i]);
                assertEquals(computed, computedArray[i]);
                for (int j = 0; j < yValues.Length; ++j)
                {
                    double[] yValuesBump = Arrays.copyOf(yValues, yValues.Length);
                    yValuesBump[j] += delta;
                    PiecewisePolynomialResult resultBump = INTERP.interpolate(xValues, yValuesBump);
                    double expected = (func.evaluate(resultBump, keys[i]).get(0) - @base) / delta;
                    assertEquals(computed.get(j), expected, delta);
                }
            }
        }
        ///
        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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {1.0, 1.0, 4.0, 5.0, 4.0, 1.0, 1.0 };
            double[] yValues = new double[] { 1.0, 1.0, 4.0, 5.0, 4.0, 1.0, 1.0 };

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

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

            assertEquals(result.Dimensions, 1);
            assertEquals(result.NumberOfIntervals, 6);
            assertEquals(result.Order, 4);

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

            key0 = 4.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 = 4.0 + 3.0 / (nKeys - 1) * i;
                double key = 4.0 + 3.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(result, key).get(0) - function.evaluate(result, key0).get(0) <= 0.0);
                key0 = 4.0 + 3.0 / (nKeys - 1) * i;
            }
        }
        public virtual void testFunctionalForm()
        {
            double[] xValues = new double[] { 0.5, 1.0, 3.0, 5.0, 10.0, 30.0 };
            double   lambda0 = 0.14;

            double[] lambda    = new double[] { 0.25, 0.05, -0.12, 0.03, -0.15, 0.0 };
            double   pValueTmp = 0d;
            int      nData     = xValues.Length;

            for (int i = 0; i < nData - 1; ++i)
            {
                lambda[nData - 1] += lambda[i] * xValues[i];
                pValueTmp         += lambda[i];
            }
            lambda[nData - 1] *= -1d / xValues[nData - 1];
            pValueTmp         += lambda[nData - 1];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double pValue = pValueTmp;
            double pValue = pValueTmp;
            Function <double, double> func = new FunctionAnonymousInnerClass(this, xValues, lambda0, lambda, nData, pValue);

            double[] rt = new double[nData];
            for (int i = 0; i < nData; ++i)
            {
                rt[i] = func.apply(xValues[i]);
            }
            ClampedPiecewisePolynomialInterpolator interp = new ClampedPiecewisePolynomialInterpolator(BASE_INTERP[0], new double[] { 0d }, new double[] { 0d });
            PiecewisePolynomialResult     result          = interp.interpolate(xValues, rt);
            PiecewisePolynomialFunction1D polyFunc        = new PiecewisePolynomialFunction1D();

            for (int i = 0; i < 600; ++i)
            {
                double tm  = 0.05 * i;
                double exp = func.apply(tm);
                assertEquals(exp, polyFunc.evaluate(result, tm).get(0), Math.Abs(exp) * TOL);
            }
        }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public PiecewisePolynomialResult2D interpolate(final double[] x0Values, final double[] x1Values, final double[][] yValues)
        public override PiecewisePolynomialResult2D interpolate(double[] x0Values, double[] x1Values, double[][] yValues)
        {
            ArgChecker.notNull(x0Values, "x0Values");
            ArgChecker.notNull(x1Values, "x1Values");
            ArgChecker.notNull(yValues, "yValues");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData0 = x0Values.length;
            int nData0 = x0Values.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData1 = x1Values.length;
            int nData1 = x1Values.Length;

            DoubleMatrix yValuesMatrix = DoubleMatrix.copyOf(yValues);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction1D func = new com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction1D();
            PiecewisePolynomialFunction1D func = new PiecewisePolynomialFunction1D();

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] diff0 = new double[nData1][nData0];
            double[][] diff0 = RectangularArrays.ReturnRectangularDoubleArray(nData1, nData0);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] diff1 = new double[nData0][nData1];
            double[][] diff1 = RectangularArrays.ReturnRectangularDoubleArray(nData0, nData1);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] cross = new double[nData0][nData1];
            double[][] cross = RectangularArrays.ReturnRectangularDoubleArray(nData0, nData1);

            PiecewisePolynomialResult result0 = _method[0].interpolate(x0Values, OG_ALGEBRA.getTranspose(yValuesMatrix).toArray());

            diff0 = func.differentiate(result0, x0Values).toArray();

            PiecewisePolynomialResult result1 = _method[1].interpolate(x1Values, yValuesMatrix.toArray());

            diff1 = func.differentiate(result1, x1Values).toArray();

            const int order = 4;

            for (int i = 0; i < nData0; ++i)
            {
                for (int j = 0; j < nData1; ++j)
                {
                    if (yValues[i][j] == 0.0)
                    {
                        if (diff0[j][i] == 0.0)
                        {
                            cross[i][j] = diff1[i][j];
                        }
                        else
                        {
                            if (diff1[i][j] == 0.0)
                            {
                                cross[i][j] = diff0[j][i];
                            }
                            else
                            {
                                cross[i][j] = Math.Sign(diff0[j][i] * diff1[i][j]) * Math.Sqrt(Math.Abs(diff0[j][i] * diff1[i][j]));
                            }
                        }
                    }
                    else
                    {
                        cross[i][j] = diff0[j][i] * diff1[i][j] / yValues[i][j];
                    }
                }
            }

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: DoubleMatrix[][] coefMat = new DoubleMatrix[nData0 - 1][nData1 - 1];
            DoubleMatrix[][] coefMat = RectangularArrays.ReturnRectangularDoubleMatrixArray(nData0 - 1, nData1 - 1);
            for (int i = 0; i < nData0 - 1; ++i)
            {
                for (int j = 0; j < nData1 - 1; ++j)
                {
                    double[] diffsVec = new double[16];
                    for (int l = 0; l < 2; ++l)
                    {
                        for (int m = 0; m < 2; ++m)
                        {
                            diffsVec[l + 2 * m] = yValues[i + l][j + m];
                        }
                    }
                    for (int l = 0; l < 2; ++l)
                    {
                        for (int m = 0; m < 2; ++m)
                        {
                            diffsVec[4 + l + 2 * m] = diff0[j + m][i + l];
                        }
                    }
                    for (int l = 0; l < 2; ++l)
                    {
                        for (int m = 0; m < 2; ++m)
                        {
                            diffsVec[8 + l + 2 * m] = diff1[i + l][j + m];
                        }
                    }
                    for (int l = 0; l < 2; ++l)
                    {
                        for (int m = 0; m < 2; ++m)
                        {
                            diffsVec[12 + l + 2 * m] = cross[i + l][j + m];
                        }
                    }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray diffs = com.opengamma.strata.collect.array.DoubleArray.copyOf(diffsVec);
                    DoubleArray diffs = DoubleArray.copyOf(diffsVec);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray ansVec = ((com.opengamma.strata.collect.array.DoubleArray) OG_ALGEBRA.multiply(INV_MAT, diffs));
                    DoubleArray ansVec = ((DoubleArray)OG_ALGEBRA.multiply(INV_MAT, diffs));

                    double @ref = 0.0;
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] coefMatTmp = new double[order][order];
                    double[][] coefMatTmp = RectangularArrays.ReturnRectangularDoubleArray(order, order);
                    for (int l = 0; l < order; ++l)
                    {
                        for (int m = 0; m < order; ++m)
                        {
                            coefMatTmp[order - l - 1][order - m - 1] = ansVec.get(l + m * (order)) / Math.Pow((x0Values[i + 1] - x0Values[i]), l) / Math.Pow((x1Values[j + 1] - x1Values[j]), m);
                            ArgChecker.isFalse(double.IsNaN(coefMatTmp[order - l - 1][order - m - 1]), "Too large/small input");
                            ArgChecker.isFalse(double.IsInfinity(coefMatTmp[order - l - 1][order - m - 1]), "Too large/small input");
                            @ref += coefMatTmp[order - l - 1][order - m - 1] * Math.Pow((x0Values[i + 1] - x0Values[i]), l) * Math.Pow((x1Values[j + 1] - x1Values[j]), m);
                        }
                    }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double bound = Math.max(Math.abs(ref) + Math.abs(yValues[i + 1][j + 1]), 0.1);
                    double bound = Math.Max(Math.Abs(@ref) + Math.Abs(yValues[i + 1][j + 1]), 0.1);
                    ArgChecker.isTrue(Math.Abs(@ref - yValues[i + 1][j + 1]) < ERROR * bound, "Input is too large/small or data points are too close");
                    coefMat[i][j] = DoubleMatrix.copyOf(coefMatTmp);
                }
            }

            return(new PiecewisePolynomialResult2D(DoubleArray.copyOf(x0Values), DoubleArray.copyOf(x1Values), coefMat, new int[] { order, order }));
        }
        /// <summary>
        /// Recovering quadratic function
        /// </summary>
        public virtual void quadraticTest()
        {
//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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData = xValues.length;
            int nData = xValues.Length;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[nData];
            double[] yValues = new double[nData];
            for (int i = 0; i < nData; ++i)
            {
                yValues[i] = xValues[i] * xValues[i] / 7.0 + xValues[i] / 13.0 + 1 / 11.0;
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefsMatExp = new double[][] { {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[0] + 1.0 / 13.0, yValues[0] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[1] + 1.0 / 13.0, yValues[1] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[2] + 1.0 / 13.0, yValues[2] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[3] + 1.0 / 13.0, yValues[3] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[4] + 1.0 / 13.0, yValues[4] } };
            double[][] coefsMatExp = new double[][]
            {
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[0] + 1.0 / 13.0, yValues[0] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[1] + 1.0 / 13.0, yValues[1] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[2] + 1.0 / 13.0, yValues[2] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[3] + 1.0 / 13.0, yValues[3] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[4] + 1.0 / 13.0, yValues[4] }
            };

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

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

            assertEquals(result.Dimensions, 1);
            assertEquals(result.NumberOfIntervals, 5);
            assertEquals(result.Order, 4);

            for (int i = 0; i < result.NumberOfIntervals; ++i)
            {
                for (int j = 0; j < result.Order; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(coefsMatExp[i][j]) == 0.0 ? 1.0 : Math.abs(coefsMatExp[i][j]);
                    double @ref = Math.Abs(coefsMatExp[i][j]) == 0.0 ? 1.0 : Math.Abs(coefsMatExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatExp[i][j], @ref * EPS);
                }
            }

            const int nKeys = 101;

            for (int i = 0; i < nKeys; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double key = 1.0 + 5.0 / (nKeys - 1) * i;
                double key = 1.0 + 5.0 / (nKeys - 1) * i;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = key * key / 7.0 + key / 13.0 + 1 / 11.0;
                double @ref = key * key / 7.0 + key / 13.0 + 1 / 11.0;
                assertEquals(function.evaluate(result, key).get(0), @ref, @ref * EPS);
            }
        }
        /// <summary>
        /// Sample data given in the original paper, consisting of constant part and monotonically increasing part
        /// </summary>
        public virtual void sampleDataTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] xValues = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
            double[] xValues = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] yValues = new double[] {10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.5, 15.0, 50.0, 60.0, 85.0 };
            double[] yValues = new double[] { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.5, 15.0, 50.0, 60.0, 85.0 };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefsMatPartExp = new double[][] { {0.0, 0.0, 0.0, 10.0 }, {0.0, 0.0, 0.0, 10.0 }, {0.0, 0.0, 0.0, 10.0 }, {0.0, 0.0, 0.0, 10.0 }, {0.0, 0.0, 0.0, 10.0 } };
            double[][] coefsMatPartExp = new double[][]
            {
                new double[] { 0.0, 0.0, 0.0, 10.0 },
                new double[] { 0.0, 0.0, 0.0, 10.0 },
                new double[] { 0.0, 0.0, 0.0, 10.0 },
                new double[] { 0.0, 0.0, 0.0, 10.0 },
                new double[] { 0.0, 0.0, 0.0, 10.0 }
            };

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

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

            assertEquals(result.Dimensions, 1);
            assertEquals(result.NumberOfIntervals, 10);
            assertEquals(result.Order, 4);

            for (int i = 0; i < 5; ++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 = Math.abs(coefsMatPartExp[i][j]) == 0.0 ? 1.0 : Math.abs(coefsMatPartExp[i][j]);
                    double @ref = Math.Abs(coefsMatPartExp[i][j]) == 0.0 ? 1.0 : Math.Abs(coefsMatPartExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatPartExp[i][j], @ref * EPS);
                }
            }

            const int nKeys = 101;
            double    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 + 5.0 / (nKeys - 1) * i;
                double key = 5.0 + 5.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(result, key).get(0) - function.evaluate(result, key0).get(0) >= 0.0);
                key0 = 5.0 + 5.0 / (nKeys - 1) * i;
            }

            key0 = 0.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 = 0.0 + 5.0 / (nKeys - 1) * i;
                double key = 0.0 + 5.0 / (nKeys - 1) * i;
                assertTrue(function.evaluate(result, key).get(0) - function.evaluate(result, key0).get(0) == 0.0);
                key0 = 0.0 + 5.0 / (nKeys - 1) * i;
            }
        }
        ///
        public virtual void quadraticMultiTest()
        {
//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 };
            double[] xValues = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData = xValues.length;
            int nData = xValues.Length;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] yValues = new double[2][nData];
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] yValues = new double[2][nData];
            double[][] yValues = RectangularArrays.ReturnRectangularDoubleArray(2, nData);
            for (int i = 0; i < nData; ++i)
            {
                yValues[0][i] = xValues[i] * xValues[i] / 7.0 + xValues[i] / 13.0 + 1 / 11.0;
            }
            for (int i = 0; i < nData; ++i)
            {
                yValues[1][i] = xValues[i] * xValues[i] / 3.0 + xValues[i] / 7.0 + 1 / 17.0;
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefsMatExp = new double[][] { {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[0] + 1.0 / 13.0, yValues[0][0] }, {0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[0] + 1.0 / 7.0, yValues[1][0] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[1] + 1.0 / 13.0, yValues[0][1] }, {0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[1] + 1.0 / 7.0, yValues[1][1] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[2] + 1.0 / 13.0, yValues[0][2] }, {0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[2] + 1.0 / 7.0, yValues[1][2] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[3] + 1.0 / 13.0, yValues[0][3] }, {0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[3] + 1.0 / 7.0, yValues[1][3] }, {0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[4] + 1.0 / 13.0, yValues[0][4] }, {0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[4] + 1.0 / 7.0, yValues[1][4] } };
            double[][] coefsMatExp = new double[][]
            {
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[0] + 1.0 / 13.0, yValues[0][0] },
                new double[] { 0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[0] + 1.0 / 7.0, yValues[1][0] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[1] + 1.0 / 13.0, yValues[0][1] },
                new double[] { 0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[1] + 1.0 / 7.0, yValues[1][1] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[2] + 1.0 / 13.0, yValues[0][2] },
                new double[] { 0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[2] + 1.0 / 7.0, yValues[1][2] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[3] + 1.0 / 13.0, yValues[0][3] },
                new double[] { 0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[3] + 1.0 / 7.0, yValues[1][3] },
                new double[] { 0.0, 1.0 / 7.0, 2.0 / 7.0 * xValues[4] + 1.0 / 13.0, yValues[0][4] },
                new double[] { 0.0, 1.0 / 3.0, 2.0 / 3.0 * xValues[4] + 1.0 / 7.0, yValues[1][4] }
            };

            PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

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

            assertEquals(result.Dimensions, 2);
            assertEquals(result.NumberOfIntervals, 5);
            assertEquals(result.Order, 4);

            for (int i = 0; i < result.NumberOfIntervals * 2; ++i)
            {
                for (int j = 0; j < result.Order; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(coefsMatExp[i][j]) == 0.0 ? 1.0 : Math.abs(coefsMatExp[i][j]);
                    double @ref = Math.Abs(coefsMatExp[i][j]) == 0.0 ? 1.0 : Math.Abs(coefsMatExp[i][j]);
                    assertEquals(result.CoefMatrix.get(i, j), coefsMatExp[i][j], @ref * EPS);
                }
            }

            const int nKeys = 101;

            for (int i = 0; i < nKeys; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double key = 1.0 + 5.0 / (nKeys - 1) * i;
                double key = 1.0 + 5.0 / (nKeys - 1) * i;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = key * key / 7.0 + key / 13.0 + 1 / 11.0;
                double @ref = key * key / 7.0 + key / 13.0 + 1 / 11.0;
                assertEquals(function.evaluate(result, key).get(0), @ref, @ref * EPS);
            }
        }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void hashCodeEqualsTest()
        public virtual void hashCodeEqualsTest()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] knots1 = new double[] {1.0, 2.0, 3.0, 4.0 };
            double[] knots1 = 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[] knots2 = new double[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
            double[] knots2 = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] matrix1 = new double[][] { {3.0, 3.0, 3.0 }, {1.0, 1.0, 1.0 }, {2.0, 2.0, 2.0 }, {3.0, 3.0, 3.0 }, {1.0, 1.0, 1.0 }, {2.0, 2.0, 2.0 } };
            double[][] matrix1 = new double[][]
            {
                new double[] { 3.0, 3.0, 3.0 },
                new double[] { 1.0, 1.0, 1.0 },
                new double[] { 2.0, 2.0, 2.0 },
                new double[] { 3.0, 3.0, 3.0 },
                new double[] { 1.0, 1.0, 1.0 },
                new double[] { 2.0, 2.0, 2.0 }
            };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] matrix2 = new double[][] { {3.0, 3.0, 3.0 }, {1.0, 1.0, 1.0 }, {2.0, 2.0, 2.0 } };
            double[][] matrix2 = new double[][]
            {
                new double[] { 3.0, 3.0, 3.0 },
                new double[] { 1.0, 1.0, 1.0 },
                new double[] { 2.0, 2.0, 2.0 }
            };
            const int order = 3;
            const int dim1  = 2;
            const int dim2  = 1;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res1 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, dim1);
            PiecewisePolynomialResult res1 = new PiecewisePolynomialResult(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, dim1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res2 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, dim1);
            PiecewisePolynomialResult res2 = new PiecewisePolynomialResult(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, dim1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res3 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots2), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix2), order, dim2);
            PiecewisePolynomialResult res3 = new PiecewisePolynomialResult(DoubleArray.copyOf(knots2), DoubleMatrix.copyOf(matrix2), order, dim2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res4 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), 2, dim1);
            PiecewisePolynomialResult res4 = new PiecewisePolynomialResult(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), 2, dim1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res5 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, dim1 - 1);
            PiecewisePolynomialResult res5 = new PiecewisePolynomialResult(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, dim1 - 1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult res6 = new PiecewisePolynomialResult(com.opengamma.strata.collect.array.DoubleArray.of(1.0, 2.0, 3.0, 5.0), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, dim1);
            PiecewisePolynomialResult res6 = new PiecewisePolynomialResult(DoubleArray.of(1.0, 2.0, 3.0, 5.0), DoubleMatrix.copyOf(matrix1), order, dim1);

            assertTrue(res1.Equals(res1));

            assertTrue(res1.Equals(res2));
            assertTrue(res2.Equals(res1));
            assertTrue(res2.GetHashCode() == res1.GetHashCode());

            assertTrue(!(res3.GetHashCode() == res1.GetHashCode()));
            assertTrue(!(res1.Equals(res3)));
            assertTrue(!(res3.Equals(res1)));

            assertTrue(!(res4.GetHashCode() == res1.GetHashCode()));
            assertTrue(!(res1.Equals(res4)));
            assertTrue(!(res4.Equals(res1)));

            assertTrue(!(res5.GetHashCode() == res1.GetHashCode()));
            assertTrue(!(res1.Equals(res5)));
            assertTrue(!(res5.Equals(res1)));

            assertTrue(!(res6.GetHashCode() == res1.GetHashCode()));
            assertTrue(!(res1.Equals(res6)));
            assertTrue(!(res6.Equals(res1)));

            assertTrue(!(res1.Equals(null)));
            assertTrue(!(res1.Equals(ANOTHER_TYPE)));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix[] sense1 = new com.opengamma.strata.collect.array.DoubleMatrix[] {com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1)};
            DoubleMatrix[] sense1 = new DoubleMatrix[] { DoubleMatrix.copyOf(matrix1), DoubleMatrix.copyOf(matrix1) };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix[] sense2 = new com.opengamma.strata.collect.array.DoubleMatrix[] {com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1)};
            DoubleMatrix[] sense2 = new DoubleMatrix[] { DoubleMatrix.copyOf(matrix1), DoubleMatrix.copyOf(matrix1), DoubleMatrix.copyOf(matrix1) };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResultsWithSensitivity resSen1 = new PiecewisePolynomialResultsWithSensitivity(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, 1, sense1);
            PiecewisePolynomialResultsWithSensitivity resSen1 = new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResultsWithSensitivity resSen2 = new PiecewisePolynomialResultsWithSensitivity(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, 1, sense1);
            PiecewisePolynomialResultsWithSensitivity resSen2 = new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResultsWithSensitivity resSen3 = new PiecewisePolynomialResultsWithSensitivity(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, 1, sense2);
            PiecewisePolynomialResultsWithSensitivity resSen3 = new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense2);

            assertTrue(resSen1.Equals(resSen1));

            assertTrue(!(resSen1.Equals(ANOTHER_TYPE)));

            assertTrue(!(resSen1.Equals(res5)));

            assertTrue(resSen1.Equals(resSen2));
            assertTrue(resSen2.Equals(resSen1));
            assertTrue(resSen1.GetHashCode() == resSen2.GetHashCode());

            assertTrue(!(resSen1.GetHashCode() == resSen3.GetHashCode()));
            assertTrue(!(resSen1.Equals(resSen3)));
            assertTrue(!(resSen3.Equals(resSen1)));

            try
            {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unused") final PiecewisePolynomialResultsWithSensitivity resSen0 = new PiecewisePolynomialResultsWithSensitivity(com.opengamma.strata.collect.array.DoubleArray.copyOf(knots1), com.opengamma.strata.collect.array.DoubleMatrix.copyOf(matrix1), order, 2, sense1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                PiecewisePolynomialResultsWithSensitivity resSen0 = new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 2, sense1);
                throw new Exception();
            }
            catch (Exception e)
            {
                assertTrue(e is System.NotSupportedException);
            }
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[][] yValuesMatrix)
        public override PiecewisePolynomialResult interpolate(double[] xValues, double[][] yValuesMatrix)
        {
            ArgChecker.notNull(xValues, "xValues");
            ArgChecker.notNull(yValuesMatrix, "yValuesMatrix");

            ArgChecker.isTrue(xValues.Length == yValuesMatrix[0].Length | xValues.Length + 2 == yValuesMatrix[0].Length, "(xValues length = yValuesMatrix's row vector length) or (xValues length + 2 = yValuesMatrix's row vector length)");
            ArgChecker.isTrue(xValues.Length > 2, "Data points should be more than 2");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nDataPts = xValues.length;
            int nDataPts = xValues.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int yValuesLen = yValuesMatrix[0].length;
            int yValuesLen = yValuesMatrix[0].Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int dim = yValuesMatrix.length;
            int dim = yValuesMatrix.Length;

            for (int i = 0; i < nDataPts; ++i)
            {
                ArgChecker.isFalse(double.IsNaN(xValues[i]), "xValues containing NaN");
                ArgChecker.isFalse(double.IsInfinity(xValues[i]), "xValues containing Infinity");
            }
            for (int i = 0; i < yValuesLen; ++i)
            {
                for (int j = 0; j < dim; ++j)
                {
                    ArgChecker.isFalse(double.IsNaN(yValuesMatrix[j][i]), "yValuesMatrix containing NaN");
                    ArgChecker.isFalse(double.IsInfinity(yValuesMatrix[j][i]), "yValuesMatrix containing Infinity");
                }
            }
            for (int i = 0; i < nDataPts; ++i)
            {
                for (int j = i + 1; j < nDataPts; ++j)
                {
                    ArgChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct");
                }
            }

            double[]       xValuesSrt = new double[nDataPts];
            DoubleMatrix[] coefMatrix = new DoubleMatrix[dim];

            for (int i = 0; i < dim; ++i)
            {
                xValuesSrt = Arrays.copyOf(xValues, nDataPts);
                double[] yValuesSrt = new double[nDataPts];
                if (nDataPts == yValuesLen)
                {
                    yValuesSrt = Arrays.copyOf(yValuesMatrix[i], nDataPts);
                }
                else
                {
                    yValuesSrt = Arrays.copyOfRange(yValuesMatrix[i], 1, nDataPts + 1);
                }
                DoubleArrayMath.sortPairs(xValuesSrt, yValuesSrt);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] intervals = _solver.intervalsCalculator(xValuesSrt);
                double[] intervals = _solver.intervalsCalculator(xValuesSrt);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals);
                double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult result = _method.interpolate(xValues, yValuesMatrix[i]);
                PiecewisePolynomialResult result = _method.interpolate(xValues, yValuesMatrix[i]);

                ArgChecker.isTrue(result.Order == 4, "Primary interpolant is not cubic");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] initialFirst = _function.differentiate(result, xValuesSrt).rowArray(0);
                double[] initialFirst = _function.differentiate(result, xValuesSrt).rowArray(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst);
                double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst);

                coefMatrix[i] = DoubleMatrix.copyOf(_solver.solve(yValuesSrt, intervals, slopes, first));
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nIntervals = coefMatrix[0].rowCount();
            int nIntervals = coefMatrix[0].rowCount();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nCoefs = coefMatrix[0].columnCount();
            int nCoefs = coefMatrix[0].columnCount();

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] resMatrix = new double[dim * nIntervals][nCoefs];
            double[][] resMatrix = RectangularArrays.ReturnRectangularDoubleArray(dim * nIntervals, nCoefs);

            for (int i = 0; i < nIntervals; ++i)
            {
                for (int j = 0; j < dim; ++j)
                {
                    resMatrix[dim * i + j] = coefMatrix[j].row(i).toArray();
                }
            }

            for (int i = 0; i < (nIntervals * dim); ++i)
            {
                for (int j = 0; j < nCoefs; ++j)
                {
                    ArgChecker.isFalse(double.IsNaN(resMatrix[i][j]), "Too large input");
                    ArgChecker.isFalse(double.IsInfinity(resMatrix[i][j]), "Too large input");
                }
            }

            return(new PiecewisePolynomialResult(DoubleArray.copyOf(xValuesSrt), DoubleMatrix.copyOf(resMatrix), nCoefs, dim));
        }
        /// <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;
            }
        }
//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)
        {
            ArgChecker.notNull(xValues, "xValues");
            ArgChecker.notNull(yValues, "yValues");

            ArgChecker.isTrue(xValues.Length == yValues.Length | xValues.Length + 2 == yValues.Length, "(xValues length = yValues length) or (xValues length + 2 = yValues length)");
            ArgChecker.isTrue(xValues.Length > 2, "Data points should be more than 2");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nDataPts = xValues.length;
            int nDataPts = xValues.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int yValuesLen = yValues.length;
            int yValuesLen = yValues.Length;

            for (int i = 0; i < nDataPts; ++i)
            {
                ArgChecker.isFalse(double.IsNaN(xValues[i]), "xValues containing NaN");
                ArgChecker.isFalse(double.IsInfinity(xValues[i]), "xValues containing Infinity");
            }
            for (int i = 0; i < yValuesLen; ++i)
            {
                ArgChecker.isFalse(double.IsNaN(yValues[i]), "yValues containing NaN");
                ArgChecker.isFalse(double.IsInfinity(yValues[i]), "yValues containing Infinity");
            }

            for (int i = 0; i < nDataPts - 1; ++i)
            {
                for (int j = i + 1; j < nDataPts; ++j)
                {
                    ArgChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct");
                }
            }

            double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
            double[] yValuesSrt = new double[nDataPts];
            if (nDataPts == yValuesLen)
            {
                yValuesSrt = Arrays.copyOf(yValues, nDataPts);
            }
            else
            {
                yValuesSrt = Arrays.copyOfRange(yValues, 1, nDataPts + 1);
            }
            DoubleArrayMath.sortPairs(xValuesSrt, yValuesSrt);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] intervals = _solver.intervalsCalculator(xValuesSrt);
            double[] intervals = _solver.intervalsCalculator(xValuesSrt);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals);
            double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PiecewisePolynomialResult result = _method.interpolate(xValues, yValues);
            PiecewisePolynomialResult result = _method.interpolate(xValues, yValues);

            ArgChecker.isTrue(result.Order == 4, "Primary interpolant is not cubic");

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] initialFirst = _function.differentiate(result, xValuesSrt).rowArray(0);
            double[] initialFirst = _function.differentiate(result, xValuesSrt).rowArray(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst);
            double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] coefs = _solver.solve(yValuesSrt, intervals, slopes, first);
            double[][] coefs = _solver.solve(yValuesSrt, intervals, slopes, first);

            for (int i = 0; i < nDataPts - 1; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    ArgChecker.isFalse(double.IsNaN(coefs[i][j]), "Too large input");
                    ArgChecker.isFalse(double.IsInfinity(coefs[i][j]), "Too large input");
                }
            }

            return(new PiecewisePolynomialResult(DoubleArray.copyOf(xValuesSrt), DoubleMatrix.copyOf(coefs), 4, 1));
        }