public override PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(double[] xValues, double[] yValues)
 {
     ArgChecker.notNull(xValues, "xValues");
     ArgChecker.notNull(yValues, "yValues");
     ArgChecker.isTrue(xValues.Length == yValues.Length, "xValues length = yValues length");
     double[][] xyValuesAll = getDataTotal(xValues, yValues);
     return(_baseMethod.interpolateWithSensitivity(xyValuesAll[0], xyValuesAll[1]));
 }
Exemple #2
0
        public override PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(double[] xValues, double[] yValues)
        {
            ArgChecker.notNull(xValues, "xValues");
            ArgChecker.notNull(yValues, "yValues");
            ArgChecker.isTrue(xValues.Length == yValues.Length, "xValues length = yValues length");
            PiecewisePolynomialResultsWithSensitivity result;

            if (_isClamped)
            {
                double[][] xyValuesAll = getDataTotal(xValues, yValues);
                result = _baseMethod.interpolateWithSensitivity(xyValuesAll[0], xyValuesAll[1]);
            }
            else
            {
                double[] xyValues = getProduct(xValues, yValues);
                result = _baseMethod.interpolateWithSensitivity(xValues, xyValues);
            }
            return((PiecewisePolynomialResultsWithSensitivity)extrapolateByLinearFunction(result, xValues));
        }
//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));
        }