From 095f50f057f09bd437f7c60b4a67a9f3810b8193 Mon Sep 17 00:00:00 2001 From: Lakshmi Krishnamurthy Date: Tue, 25 Jun 2024 22:06:31 -0400 Subject: [PATCH] Features: - Ryabenkii Tsynkov U Solution Array (5, 6) - Ryabenkii Tsynkov V Solution Array (9, 10) - Ryabenkii Tsynkov x1 Calculation #1 (11, 12) - Ryabenkii Tsynkov x1 Calculation #2 (13, 14) - Ryabenkii Tsynkov UV Solution #1 (15, 16) - Ryabenkii Tsynkov UV Solution #2 (17, 18, 19) - Sherman-Morrison Tridiagonal Periodic Solver (24, 25) - Sherman-Morrison Solver Square Matrix (26, 27) - Sherman-Morrison Solver RHS Matrix (28, 29) - Sherman-Morrison Solver Default Gamma (30) - Sherman-Morrison Tridiagonal Solver Gamma (31, 32) - Sherman-Morrison Tridiagonal Solver Constructor (33, 34, 35) - Sherman-Morrison Batista-Karawia Gamma (36) - Sherman-Morrison Batista-Karawia #1 (37, 38) - Sherman-Morrison Batista-Karawia #2 (39, 40) - Sherman-Morrison U RHS Array (45, 46, 47) - Sherman-Morrison V RHS Array (50, 51, 52) - Sherman-Morrison U Solution Array (55, 56) - Sherman-Morrison V Solution Array (57, 58) - Sherman-Morrison Q Solution Array (65, 66) - Sherman-Morrison Y Solution (67) - Sherman-Morrison Q Y #1 (70, 71, 72) - Sherman-Morrison Q Y #2 (73, 74, 75) - Standard Sherman-Morrison Tridiagonal Solver (99, 100, 101) - Sherman-Morrison Batista-Karawia #1 (102, 103) - Sherman-Morrison Batista-Karawia #2 (104, 105) - Ryabenkii Tsynkov UV Solution Robustness (112, 113) - Forward Sweep Back Substitution Robustness (116) Bug Fixes/Re-organization: - Ryabenkii Tsynkov V Array Fix (4) - Ryabenkii Tsynkov UV Array Fix (23) - RHS V Solution Array Fix (63, 64) - Sherman Morrison Batista-Karawia B (90, 91) - Regular/Periodic Tridiagonal Solver Schemes (115) Samples: - Ryabenkii Tsynkov Tridiagonal Run #1 (1, 2, 3) - Ryabenkii Tsynkov Tridiagonal Run #2 (7, 8) - Ryabenkii Tsynkov Tridiagonal Run #3 (11, 12) - Ryabenkii Tsynkov Tridiagonal Run #4 (20, 21, 22) - Batista-Karawia Tridiagonal Periodic #1 (41, 42) - Batista-Karawia Tridiagonal Periodic #2 (43, 44) - Batista-Karawia Tridiagonal Periodic #3 (48, 49) - Batista-Karawia Tridiagonal Periodic #4 (53, 54) - Batista-Karawia Tridiagonal Periodic #5 (59, 60) - Batista-Karawia Tridiagonal Periodic #6 (61, 62) - Batista-Karawia Tridiagonal Periodic #7 (68, 69) - Batista-Karawia Tridiagonal Periodic #8 (76, 77) - Batista-Karawia Tridiagonal Periodic #9 (78, 79) - Batista-Karawia Tridiagonal Periodic #10 (80, 81, 82) - Batista-Karawia Tridiagonal Periodic #11 (83, 84) - Batista-Karawia Tridiagonal Periodic #12 (85, 86) - Batista-Karawia Tridiagonal Periodic #13 (87, 88, 89) - Batista-Karawia Tridiagonal Periodic #14 (92, 93, 94) - Batista-Karawia Tridiagonal Periodic #15 (95, 96, 97) - Batista-Karawia Tridiagonal Periodic #16 (98) - Batista-Karawia Tridiagonal Periodic #17 (106, 107, 108) - Batista-Karawia Tridiagonal Periodic #18 (109, 110, 111) - Ryabenkii Tsynkov Tridiagonal Run #5 (114) - Forward Sweep Back Substitution Run (117) - Non-period Tridiagonal Solver Shell (118, 119, 120) IdeaDRIP: --- ReleaseNotes/01_17_2024.txt | 72 +++ .../linearalgebra/RyabenkiiTsynkovSolver.java | 111 ++++- .../linearalgebra/ShermanMorrisonSolver.java | 457 ++++++++++++++++++ .../linearalgebra/TridiagonalSolver.java | 11 +- .../sample/tridiagonal/NonPeriodicSolver.java | 119 +++++ .../drip/sample/tridiagonal/package-info.java | 8 + 6 files changed, 774 insertions(+), 4 deletions(-) create mode 100644 ReleaseNotes/01_17_2024.txt create mode 100644 src/main/java/org/drip/numerical/linearalgebra/ShermanMorrisonSolver.java create mode 100644 src/main/java/org/drip/sample/tridiagonal/NonPeriodicSolver.java create mode 100644 src/main/java/org/drip/sample/tridiagonal/package-info.java diff --git a/ReleaseNotes/01_17_2024.txt b/ReleaseNotes/01_17_2024.txt new file mode 100644 index 00000000000..a4f63954db6 --- /dev/null +++ b/ReleaseNotes/01_17_2024.txt @@ -0,0 +1,72 @@ + +Features: + + - Ryabenkii Tsynkov U Solution Array (5, 6) + - Ryabenkii Tsynkov V Solution Array (9, 10) + - Ryabenkii Tsynkov x1 Calculation #1 (11, 12) + - Ryabenkii Tsynkov x1 Calculation #2 (13, 14) + - Ryabenkii Tsynkov UV Solution #1 (15, 16) + - Ryabenkii Tsynkov UV Solution #2 (17, 18, 19) + - Sherman-Morrison Tridiagonal Periodic Solver (24, 25) + - Sherman-Morrison Solver Square Matrix (26, 27) + - Sherman-Morrison Solver RHS Matrix (28, 29) + - Sherman-Morrison Solver Default Gamma (30) + - Sherman-Morrison Tridiagonal Solver Gamma (31, 32) + - Sherman-Morrison Tridiagonal Solver Constructor (33, 34, 35) + - Sherman-Morrison Batista-Karawia Gamma (36) + - Sherman-Morrison Batista-Karawia #1 (37, 38) + - Sherman-Morrison Batista-Karawia #2 (39, 40) + - Sherman-Morrison U RHS Array (45, 46, 47) + - Sherman-Morrison V RHS Array (50, 51, 52) + - Sherman-Morrison U Solution Array (55, 56) + - Sherman-Morrison V Solution Array (57, 58) + - Sherman-Morrison Q Solution Array (65, 66) + - Sherman-Morrison Y Solution (67) + - Sherman-Morrison Q Y #1 (70, 71, 72) + - Sherman-Morrison Q Y #2 (73, 74, 75) + - Standard Sherman-Morrison Tridiagonal Solver (99, 100, 101) + - Sherman-Morrison Batista-Karawia #1 (102, 103) + - Sherman-Morrison Batista-Karawia #2 (104, 105) + - Ryabenkii Tsynkov UV Solution Robustness (112, 113) + - Forward Sweep Back Substitution Robustness (116) + + +Bug Fixes/Re-organization: + + - Ryabenkii Tsynkov V Array Fix (4) + - Ryabenkii Tsynkov UV Array Fix (23) + - RHS V Solution Array Fix (63, 64) + - Sherman Morrison Batista-Karawia B (90, 91) + - Regular/Periodic Tridiagonal Solver Schemes (115) + + +Samples: + + - Ryabenkii Tsynkov Tridiagonal Run #1 (1, 2, 3) + - Ryabenkii Tsynkov Tridiagonal Run #2 (7, 8) + - Ryabenkii Tsynkov Tridiagonal Run #3 (11, 12) + - Ryabenkii Tsynkov Tridiagonal Run #4 (20, 21, 22) + - Batista-Karawia Tridiagonal Periodic #1 (41, 42) + - Batista-Karawia Tridiagonal Periodic #2 (43, 44) + - Batista-Karawia Tridiagonal Periodic #3 (48, 49) + - Batista-Karawia Tridiagonal Periodic #4 (53, 54) + - Batista-Karawia Tridiagonal Periodic #5 (59, 60) + - Batista-Karawia Tridiagonal Periodic #6 (61, 62) + - Batista-Karawia Tridiagonal Periodic #7 (68, 69) + - Batista-Karawia Tridiagonal Periodic #8 (76, 77) + - Batista-Karawia Tridiagonal Periodic #9 (78, 79) + - Batista-Karawia Tridiagonal Periodic #10 (80, 81, 82) + - Batista-Karawia Tridiagonal Periodic #11 (83, 84) + - Batista-Karawia Tridiagonal Periodic #12 (85, 86) + - Batista-Karawia Tridiagonal Periodic #13 (87, 88, 89) + - Batista-Karawia Tridiagonal Periodic #14 (92, 93, 94) + - Batista-Karawia Tridiagonal Periodic #15 (95, 96, 97) + - Batista-Karawia Tridiagonal Periodic #16 (98) + - Batista-Karawia Tridiagonal Periodic #17 (106, 107, 108) + - Batista-Karawia Tridiagonal Periodic #18 (109, 110, 111) + - Ryabenkii Tsynkov Tridiagonal Run #5 (114) + - Forward Sweep Back Substitution Run (117) + - Non-period Tridiagonal Solver Shell (118, 119, 120) + + +IdeaDRIP: diff --git a/src/main/java/org/drip/numerical/linearalgebra/RyabenkiiTsynkovSolver.java b/src/main/java/org/drip/numerical/linearalgebra/RyabenkiiTsynkovSolver.java index 0cda5b0fb19..ac53ec02244 100644 --- a/src/main/java/org/drip/numerical/linearalgebra/RyabenkiiTsynkovSolver.java +++ b/src/main/java/org/drip/numerical/linearalgebra/RyabenkiiTsynkovSolver.java @@ -217,12 +217,101 @@ public double[] vRHSArray() vRHSArray[size - 1] = -1. * _squareMatrix[size][0]; for (int i = 2; i <= size - 1; ++i) { - vRHSArray[i - 1] = _rhsArray[i]; + vRHSArray[i - 1] = 0.; } return vRHSArray; } + /** + * Compute the U Solution Array + * + * @return U Solution Array + */ + + public double[] uSolutionArray() + { + try { + return new TridiagonalSolver (tridiagonalMatrix(), uRHSArray()).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Compute the V Solution Array + * + * @return V Solution Array + */ + + public double[] vSolutionArray() + { + try { + return new TridiagonalSolver (tridiagonalMatrix(), vRHSArray()).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Compute the Solution Array based on U/V Scheme + * + * @return Solution Array + */ + + public double[] uvSolver() + { + double[] uSolutionArray = null; + double[] vSolutionArray = null; + int size = _rhsArray.length - 1; + double[] solutionArray = new double[size + 1]; + + double[][] tridiagonalMatrix = tridiagonalMatrix(); + + if (null == tridiagonalMatrix) { + return null; + } + + try { + uSolutionArray = new TridiagonalSolver ( + tridiagonalMatrix, + uRHSArray() + ).forwardSweepBackSubstitution(); + + vSolutionArray = new TridiagonalSolver ( + tridiagonalMatrix, + vRHSArray() + ).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + + return null; + } + + if (!NumberUtil.IsValid ( + solutionArray[0] = ( + _rhsArray[0] - _squareMatrix[0][size] * uSolutionArray[size - 1] - + _squareMatrix[0][1] * uSolutionArray[0] + ) / ( + _squareMatrix[0][0] + _squareMatrix[0][size] * vSolutionArray[size - 1] + + _squareMatrix[0][1] * vSolutionArray[0] + ) + )) + { + return null; + } + + for (int i = size; i >= 1; --i) { + solutionArray[i] = uSolutionArray[i - 1] + solutionArray[0] * vSolutionArray[i - 1]; + } + + return solutionArray; + } + public static final void main ( final String[] argumentArray) throws Exception @@ -253,5 +342,25 @@ public static final void main ( System.out.println ( NumberUtil.Print1DArrayRow (ryabenkiiTsynkovSolver.uRHSArray(), 4, false) ); + + System.out.println ( + NumberUtil.Print1DArrayRow (ryabenkiiTsynkovSolver.vRHSArray(), 4, false) + ); + + System.out.println(); + + System.out.println ( + NumberUtil.Print1DArrayRow (ryabenkiiTsynkovSolver.uSolutionArray(), 4, false) + ); + + System.out.println ( + NumberUtil.Print1DArrayRow (ryabenkiiTsynkovSolver.vSolutionArray(), 4, false) + ); + + System.out.println(); + + System.out.println ( + NumberUtil.Print1DArrayRow (ryabenkiiTsynkovSolver.uvSolver(), 4, false) + ); } } diff --git a/src/main/java/org/drip/numerical/linearalgebra/ShermanMorrisonSolver.java b/src/main/java/org/drip/numerical/linearalgebra/ShermanMorrisonSolver.java new file mode 100644 index 00000000000..8ab12088077 --- /dev/null +++ b/src/main/java/org/drip/numerical/linearalgebra/ShermanMorrisonSolver.java @@ -0,0 +1,457 @@ + +package org.drip.numerical.linearalgebra; + +import org.drip.numerical.common.NumberUtil; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2025 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ShermanMorrisonSolver implements the O(n) solver for a Tridiagonal Matrix with Periodic Boundary + * Conditions. The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class ShermanMorrisonSolver +{ + + /** + * Batistia-Karawia Default Gamma + */ + + public static final double BATISTA_KARAWIA_DEFAULT_GAMMA = 1.; + + private double[] _rhsArray = null; + private double _gamma = Double.NaN; + private double[][] _squareMatrix = null; + + /** + * Construct a Standard Gamma Instance of Sherman Morrison Solver + * + * @param squareMatrix Square Matrix + * @param rhsArray RHS Array + * + * @return Standard Gamma Instance of Sherman Morrison Solver + */ + + public static final ShermanMorrisonSolver Standard ( + final double[][] squareMatrix, + final double[] rhsArray) + { + try { + return new ShermanMorrisonSolver ( + squareMatrix, + rhsArray, + BATISTA_KARAWIA_DEFAULT_GAMMA + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Construct a Standard Batista-Karawia Instance of Sherman Morrison Solver + * + * @param squareMatrix Square Matrix + * @param rhsArray RHS Array + * + * @return Standard Batista-Karawia Instance of Sherman Morrison Solver + */ + + public static final ShermanMorrisonSolver StandardBatistaKarawia ( + final double[][] squareMatrix, + final double[] rhsArray) + { + if (null == squareMatrix || 0 == squareMatrix.length) { + return null; + } + + int index = 1; + double gamma = -1. * squareMatrix[0][0]; + + while (0. == gamma && index < squareMatrix.length) { + gamma = -1. * squareMatrix[index][index]; + ++index; + } + + if (0. == gamma) { + return null; + } + + try { + return new ShermanMorrisonSolver (squareMatrix, rhsArray, gamma); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * ShermanMorrisonSolver Constructor + * + * @param squareMatrix Square Matrix + * @param rhsArray RHS Array + * @param gamma Gamma + * + * @throws Exception Thrown if the Square Matrix is not Periodic Tridiagonal + */ + + public ShermanMorrisonSolver ( + final double[][] squareMatrix, + final double[] rhsArray, + final double gamma) + throws Exception + { + if (!Matrix.IsPeriodicTridiagonal (_squareMatrix = squareMatrix) || + null == (_rhsArray = rhsArray) || + _squareMatrix.length != _rhsArray.length || + !NumberUtil.IsValid (_gamma = gamma) || 0. == _gamma) + { + throw new Exception ("ShermanMorrisonSolver Constructor => Matrix not Periodic Tridiagonal"); + } + } + + /** + * Retrieve the Square Matrix + * + * @return Square Matrix + */ + + public double[][] squareMatrix() + { + return _squareMatrix; + } + + /** + * Retrieve the RHS Array + * + * @return Square Matrix + */ + + public double[] rhsArray() + { + return _rhsArray; + } + + /** + * Retrieve the Gamma + * + * @return Gamma + */ + + public double gamma() + { + return _gamma; + } + + /** + * Construct a Batista-Karawia Modification to the Periodic Tridiagonal Matrix + * + * @return Batista-Karawia Modification to the Periodic Tridiagonal Matrix + */ + + public double[][] batistaKarawiaMatrix() + { + double[][] batistaKarawiaMatrix = new double[_rhsArray.length][_rhsArray.length]; + + for (int i = 0; i < _squareMatrix.length; ++i) { + for (int j = 0; j < _squareMatrix.length; ++j) { + batistaKarawiaMatrix[i][j] = j >= i - 1 && j <= i + 1 ? _squareMatrix[i][j] : 0.; + } + } + + int lastIndex = _rhsArray.length - 1; + batistaKarawiaMatrix[0][0] = _squareMatrix[0][0] - _gamma; + batistaKarawiaMatrix[lastIndex][lastIndex] = _squareMatrix[lastIndex][lastIndex] - ( + _squareMatrix[lastIndex][0] * _squareMatrix[0][lastIndex] / _gamma + ); + return batistaKarawiaMatrix; + } + + /** + * Construct a Batista-Karawia U RHS Array + * + * @return Batista-Karawia U RHS Array + */ + + public double[] uRHSArray() + { + double[] uRHSArray = new double[_rhsArray.length]; + + for (int i = 0; i < _rhsArray.length; ++i) { + uRHSArray[i] = 0.; + } + + uRHSArray[0] = _gamma; + int lastIndex = _rhsArray.length - 1; + uRHSArray[lastIndex] = _squareMatrix[lastIndex][0]; + return uRHSArray; + } + + /** + * Compute the Q Solution Array + * + * @return Q Solution Array + */ + + public double[] qSolutionArray() + { + double[][] batistaKarawiaMatrix = batistaKarawiaMatrix(); + + if (null == batistaKarawiaMatrix) { + return null; + } + + try { + return new TridiagonalSolver (batistaKarawiaMatrix, uRHSArray()).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Compute the Y Solution Array + * + * @return Y Solution Array + */ + + public double[] ySolutionArray() + { + double[][] batistaKarawiaMatrix = batistaKarawiaMatrix(); + + if (null == batistaKarawiaMatrix) { + return null; + } + + try { + return new TridiagonalSolver (batistaKarawiaMatrix, _rhsArray).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Construct a Batista-Karawia V Array + * + * @return Batista-Karawia V Array + */ + + public double[] vArray() + { + double[] vArray = new double[_rhsArray.length]; + + for (int i = 0; i < _rhsArray.length; ++i) { + vArray[i] = 0.; + } + + vArray[0] = 1.; + int lastIndex = _rhsArray.length - 1; + vArray[lastIndex] = _squareMatrix[0][lastIndex] / _gamma; + return vArray; + } + + /** + * Compute the Solution Array based on Q/Y Scheme + * + * @return Solution Array + */ + + public double[] qySolver() + { + double[] vArray = vArray(); + + double[] qSolutionArray = null; + double[] ySolutionArray = null; + double vqDotProductScaler = Double.NaN; + + double[][] batistaKarawiaMatrix = batistaKarawiaMatrix(); + + try { + qSolutionArray = new TridiagonalSolver ( + batistaKarawiaMatrix, + uRHSArray() + ).forwardSweepBackSubstitution(); + + ySolutionArray = new TridiagonalSolver ( + batistaKarawiaMatrix, + _rhsArray + ).forwardSweepBackSubstitution(); + } catch (Exception e) { + e.printStackTrace(); + + return null; + } + + double[] solutionArray = Matrix.Product ( + Matrix.CrossProduct (qSolutionArray, vArray), + ySolutionArray + ); + + if (null == solutionArray) { + return null; + } + + try { + vqDotProductScaler = 1. / (1. + Matrix.DotProduct (vArray, qSolutionArray)); + } catch (Exception e) { + e.printStackTrace(); + + return null; + } + + for (int i = 0; i < _rhsArray.length; ++i) { + solutionArray[i] = ySolutionArray[i] - solutionArray[i] * vqDotProductScaler; + } + + return solutionArray; + } + + public static final void main ( + final String[] argumentArray) + throws Exception + { + double[][] periodicTridiagonalMatrix = new double[][] { + {2., 7., 0., 0., 3.}, + {7., 6., 4., 0., 0.}, + {0., 4., 1., 5., 0.}, + {0., 0., 5., 9., 2.}, + {8., 0., 0., 2., 6.}, + }; + + double[] rhsArray = new double[] { + 31., + 31., + 31., + 61., + 46. + }; + + ShermanMorrisonSolver shermanMorrisonSolver = ShermanMorrisonSolver.StandardBatistaKarawia ( + periodicTridiagonalMatrix, + rhsArray + ); + + NumberUtil.Print2DArray ("Batista-Karawia", shermanMorrisonSolver.batistaKarawiaMatrix(), false); + + System.out.println ("U RHS: " + NumberUtil.Print1DArrayRow (shermanMorrisonSolver.uRHSArray(), 4, false)); + + System.out.println ("V Array: " + NumberUtil.Print1DArrayRow (shermanMorrisonSolver.vArray(), 4, false)); + + System.out.println ("Q Solution Array: " + NumberUtil.Print1DArrayRow (shermanMorrisonSolver.qSolutionArray(), 4, false)); + + System.out.println ("Y Solution Array: " + NumberUtil.Print1DArrayRow (shermanMorrisonSolver.ySolutionArray(), 4, false)); + + System.out.println ("Solution Array: " + NumberUtil.Print1DArrayRow (shermanMorrisonSolver.qySolver(), 4, false)); + } +} diff --git a/src/main/java/org/drip/numerical/linearalgebra/TridiagonalSolver.java b/src/main/java/org/drip/numerical/linearalgebra/TridiagonalSolver.java index 7b5ec2e9a1d..3d148b192e3 100644 --- a/src/main/java/org/drip/numerical/linearalgebra/TridiagonalSolver.java +++ b/src/main/java/org/drip/numerical/linearalgebra/TridiagonalSolver.java @@ -179,9 +179,14 @@ public double[] forwardSweepBackSubstitution() } for (int i = 1; i < matrixSize; ++i) { - modifiedRHSArray[i] = (_rhsArray[i] - _squareMatrix[i][i - 1] * modifiedRHSArray[i - 1]) / ( - _squareMatrix[i][i] - _squareMatrix[i][i - 1] * modifiedSupraDiagonalArray[i - 1] - ); + if (!NumberUtil.IsValid ( + modifiedRHSArray[i] = (_rhsArray[i] - _squareMatrix[i][i - 1] * modifiedRHSArray[i - 1]) / ( + _squareMatrix[i][i] - _squareMatrix[i][i - 1] * modifiedSupraDiagonalArray[i - 1] + ) + )) + { + return null; + } } solutionArray[matrixSize - 1] = modifiedRHSArray[matrixSize - 1]; diff --git a/src/main/java/org/drip/sample/tridiagonal/NonPeriodicSolver.java b/src/main/java/org/drip/sample/tridiagonal/NonPeriodicSolver.java new file mode 100644 index 00000000000..dd93af01e06 --- /dev/null +++ b/src/main/java/org/drip/sample/tridiagonal/NonPeriodicSolver.java @@ -0,0 +1,119 @@ + +package org.drip.sample.tridiagonal; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2025 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * NonPeriodicSolver illustrates the application of the Non-periodic Solver of a Tridiagonal Matrix. + * The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class NonPeriodicSolver +{ + +} diff --git a/src/main/java/org/drip/sample/tridiagonal/package-info.java b/src/main/java/org/drip/sample/tridiagonal/package-info.java new file mode 100644 index 00000000000..7d861d5e029 --- /dev/null +++ b/src/main/java/org/drip/sample/tridiagonal/package-info.java @@ -0,0 +1,8 @@ + +/** + * Regular/Periodic Tridiagonal Solver Schemes + * + * @author Lakshmi Krishnamurthy + */ + +package org.drip.sample.tridiagonal;