Class CubicSplineNakSolver
- java.lang.Object
-
- com.opengamma.strata.math.impl.interpolation.CubicSplineNakSolver
-
public class CubicSplineNakSolver extends Object
Solves cubic spline problem with Not-A-Knot endpoint conditions, where the third derivative at the endpoints is the same as that of their adjacent points.
-
-
Constructor Summary
Constructors Constructor Description CubicSplineNakSolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DoubleArray[]
combinedMatrixEqnSolver(double[][] doubMat1, double[] doubVec, double[][] doubMat2)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matricesprotected DoubleMatrix[]
getCommonCoefficientWithSensitivity(double[] xValues, double[] yValues, double[] intervals, double[][] toBeInv, double[] commonVector, double[][] commonVecSensitivity)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matricesprotected double[][]
getCommonMatrixElements(double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vectorprotected DoubleMatrix[]
getCommonSensitivityCoeffs(double[] intervals, double[][] solnMatrix)
protected DoubleMatrix
getCommonSplineCoeffs(double[] xValues, double[] yValues, double[] intervals, double[] solnVector)
protected double[]
getCommonVectorElements(double[] yValues, double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vectorprotected double[][]
getCommonVectorSensitivity(double[] intervals)
Node sensitivity is obtained by solving a linear problem AN = L where A,N,L are matricesprotected double[]
getDiffs(double[] xValues)
DoubleArray
getKnotsMat1D(double[] xValues)
protected double[]
matrixEqnSolver(double[][] doubMat, double[] doubVec)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector This can be done by LU decompositionDoubleMatrix
solve(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are usedDoubleMatrix[]
solveMultiDim(double[] xValues, DoubleMatrix yValuesMatrix)
Multi-dimensional cubic spline If (xValues length) = (yValuesMatrix NumberOfColumn), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValuesMatrix NumberOfColumn), Clamped endpoint conditions are usedDoubleMatrix[]
solveWithSensitivity(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used
-
-
-
Method Detail
-
solve
public DoubleMatrix solve(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used- Parameters:
xValues
- X values of datayValues
- Y values of data- Returns:
- Coefficient matrix whose i-th row vector is (a_0,a_1,...) for i-th intervals, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + .... Note that the degree of polynomial is NOT necessarily 3
-
solveWithSensitivity
public DoubleMatrix[] solveWithSensitivity(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used- Parameters:
xValues
- X values of datayValues
- Y values of data- Returns:
- Array of matrices: the 0-th element is Coefficient Matrix (same as the solve method above), the i-th element is \frac{\partial a^{i-1}_j}{\partial yValues_k} where a_0^i,a_1^i,... are coefficients of f^i(x) = a_0^i + a_1^i (x - xValues_{i}) + .... with x \in [xValues_{i}, xValues_{i+1}]
-
solveMultiDim
public DoubleMatrix[] solveMultiDim(double[] xValues, DoubleMatrix yValuesMatrix)
Multi-dimensional cubic spline If (xValues length) = (yValuesMatrix NumberOfColumn), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValuesMatrix NumberOfColumn), Clamped endpoint conditions are used- Parameters:
xValues
- X values of datayValuesMatrix
- Y values of data, where NumberOfRow defines dimension of the spline- Returns:
- A set of coefficient matrices whose i-th row vector is (a_0,a_1,...) for the i-th interval, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + .... Each matrix corresponds to an interpolation (xValues, yValuesMatrix RowVector) Note that the degree of polynomial is NOT necessarily 3
-
getKnotsMat1D
public DoubleArray getKnotsMat1D(double[] xValues)
- Parameters:
xValues
- X values of data- Returns:
- X values of knots (Note that these are NOT necessarily xValues if nDataPts=2,3)
-
getDiffs
protected double[] getDiffs(double[] xValues)
- Parameters:
xValues
- X values of Data- Returns:
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...} xValues (and corresponding yValues) should be sorted before calling this method
-
getCommonSplineCoeffs
protected DoubleMatrix getCommonSplineCoeffs(double[] xValues, double[] yValues, double[] intervals, double[] solnVector)
- Parameters:
xValues
- X values of DatayValues
- Y values of Dataintervals
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...}solnVector
- Values of second derivative at knots- Returns:
- Coefficient matrix whose i-th row vector is {a_0,a_1,...} for i-th intervals, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + ....
-
getCommonSensitivityCoeffs
protected DoubleMatrix[] getCommonSensitivityCoeffs(double[] intervals, double[][] solnMatrix)
- Parameters:
intervals
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...}solnMatrix
- Sensitivity of second derivatives (x 0.5)- Returns:
- Array of i coefficient matrices \frac{\partial a^i_j}{\partial y_k}
-
getCommonCoefficientWithSensitivity
protected DoubleMatrix[] getCommonCoefficientWithSensitivity(double[] xValues, double[] yValues, double[] intervals, double[][] toBeInv, double[] commonVector, double[][] commonVecSensitivity)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices- Parameters:
xValues
- X values of datayValues
- Y values of dataintervals
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...}toBeInv
- The matrix AcommonVector
- The vector bcommonVecSensitivity
- The matrix L- Returns:
- Coefficient matrices of interpolant (x) and its node sensitivity (N)
-
getCommonMatrixElements
protected double[][] getCommonMatrixElements(double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector- Parameters:
intervals
- the intervals- Returns:
- Endpoint-independent part of the matrix A
-
getCommonVectorElements
protected double[] getCommonVectorElements(double[] yValues, double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector- Parameters:
yValues
- Y values of Dataintervals
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...}- Returns:
- Endpoint-independent part of vector b
-
getCommonVectorSensitivity
protected double[][] getCommonVectorSensitivity(double[] intervals)
Node sensitivity is obtained by solving a linear problem AN = L where A,N,L are matrices- Parameters:
intervals
- {xValues[1]-xValues[0], xValues[2]-xValues[1],...}- Returns:
- The matrix L
-
matrixEqnSolver
protected double[] matrixEqnSolver(double[][] doubMat, double[] doubVec)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector This can be done by LU decomposition- Parameters:
doubMat
- Matrix AdoubVec
- Vector B- Returns:
- Solution to the linear equation, x
-
combinedMatrixEqnSolver
protected DoubleArray[] combinedMatrixEqnSolver(double[][] doubMat1, double[] doubVec, double[][] doubMat2)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices- Parameters:
doubMat1
- The matrix AdoubVec
- The vector bdoubMat2
- The matrix L- Returns:
- The solutions to the linear systems, x,N
-
-