///
        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>
        /// 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;
            }
        }
        ///
        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);
            }
        }
Esempio n. 6
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);
            }
        }
        ///
        public virtual void crossDerivativeTest()
        {
            double[] x0Values = new double[] { 1.0, 2.0, 3.0, 4.0 };
            double[] x1Values = new double[] { -1.0, 0.0, 1.0, 2.0, 3.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n0Data = x0Values.length;
            int n0Data = x0Values.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n1Data = x1Values.length;
            int n1Data = x1Values.Length;

            double[][] yValues = new double[][]
            {
                new double[] { 1.0, -1.0, 0.0, 1.0, 0.0 },
                new double[] { 1.0, -1.0, 0.0, 1.0, -2.0 },
                new double[] { 1.0, -2.0, 0.0, -2.0, -2.0 },
                new double[] { -1.0, -1.0, -2.0, -2.0, -1.0 }
            };

            NaturalSplineInterpolator         method = new NaturalSplineInterpolator();
            PiecewisePolynomialInterpolator2D interp = new BicubicSplineInterpolator(method);
            PiecewisePolynomialResult2D       result = interp.interpolate(x0Values, x1Values, yValues);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n0IntExp = n0Data - 1;
            int n0IntExp = n0Data - 1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n1IntExp = n1Data - 1;
            int       n1IntExp = n1Data - 1;
            const int orderExp = 4;

            const int n0Keys = 51;
            const int n1Keys = 61;

            double[] x0Keys = new double[n0Keys];
            double[] x1Keys = new double[n1Keys];
            for (int i = 0; i < n0Keys; ++i)
            {
                x0Keys[i] = 0.0 + 5.0 * i / (n0Keys - 1);
            }
            for (int i = 0; i < n1Keys; ++i)
            {
                x1Keys[i] = -2.0 + 6.0 * i / (n1Keys - 1);
            }

            assertEquals(result.NumberOfIntervals[0], n0IntExp);
            assertEquals(result.NumberOfIntervals[1], n1IntExp);
            assertEquals(result.Order[0], orderExp);
            assertEquals(result.Order[1], orderExp);

            for (int i = 0; i < n0Data; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(x0Values[i]) == 0.0 ? 1.0 : Math.abs(x0Values[i]);
                double @ref = Math.Abs(x0Values[i]) == 0.0 ? 1.0 : Math.Abs(x0Values[i]);
                assertEquals(result.Knots0.get(i), x0Values[i], @ref * EPS);
                assertEquals(result.Knots2D[0].get(i), x0Values[i], @ref * EPS);
            }
            for (int i = 0; i < n1Data; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(x1Values[i]) == 0.0 ? 1.0 : Math.abs(x1Values[i]);
                double @ref = Math.Abs(x1Values[i]) == 0.0 ? 1.0 : Math.Abs(x1Values[i]);
                assertEquals(result.Knots1.get(i), x1Values[i], @ref * EPS);
                assertEquals(result.Knots2D[1].get(i), x1Values[i], @ref * EPS);
            }

            for (int i = 0; i < n0Data - 1; ++i)
            {
                for (int j = 0; j < n1Data - 1; ++j)
                {
                    double @ref = Math.Abs(yValues[i][j]) == 0.0 ? 1.0 : Math.Abs(yValues[i][j]);
                    assertEquals(result.Coefs[i][j].get(orderExp - 1, orderExp - 1), yValues[i][j], @ref * EPS);
                }
            }

            DoubleMatrix resValues = interp.interpolate(x0Values, x1Values, yValues, x0Values, x1Values);
            PiecewisePolynomialFunction2D func2D = new PiecewisePolynomialFunction2D();
            DoubleMatrix resDiffX0 = func2D.differentiateX0(result, x0Values, x1Values);
            DoubleMatrix resDiffX1 = func2D.differentiateX1(result, x0Values, x1Values);

            PiecewisePolynomialFunction1D func1D = new PiecewisePolynomialFunction1D();
            DoubleMatrix expDiffX0 = func1D.differentiate(method.interpolate(x0Values, OG_ALGEBRA.getTranspose(DoubleMatrix.copyOf(yValues)).toArray()), x0Values);
            DoubleMatrix expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values);

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
                    double expVal = expDiffX1.get(i, j);
                    double @ref   = Math.Abs(expVal) == 0.0 ? 1.0 : Math.Abs(expVal);
                    assertEquals(resDiffX1.get(i, j), expVal, @ref * EPS);
                }
            }

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
                    double expVal = expDiffX0.get(j, i);
                    double @ref   = Math.Abs(expVal) == 0.0 ? 1.0 : Math.Abs(expVal);
                    assertEquals(resDiffX0.get(i, j), expVal, @ref * EPS);
                }
            }

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
                    double expVal = yValues[i][j];
                    double @ref   = Math.Abs(expVal) == 0.0 ? 1.0 : Math.Abs(expVal);
                    assertEquals(resValues.get(i, j), expVal, @ref * EPS);
                }
            }
        }
        /// <summary>
        /// f(x0,x1) = ( x0 - 1.)^3 * (x1  + 14./13.)^3
        /// </summary>
        public virtual void cubicTest()
        {
            double[] x0Values = new double[] { 1.0, 2.0, 3.0, 4.0 };
            double[] x1Values = new double[] { -1.0, 0.0, 1.0, 2.0, 3.0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n0Data = x0Values.length;
            int n0Data = x0Values.Length;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n1Data = x1Values.length;
            int n1Data = x1Values.Length;

//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[n0Data][n1Data];
            double[][] yValues = RectangularArrays.ReturnRectangularDoubleArray(n0Data, n1Data);

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
                    yValues[i][j] = (x0Values[i] - 1.0) * (x0Values[i] - 1.0) * (x0Values[i] - 1.0) * (x1Values[j] + 14.0 / 13.0) * (x1Values[j] + 14.0 / 13.0) * (x1Values[j] + 14.0 / 13.0);
                }
            }

            CubicSplineInterpolator           method = new CubicSplineInterpolator();
            PiecewisePolynomialInterpolator2D interp = new BicubicSplineInterpolator(method);
            PiecewisePolynomialResult2D       result = interp.interpolate(x0Values, x1Values, yValues);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n0IntExp = n0Data - 1;
            int n0IntExp = n0Data - 1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n1IntExp = n1Data - 1;
            int       n1IntExp = n1Data - 1;
            const int orderExp = 4;

            const int n0Keys = 51;
            const int n1Keys = 61;

            double[] x0Keys = new double[n0Keys];
            double[] x1Keys = new double[n1Keys];
            for (int i = 0; i < n0Keys; ++i)
            {
                x0Keys[i] = 0.0 + 5.0 * i / (n0Keys - 1);
            }
            for (int i = 0; i < n1Keys; ++i)
            {
                x1Keys[i] = -2.0 + 6.0 * i / (n1Keys - 1);
            }

            assertEquals(result.NumberOfIntervals[0], n0IntExp);
            assertEquals(result.NumberOfIntervals[1], n1IntExp);
            assertEquals(result.Order[0], orderExp);
            assertEquals(result.Order[1], orderExp);

            for (int i = 0; i < n0Data; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(x0Values[i]) == 0.0 ? 1.0 : Math.abs(x0Values[i]);
                double @ref = Math.Abs(x0Values[i]) == 0.0 ? 1.0 : Math.Abs(x0Values[i]);
                assertEquals(result.Knots0.get(i), x0Values[i], @ref * EPS);
                assertEquals(result.Knots2D[0].get(i), x0Values[i], @ref * EPS);
            }
            for (int i = 0; i < n1Data; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(x1Values[i]) == 0.0 ? 1.0 : Math.abs(x1Values[i]);
                double @ref = Math.Abs(x1Values[i]) == 0.0 ? 1.0 : Math.Abs(x1Values[i]);
                assertEquals(result.Knots1.get(i), x1Values[i], @ref * EPS);
                assertEquals(result.Knots2D[1].get(i), x1Values[i], @ref * EPS);
            }

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

            DoubleMatrix resValues = interp.interpolate(x0Values, x1Values, yValues, x0Values, x1Values);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction2D func2D = new com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction2D();
            PiecewisePolynomialFunction2D func2D = new PiecewisePolynomialFunction2D();
            DoubleMatrix resDiffX0 = func2D.differentiateX0(result, x0Values, x1Values);
            DoubleMatrix resDiffX1 = func2D.differentiateX1(result, x0Values, x1Values);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction1D func1D = new com.opengamma.strata.math.impl.function.PiecewisePolynomialFunction1D();
            PiecewisePolynomialFunction1D func1D = new PiecewisePolynomialFunction1D();
            DoubleMatrix expDiffX0 = func1D.differentiate(method.interpolate(x0Values, OG_ALGEBRA.getTranspose(DoubleMatrix.copyOf(yValues)).toArray()), x0Values);
            DoubleMatrix expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values);

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double expVal = expDiffX1.get(i, j);
                    double expVal = expDiffX1.get(i, j);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(expVal) == 0.0 ? 1.0 : Math.abs(expVal);
                    double @ref = Math.Abs(expVal) == 0.0 ? 1.0 : Math.Abs(expVal);
                    assertEquals(resDiffX1.get(i, j), expVal, @ref * EPS);
                }
            }

            for (int i = 0; i < n0Data; ++i)
            {
                for (int j = 0; j < n1Data; ++j)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double expVal = expDiffX0.get(j, i);
                    double expVal = expDiffX0.get(j, i);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double ref = Math.abs(expVal) == 0.0 ? 1.0 : Math.abs(expVal);
                    double @ref = Math.Abs(expVal) == 0.0 ? 1.0 : Math.Abs(expVal);
                    assertEquals(resDiffX0.get(i, j), expVal, @ref * EPS);
                }
            }

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