public virtual void sensitivityTest()
        {
//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;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nData = X.length;
            int nData = X.Length;

            for (int example = 0; example < nExamples; example++)
            {
                PiecewisePolynomialResultsWithSensitivity pp = PCHIP_S.interpolateWithSensitivity(X, Y[example]);

                DoubleArray[] fdRes = fdSenseCal(X, Y[example], XX);

                for (int i = 0; i < n; i++)
                {
                    DoubleArray res = PPVAL_S.nodeSensitivity(pp, XX[i]);
                    for (int j = 0; j < nData; j++)
                    {
                        assertEquals("example: " + example + ", sample: " + i + ", node: " + j, fdRes[j].get(i), res.get(j), 1e-4);
                    }
                }
            }
        }
Beispiel #2
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);
                    }
                }
            }
        }
 public virtual void testInterpolateWithSensitivity()
 {
     foreach (PiecewisePolynomialInterpolator baseInterp in BASE_INTERP)
     {
         ClampedPiecewisePolynomialInterpolator    interp   = new ClampedPiecewisePolynomialInterpolator(baseInterp, X_CLAMPED, Y_CLAMPED);
         PiecewisePolynomialResultsWithSensitivity computed = interp.interpolateWithSensitivity(X_VALUES, Y_VALUES);
         PiecewisePolynomialResultsWithSensitivity expected = baseInterp.interpolateWithSensitivity(X_VALUES_TOTAL, Y_VALUES_TOTAL);
         assertEquals(computed, expected);
     }
 }
Beispiel #4
0
        /// <summary>
        /// No clamped points added
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void notClampedTest()
        public virtual void notClampedTest()
        {
            double[][] xValuesSet = new double[][]
            {
                new double[] { -5.0, -1.4, 3.2, 3.5, 7.6 },
                new double[] { 1.0, 2.0, 4.5, 12.1, 14.2 },
                new double[] { -5.2, -3.4, -3.2, -0.9, -0.2 }
            };
            double[][] yValuesSet = new double[][]
            {
                new double[] { -2.2, 1.1, 1.9, 2.3, -0.1 },
                new double[] { 3.4, 5.2, 4.3, 1.1, 0.2 },
                new double[] { 1.4, 2.2, 4.1, 1.9, 0.99 }
            };

            for (int k = 0; k < xValuesSet.Length; ++k)
            {
                double[] xValues  = Arrays.copyOf(xValuesSet[k], xValuesSet[k].Length);
                double[] yValues  = Arrays.copyOf(yValuesSet[k], yValuesSet[k].Length);
                int      nData    = xValues.Length;
                double[] xyValues = new double[nData];
                for (int j = 0; j < nData; ++j)
                {
                    xyValues[j] = xValues[j] * yValues[j];
                }
                int    nKeys    = 100;
                double interval = (xValues[nData - 1] - xValues[0]) / (nKeys - 1.0);

                int n = INTERP.Length;
                for (int i = 0; i < n; ++i)
                {
                    ProductPiecewisePolynomialInterpolator interp = new ProductPiecewisePolynomialInterpolator(INTERP[i]);
                    for (int j = 0; j < nKeys; ++j)
                    {
                        double key = xValues[0] + interval * j;
                        InterpolatorTestUtil.assertRelative("notClampedTest", INTERP[i].interpolate(xValues, xyValues, key), interp.interpolate(xValues, yValues, key), 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);
                    PiecewisePolynomialResultsWithSensitivity resultBase = INTERP_SENSE[i].interpolateWithSensitivity(xValues, xyValues);
                    for (int j = 0; j < nKeys; ++j)
                    {
                        double key = xValues[0] + interval * j;
                        InterpolatorTestUtil.assertRelative("notClampedTest", FUNC.evaluate(resultBase, key).get(0), FUNC.evaluate(result, key).get(0), EPS);
                        InterpolatorTestUtil.assertArrayRelative("notClampedTest", FUNC.nodeSensitivity(resultBase, key).toArray(), FUNC.nodeSensitivity(result, key).toArray(), EPS);
                    }
                }
            }
        }
        public virtual void sensitivityTwoNodeTest()
        {
            int n = XX.Length;

            double[] xValues = new double[] { -0.2, 3.63 };
            double[] yValues = new double[] { 4.67, -1.22 };
            PiecewisePolynomialResultsWithSensitivity pp = PCHIP_S.interpolateWithSensitivity(xValues, yValues);

            DoubleArray[] fdRes = fdSenseCal(xValues, yValues, XX);
            for (int i = 0; i < n; i++)
            {
                DoubleArray res = PPVAL_S.nodeSensitivity(pp, XX[i]);
                for (int j = 0; j < 2; j++)
                {
                    assertEquals(fdRes[j].get(i), res.get(j), 1e-4);
                }
            }
        }
Beispiel #6
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);
        }
