/// <summary> /// Finds the node sensitivity. /// </summary> /// <param name="pp"> the <seealso cref="PiecewisePolynomialResultsWithSensitivity"/> </param> /// <param name="xKey"> the key </param> /// <returns> Node sensitivity value at x=xKey </returns> public virtual DoubleArray nodeSensitivity(PiecewisePolynomialResultsWithSensitivity pp, double xKey) { ArgChecker.notNull(pp, "null pp"); ArgChecker.isFalse(double.IsNaN(xKey), "xKey containing NaN"); ArgChecker.isFalse(double.IsInfinity(xKey), "xKey containing Infinity"); if (pp.Dimensions > 1) { throw new System.NotSupportedException(); } DoubleArray knots = pp.Knots; int nKnots = knots.size(); int interval = FunctionUtils.getLowerBoundIndex(knots, xKey); if (interval == nKnots - 1) { interval--; // there is 1 less interval that knots } double s = xKey - knots.get(interval); DoubleMatrix a = pp.getCoefficientSensitivity(interval); int nCoefs = a.rowCount(); DoubleArray res = a.row(0); for (int i = 1; i < nCoefs; i++) { res = (DoubleArray)MA.scale(res, s); res = (DoubleArray)MA.add(res, a.row(i)); } return(res); }
/// <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)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: @Override public com.opengamma.strata.collect.array.DoubleMatrix[] solveMultiDim(final double[] xValues, final com.opengamma.strata.collect.array.DoubleMatrix yValuesMatrix) public override DoubleMatrix[] solveMultiDim(double[] xValues, DoubleMatrix yValuesMatrix) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int dim = yValuesMatrix.rowCount(); int dim = yValuesMatrix.rowCount(); DoubleMatrix[] coefMatrix = new DoubleMatrix[dim]; for (int i = 0; i < dim; ++i) { coefMatrix[i] = solve(xValues, yValuesMatrix.row(i).toArray()); } return(coefMatrix); }
/// <summary> /// Evaluates the function. /// </summary> /// <param name="pp"> the PiecewisePolynomialResult </param> /// <param name="xKeys"> the key </param> /// <returns> the values of piecewise polynomial functions at xKeys /// When _dim in PiecewisePolynomialResult is greater than 1, i.e., the struct contains /// multiple piecewise polynomials, a row vector of return value corresponds to each piecewise polynomial </returns> public virtual DoubleMatrix evaluate(PiecewisePolynomialResult pp, double[] xKeys) { ArgChecker.notNull(pp, "pp"); ArgChecker.notNull(xKeys, "xKeys"); 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"); } DoubleArray knots = pp.Knots; int nKnots = knots.size(); DoubleMatrix coefMatrix = pp.CoefMatrix; int dim = pp.Dimensions; //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[][] res = new double[dim][keyLength]; double[][] res = RectangularArrays.ReturnRectangularDoubleArray(dim, keyLength); for (int k = 0; k < dim; ++k) { 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; } } } DoubleArray coefs = coefMatrix.row(dim * indicator + k); res[k][j] = getValue(coefs, xKeys[j], knots.get(indicator)); ArgChecker.isFalse(double.IsInfinity(res[k][j]), "Too large input"); ArgChecker.isFalse(double.IsNaN(res[k][j]), "Too large input"); } } return(DoubleMatrix.copyOf(res)); }
/// <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> /// Evaluates the function. /// </summary> /// <param name="pp"> the PiecewisePolynomialResult </param> /// <param name="xKey"> the key </param> /// <returns> the values of piecewise polynomial functions at xKey /// When _dim in PiecewisePolynomialResult is greater than 1, i.e., the struct contains /// multiple splines, an element in the return values corresponds to each spline </returns> public virtual DoubleArray evaluate(PiecewisePolynomialResult pp, double xKey) { ArgChecker.notNull(pp, "pp"); ArgChecker.isFalse(double.IsNaN(xKey), "xKey containing NaN"); ArgChecker.isFalse(double.IsInfinity(xKey), "xKey containing Infinity"); DoubleArray knots = pp.Knots; int nKnots = knots.size(); DoubleMatrix coefMatrix = pp.CoefMatrix; // check for 1 less interval that knots int lowerBound = FunctionUtils.getLowerBoundIndex(knots, xKey); int indicator = lowerBound == nKnots - 1 ? lowerBound - 1 : lowerBound; return(DoubleArray.of(pp.Dimensions, i => { DoubleArray coefs = coefMatrix.row(pp.Dimensions * indicator + i); double 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; })); }