Beispiel #7
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 override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (!(obj is PiecewisePolynomialResultsWithSensitivity))
            {
                return(false);
            }
            PiecewisePolynomialResultsWithSensitivity other = (PiecewisePolynomialResultsWithSensitivity)obj;

            if (!Arrays.Equals(_coeffSense, other._coeffSense))
            {
                return(false);
            }
            return(true);
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Clamped points
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void clampedTest()
        public virtual void clampedTest()
        {
            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 };
            double[][] xValuesClampedSet = new double[][]
            {
                new double[] { 0.0 },
                new double[] { -7.2, -2.5, 8.45 },
                new double[] {}
            };
            double[][] yValuesClampedSet = new double[][]
            {
                new double[] { 0.0 },
                new double[] { -1.2, -1.4, 2.2 },
                new double[] {}
            };

            for (int k = 0; k < xValuesClampedSet.Length; ++k)
            {
                double[] xValuesClamped = Arrays.copyOf(xValuesClampedSet[k], xValuesClampedSet[k].Length);
                double[] yValuesClamped = Arrays.copyOf(yValuesClampedSet[k], yValuesClampedSet[k].Length);
                int      nData          = xValues.Length;
                int      nClamped       = xValuesClamped.Length;
                int      nTotal         = nData + nClamped;
                double[] xValuesForBase = new double[nTotal];
                double[] yValuesForBase = new double[nTotal];
                Array.Copy(xValues, 0, xValuesForBase, 0, nData);
                Array.Copy(yValues, 0, yValuesForBase, 0, nData);
                Array.Copy(xValuesClamped, 0, xValuesForBase, nData, nClamped);
                Array.Copy(yValuesClamped, 0, yValuesForBase, nData, nClamped);
                DoubleArrayMath.sortPairs(xValuesForBase, yValuesForBase);

                double[] xyValuesBase = new double[nTotal];
                for (int j = 0; j < nTotal; ++j)
                {
                    xyValuesBase[j] = xValuesForBase[j] * yValuesForBase[j];
                }
                int    nKeys    = 100;
                double interval = (xValues[nData - 1] - xValues[0]) / (nKeys - 1.0);

                int n = INTERP.Length;
                for (int i = 0; i < n; ++i)
                {
                    ProductPiecewisePolynomialInterpolator interp = new ProductPiecewisePolynomialInterpolator(INTERP[i], xValuesClamped, yValuesClamped);
                    for (int j = 0; j < nKeys; ++j)
                    {
                        double key = xValues[0] + interval * j;
                        InterpolatorTestUtil.assertRelative("clampedTest", INTERP[i].interpolate(xValuesForBase, xyValuesBase, key), interp.interpolate(xValues, yValues, key), EPS);
                    }
                }
                n = INTERP_SENSE.Length;
                for (int i = 0; i < n; ++i)
                {
                    ProductPiecewisePolynomialInterpolator    interp     = new ProductPiecewisePolynomialInterpolator(INTERP_SENSE[i], xValuesClamped, yValuesClamped);
                    PiecewisePolynomialResultsWithSensitivity result     = interp.interpolateWithSensitivity(xValues, yValues);
                    PiecewisePolynomialResultsWithSensitivity resultBase = INTERP_SENSE[i].interpolateWithSensitivity(xValuesForBase, xyValuesBase);
                    for (int j = 0; j < nKeys; ++j)
                    {
                        double key = xValues[0] + interval * j;
                        InterpolatorTestUtil.assertRelative("clampedTest", FUNC.evaluate(resultBase, key).get(0), FUNC.evaluate(result, key).get(0), EPS);
                        InterpolatorTestUtil.assertArrayRelative("clampedTest", FUNC.nodeSensitivity(resultBase, key).toArray(), FUNC.nodeSensitivity(result, key).toArray(), EPS);
                    }
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues, final double[] yValues)
        public override PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(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[] yValuesSrt = new double[nDataPts];
            if (nDataPts == yValuesLen)
            {
                yValuesSrt = Arrays.copyOf(yValues, nDataPts);
            }
            else
            {
                yValuesSrt = Arrays.copyOfRange(yValues, 1, nDataPts + 1);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[] intervals = _solver.intervalsCalculator(xValues);
            double[] intervals = _solver.intervalsCalculator(xValues);
//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 PiecewisePolynomialResultsWithSensitivity resultWithSensitivity = _method.interpolateWithSensitivity(xValues, yValues);
            PiecewisePolynomialResultsWithSensitivity resultWithSensitivity = _method.interpolateWithSensitivity(xValues, yValues);

            ArgChecker.isTrue(resultWithSensitivity.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(resultWithSensitivity, xValues).rowArray(0);
            double[] initialFirst = _function.differentiate(resultWithSensitivity, xValues).rowArray(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double[][] slopeSensitivity = _solver.slopeSensitivityCalculator(intervals);
            double[][] slopeSensitivity = _solver.slopeSensitivityCalculator(intervals);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray[] initialFirstSense = _function.differentiateNodeSensitivity(resultWithSensitivity, xValues);
            DoubleArray[] initialFirstSense = _function.differentiateNodeSensitivity(resultWithSensitivity, xValues);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray[] firstWithSensitivity = firstDerivativeWithSensitivityCalculator(yValuesSrt, intervals, initialFirst, initialFirstSense);
            DoubleArray[] firstWithSensitivity = firstDerivativeWithSensitivityCalculator(yValuesSrt, intervals, initialFirst, initialFirstSense);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix[] resMatrix = _solver.solveWithSensitivity(yValuesSrt, intervals, slopes, slopeSensitivity, firstWithSensitivity);
            DoubleMatrix[] resMatrix = _solver.solveWithSensitivity(yValuesSrt, intervals, slopes, slopeSensitivity, firstWithSensitivity);

            for (int k = 0; k < nDataPts; k++)
            {
                DoubleMatrix m = resMatrix[k];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int rows = m.rowCount();
                int rows = m.rowCount();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int cols = m.columnCount();
                int cols = m.columnCount();
                for (int i = 0; i < rows; ++i)
                {
                    for (int j = 0; j < cols; ++j)
                    {
                        ArgChecker.isTrue(Doubles.isFinite(m.get(i, j)), "Matrix contains a NaN or infinite");
                    }
                }
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix coefMatrix = resMatrix[0];
            DoubleMatrix coefMatrix = resMatrix[0];

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix[] coefSenseMatrix = new com.opengamma.strata.collect.array.DoubleMatrix[nDataPts - 1];
            DoubleMatrix[] coefSenseMatrix = new DoubleMatrix[nDataPts - 1];
            Array.Copy(resMatrix, 1, coefSenseMatrix, 0, nDataPts - 1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nCoefs = coefMatrix.columnCount();
            int nCoefs = coefMatrix.columnCount();

            return(new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix));
        }