From e9dd99dc2f7e4f96a1aaf4e41ce3765b742f9edd Mon Sep 17 00:00:00 2001 From: Lakshmi Krishnamurthy Date: Sun, 1 Sep 2024 12:21:54 -0400 Subject: [PATCH] Features: - Single Vector Norm Evaluator Annotation (1) - Single Vector Norm 1 Evaluator (2, 3, 4) - Single Vector Norm 2 Evaluator (5, 6) - Single Vector Norm Infinity Evaluator (7, 8, 9) - Double Vector Norm Evaluator #1 (10, 11, 12) - Double Vector Norm Evaluator #2 (13, 14, 15) - Single Vector Norm Evaluator Constructor (16, 17, 18) - Double Vector Two Infinity Evaluator Shell (19, 20, 21) - Double Vector Two Infinity Evaluator Constructor (22, 23, 24) - Double Vector Two Infinity Evaluator Norm (25, 26, 27) - Double Vector One Two Evaluator Shell (28, 29) - Double Vector One Two Evaluator Constructor (30, 31) - Double Vector One Two Evaluator Norm (32, 33) - Matrix-Matrix Sub-multiplicative Consistency Validation (37, 38, 39) - Matrix-Matrix Sub-additive Consistency Validation (40, 41, 42) - Matrix Vector Sub-multiplicative Consistency #1 (43, 44, 45) - Matrix Vector Sub-multiplicative Consistency #2 (46, 47, 48) - Matrix Vector Sub-multiplicative Consistency #3 (49, 50, 51) - Util Unsafe Matrix Vector Product #1 (52, 53, 54) - Util Safe Matrix Vector Product #1 (55, 56, 57) - Util Unsafe Matrix Vector Product #2 (58, 59, 60) - Util Safe Matrix Vector Product #2 (61, 62, 63) - Util Safe Matrix Vector Product #3 (64, 65, 66) - Square Evaluator Consistency Validator #1 (67, 68, 69) - Square Evaluator Consistency Validator #2 (70, 71, 72) - Single Compatible Vector Evaluator p-Norm (73, 74, 75) - Entry-wise Norm Evaluator Shell #1 (76, 77, 78) - Entry-wise Evaluator p Norm (79, 80, 81) - Entry-wise Evaluator q Norm (82, 83, 84) - Entry-wise Evaluator pq Norm #1 (85, 86, 87) - Entry-wise Evaluator pq Norm #2 (88, 89) - Entry-wise Evaluator pq Norm Constructor (90, 91, 92) - Entry-wise Evaluator pq Norm 2_1 (93, 94, 95) - Entry-wise Evaluator pq Norm p_p (96, 97, 98) - Matrix Util Unsafe Trace #1 (99, 100) - Matrix Util Unsafe Trace #2 (101, 102) - R1 Matrix Util Trace Evaluator (103, 104, 105) - R1 Square Matrix Trace Evaluator (106, 107, 108) - Entry-wise Frobenius Evaluator Shell (109, 110, 111) - Entry-wise Frobenius Evaluator Constructor (112, 113, 114) - Entry-wise Frobenius Evaluator Norm (115, 116, 117) - Entry-wise Frobenius Evaluator Trace Norm (118, 119, 120) Bug Fixes/Re-organization: - R1 Square Consistency Validator Criteria (34, 35, 36) Samples: IdeaDRIP: --- ReleaseNotes/04_09_2024.txt | 55 ++++ .../numerical/linearalgebra/R1MatrixUtil.java | 184 +++++++++----- .../org/drip/numerical/matrix/R1Square.java | 51 ++++ ...or.java => DoubleVectorNormEvaluator.java} | 40 +-- .../DoubleVectorOneTwoEvaluator.java | 169 +++++++++++++ .../DoubleVectorTwoInfinityEvaluator.java | 169 +++++++++++++ .../matrixnorm/EntryWiseEvaluator.java | 236 ++++++++++++++++++ .../matrixnorm/FrobeniusEvaluator.java | 192 ++++++++++++++ ...java => R1SquareConsistencyValidator.java} | 114 ++++++--- .../matrixnorm/R1SquareEvaluator.java | 31 ++- ...r.java => SingleVectorNorm1Evaluator.java} | 14 +- ...r.java => SingleVectorNorm2Evaluator.java} | 16 +- .../matrixnorm/SingleVectorNormEvaluator.java | 24 +- ...=> SingleVectorNormInfinityEvaluator.java} | 15 +- 14 files changed, 1170 insertions(+), 140 deletions(-) create mode 100644 ReleaseNotes/04_09_2024.txt rename src/main/java/org/drip/numerical/matrixnorm/{AlphaBetaEvaluator.java => DoubleVectorNormEvaluator.java} (84%) create mode 100644 src/main/java/org/drip/numerical/matrixnorm/DoubleVectorOneTwoEvaluator.java create mode 100644 src/main/java/org/drip/numerical/matrixnorm/DoubleVectorTwoInfinityEvaluator.java create mode 100644 src/main/java/org/drip/numerical/matrixnorm/EntryWiseEvaluator.java create mode 100644 src/main/java/org/drip/numerical/matrixnorm/FrobeniusEvaluator.java rename src/main/java/org/drip/numerical/matrixnorm/{R1SquareEvaluatorValidator.java => R1SquareConsistencyValidator.java} (73%) rename src/main/java/org/drip/numerical/matrixnorm/{P1Evaluator.java => SingleVectorNorm1Evaluator.java} (92%) rename src/main/java/org/drip/numerical/matrixnorm/{P2Evaluator.java => SingleVectorNorm2Evaluator.java} (90%) rename src/main/java/org/drip/numerical/matrixnorm/{PInfinityEvaluator.java => SingleVectorNormInfinityEvaluator.java} (91%) diff --git a/ReleaseNotes/04_09_2024.txt b/ReleaseNotes/04_09_2024.txt new file mode 100644 index 00000000000..fb9a20d663c --- /dev/null +++ b/ReleaseNotes/04_09_2024.txt @@ -0,0 +1,55 @@ + +Features: + + - Single Vector Norm Evaluator Annotation (1) + - Single Vector Norm 1 Evaluator (2, 3, 4) + - Single Vector Norm 2 Evaluator (5, 6) + - Single Vector Norm Infinity Evaluator (7, 8, 9) + - Double Vector Norm Evaluator #1 (10, 11, 12) + - Double Vector Norm Evaluator #2 (13, 14, 15) + - Single Vector Norm Evaluator Constructor (16, 17, 18) + - Double Vector Two Infinity Evaluator Shell (19, 20, 21) + - Double Vector Two Infinity Evaluator Constructor (22, 23, 24) + - Double Vector Two Infinity Evaluator Norm (25, 26, 27) + - Double Vector One Two Evaluator Shell (28, 29) + - Double Vector One Two Evaluator Constructor (30, 31) + - Double Vector One Two Evaluator Norm (32, 33) + - Matrix-Matrix Sub-multiplicative Consistency Validation (37, 38, 39) + - Matrix-Matrix Sub-additive Consistency Validation (40, 41, 42) + - Matrix Vector Sub-multiplicative Consistency #1 (43, 44, 45) + - Matrix Vector Sub-multiplicative Consistency #2 (46, 47, 48) + - Matrix Vector Sub-multiplicative Consistency #3 (49, 50, 51) + - Util Unsafe Matrix Vector Product #1 (52, 53, 54) + - Util Safe Matrix Vector Product #1 (55, 56, 57) + - Util Unsafe Matrix Vector Product #2 (58, 59, 60) + - Util Safe Matrix Vector Product #2 (61, 62, 63) + - Util Safe Matrix Vector Product #3 (64, 65, 66) + - Square Evaluator Consistency Validator #1 (67, 68, 69) + - Square Evaluator Consistency Validator #2 (70, 71, 72) + - Single Compatible Vector Evaluator p-Norm (73, 74, 75) + - Entry-wise Norm Evaluator Shell #1 (76, 77, 78) + - Entry-wise Evaluator p Norm (79, 80, 81) + - Entry-wise Evaluator q Norm (82, 83, 84) + - Entry-wise Evaluator pq Norm #1 (85, 86, 87) + - Entry-wise Evaluator pq Norm #2 (88, 89) + - Entry-wise Evaluator pq Norm Constructor (90, 91, 92) + - Entry-wise Evaluator pq Norm 2_1 (93, 94, 95) + - Entry-wise Evaluator pq Norm p_p (96, 97, 98) + - Matrix Util Unsafe Trace #1 (99, 100) + - Matrix Util Unsafe Trace #2 (101, 102) + - R1 Matrix Util Trace Evaluator (103, 104, 105) + - R1 Square Matrix Trace Evaluator (106, 107, 108) + - Entry-wise Frobenius Evaluator Shell (109, 110, 111) + - Entry-wise Frobenius Evaluator Constructor (112, 113, 114) + - Entry-wise Frobenius Evaluator Norm (115, 116, 117) + - Entry-wise Frobenius Evaluator Trace Norm (118, 119, 120) + + +Bug Fixes/Re-organization: + + - R1 Square Consistency Validator Criteria (34, 35, 36) + + +Samples: + +IdeaDRIP: diff --git a/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java b/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java index 8a5c20083e0..96d0dfa3b6f 100644 --- a/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java +++ b/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java @@ -215,6 +215,70 @@ public static final double[][] UnsafeProduct ( return product; } + /** + * Compute the Product of an Input Matrix and a Vector. Unsafe Methods do not validate the Input + * Arguments, so use caution in applying these Methods + * + * @param a Matrix A + * @param b Vector B + * + * @return The Product + */ + + public static final double[] UnsafeProduct ( + final double[][] a, + final double[] b) + { + double[] product = new double[a.length]; + + for (int rowIndex = 0; rowIndex < a.length; ++rowIndex) { + product[rowIndex] = 0.; + + for (int columnIndex = 0; columnIndex < a[0].length; ++columnIndex) { + if (!NumberUtil.IsValid (a[rowIndex][columnIndex]) || !NumberUtil.IsValid (b[columnIndex])) { + return null; + } + + product[rowIndex] += a[rowIndex][columnIndex] * b[columnIndex]; + } + } + + return product; + } + + /** + * Compute the Product of an Input Vector and a Matrix. Unsafe Methods do not validate the Input + * Arguments, so use caution in applying these Methods + * + * @param a Column A + * @param b Matrix B + * + * @return The Product + */ + + public static final double[][] UnsafeProduct ( + final double[] a, + final double[][] b) + { + double[][] product = new double[a.length][b.length]; + + for (int rowIndex = 0; rowIndex < a.length; ++rowIndex) { + for (int columnIndex = 0; columnIndex < b.length; ++columnIndex) { + product[rowIndex][columnIndex] = 0.; + + for (int i = 0; i < a.length; ++i) { + if (!NumberUtil.IsValid (a[rowIndex]) || !NumberUtil.IsValid (b[i][columnIndex])) { + return null; + } + + product[rowIndex][columnIndex] += a[rowIndex] * b[i][columnIndex]; + } + } + } + + return product; + } + /** * Compute the Addition of the Input Matrices. Unsafe Methods do not validate the Input Arguments, so * use caution in applying these Methods @@ -270,6 +334,7 @@ public static final double[][] UnsafeSubtract ( * caution in applying these Methods * * @param a Vector A + * @param k Power Exponent * * @return The Power Matrix */ @@ -289,6 +354,34 @@ public static final double[][] UnsafePower ( return aPower; } + /** + * Compute the Trace of the Input Matrix. Unsafe Methods do not validate the Input Arguments, so use + * caution in applying these Methods + * + * @param a Vector A + * + * @return The Trace + * + * @throws Exception Thrown if Trace cannot be Calculated + */ + + public static final double UnsafeTrace ( + final double[][] a) + throws Exception + { + double trace = 0.; + + for (int i = 0; i < a.length; ++i) { + if (!NumberUtil.IsValid (a[i][i])) { + throw new Exception ("R1MatrixUtil::UnsafeTrace => Invalid Matrix Entry"); + } + + trace += a[i][i]; + } + + return trace; + } + /** * Orthogonalize the Specified Matrix Using the RQ Graham-Schmidt Method. Unsafe Methods do not validate * the Input Arguments, so use caution in applying these Methods @@ -427,79 +520,37 @@ public static final boolean DiagonalizeRow ( } /** - * Compute the Product of an Input Matrix and a Column + * Compute the Product of an Input Matrix and a Vector * - * @param aadblA Matrix A - * @param adblB Array B + * @param a Matrix A + * @param b Array B * * @return The Product */ public static final double[] Product ( - final double[][] aadblA, - final double[] adblB) + final double[][] a, + final double[] b) { - if (null == aadblA || null == adblB) return null; - - int iNumACol = aadblA[0].length; - int iNumProductCol = adblB.length; - int iNumProductRow = aadblA.length; - double[] adblProduct = new double[iNumProductRow]; - - if (0 == iNumACol || iNumACol != adblB.length || 0 == iNumProductRow || 0 == iNumProductCol) - return null; - - for (int iRow = 0; iRow < iNumProductRow; ++iRow) { - adblProduct[iRow] = 0.; - - for (int i = 0; i < iNumACol; ++i) { - if (!org.drip.numerical.common.NumberUtil.IsValid (aadblA[iRow][i]) || - !org.drip.numerical.common.NumberUtil.IsValid (adblB[i])) - return null; - - adblProduct[iRow] += aadblA[iRow][i] * adblB[i]; - } - } - - return adblProduct; + return null == a || null == b || 0 == a.length || 0 == a[0].length || a[0].length != b.length ? + null : UnsafeProduct (a, b); } /** - * Compute the Product of an input column and a matrix + * Compute the Product of an Input Vector and a Matrix * - * @param adblA Column A - * @param aadblB Matrix B + * @param a Vector A + * @param b Matrix B * * @return The Product */ public static final double[][] Product ( - final double[] adblA, - final double[][] aadblB) + final double[] a, + final double[][] b) { - if (null == adblA || null == aadblB) return null; - - int iNumACol = adblA.length; - int iNumProductCol = aadblB.length; - double[][] aadblProduct = new double[iNumACol][iNumProductCol]; - - if (0 == iNumACol || iNumACol != aadblB.length || 0 == iNumProductCol) return null; - - for (int iRow = 0; iRow < iNumACol; ++iRow) { - for (int iCol = 0; iCol < iNumProductCol; ++iCol) { - aadblProduct[iRow][iCol] = 0.; - - for (int i = 0; i < iNumACol; ++i) { - if (!org.drip.numerical.common.NumberUtil.IsValid (adblA[iRow]) || - !org.drip.numerical.common.NumberUtil.IsValid (aadblB[i][iCol])) - return null; - - aadblProduct[iRow][iCol] += adblA[iRow] * aadblB[i][iCol]; - } - } - } - - return aadblProduct; + return null == a || null == b || 0 == a.length || a.length != b.length || 0 == b[0].length ? + null : UnsafeProduct (a, b); } /** @@ -572,6 +623,27 @@ public static final double[][] Power ( return null == a || 0 == a.length || 0 == a[0].length || 0 >= k ? null : UnsafePower (a, k); } + /** + * Compute the Trace of the Input Matrix + * + * @param a Vector A + * + * @return The Trace + * + * @throws Exception Thrown if Trace cannot be Calculated + */ + + public static final double Trace ( + final double[][] a) + throws Exception + { + if (null == a || 0 == a.length || 0 == a[0].length) { + throw new Exception ("R1MatrixUtil::Trace => Invalid Input Matrix"); + } + + return UnsafeTrace (a); + } + /** * Compute the Sum of the input matrices * diff --git a/src/main/java/org/drip/numerical/matrix/R1Square.java b/src/main/java/org/drip/numerical/matrix/R1Square.java index 2639840a224..73ac9487fcf 100644 --- a/src/main/java/org/drip/numerical/matrix/R1Square.java +++ b/src/main/java/org/drip/numerical/matrix/R1Square.java @@ -176,6 +176,23 @@ public int size() return _r1Grid.length; } + /** + * Compute the Trace + * + * @return The Trace + */ + + public double trace() + { + double trace = 0.; + + for (int i = 0; i < _r1Grid.length; ++i) { + trace += _r1Grid[i][i]; + } + + return trace; + } + /** * Transpose the Square Matrix * @@ -304,6 +321,40 @@ public R1Square multiply ( return new R1Square (r1GridProduct); } + /** + * Compute the Product with the Vector + * + * @param r1Array Vector Array + * + * @return Resulting Matrix + */ + + public R1Square multiply ( + final double[] r1Array) + { + if (null == r1Array || 0 == r1Array.length || r1Array.length != _r1Grid.length) { + return null; + } + + double[][] r1GridProduct = new double[_r1Grid.length][_r1Grid.length]; + + for (int rowIndex = 0; rowIndex < r1Array.length; ++rowIndex) { + for (int columnIndex = 0; columnIndex < _r1Grid.length; ++columnIndex) { + r1GridProduct[rowIndex][columnIndex] = 0.; + + for (int i = 0; i < r1Array.length; ++i) { + if (!NumberUtil.IsValid (r1Array[rowIndex])) { + return null; + } + + r1GridProduct[rowIndex][columnIndex] += r1Array[rowIndex] * _r1Grid[i][columnIndex]; + } + } + } + + return new R1Square (r1GridProduct); + } + /** * Calculate whether the Matrix is "Normal" * diff --git a/src/main/java/org/drip/numerical/matrixnorm/AlphaBetaEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorNormEvaluator.java similarity index 84% rename from src/main/java/org/drip/numerical/matrixnorm/AlphaBetaEvaluator.java rename to src/main/java/org/drip/numerical/matrixnorm/DoubleVectorNormEvaluator.java index 8fccbc7ef6e..72f1c0a233c 100644 --- a/src/main/java/org/drip/numerical/matrixnorm/AlphaBetaEvaluator.java +++ b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorNormEvaluator.java @@ -74,7 +74,7 @@ */ /** - * AlphaBetaEvaluator exposes the row/column alpha/beta Vector Norm of a R1Square Matrix. + * DoubleVectorNormEvaluator exposes the row/column alpha/beta Vector Norm of a R1Square Matrix. * The References are: * *

@@ -113,49 +113,49 @@ * @author Lakshmi Krishnamurthy */ -public abstract class AlphaBetaEvaluator extends R1SquareEvaluator +public abstract class DoubleVectorNormEvaluator extends R1SquareEvaluator { - private int _beta = Integer.MIN_VALUE; - private int _alpha = Integer.MIN_VALUE; + private int _rowAlpha = Integer.MIN_VALUE; + private int _columnBeta = Integer.MIN_VALUE; /** - * AlphaBetaEvaluator Constructor + * DoubleVectorNormEvaluator Constructor * - * @param alpha Alpha Vector Norm Index - * @param beta Beta Vector Norm Index + * @param rowAlpha Alpha Row Vector Norm + * @param columnBeta Beta Column Vector Norm * * @throws Exception Thrown if the Inputs are Invalid */ - public AlphaBetaEvaluator ( - final int alpha, - final int beta) + public DoubleVectorNormEvaluator ( + final int rowAlpha, + final int columnBeta) throws Exception { - if (0 >= (_alpha = alpha) || 0 >= (_beta = beta)) { - throw new Exception ("AlphaBetaEvaluator Constructor => Invalid Inputs"); + if (0 >= (_rowAlpha = rowAlpha) || 0 >= (_columnBeta = columnBeta)) { + throw new Exception ("DoubleVectorNormEvaluator Constructor => Invalid Inputs"); } } /** - * Retrieve the Alpha Vector Norm Index + * Retrieve the Alpha Row Vector Norm * - * @return Alpha Vector Norm Index + * @return Alpha Row Vector Norm */ - public int alpha() + public int rowAlpha() { - return _alpha; + return _rowAlpha; } /** - * Retrieve the Beta Vector Norm Index + * Retrieve the Beta Column Vector Norm * - * @return Beta Vector Norm Index + * @return Beta Column Vector Norm */ - public int beta() + public int columnBeta() { - return _beta; + return _columnBeta; } } diff --git a/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorOneTwoEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorOneTwoEvaluator.java new file mode 100644 index 00000000000..3d8412497db --- /dev/null +++ b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorOneTwoEvaluator.java @@ -0,0 +1,169 @@ + +package org.drip.numerical.matrixnorm; + +import org.drip.numerical.matrix.R1Square; + +/* + * -*- 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. + */ + +/** + * DoubleVectorOneTwoEvaluator exposes the row/column alpha = 1/beta = 2 Vector Norm of a + * R1 Square Matrix. The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class DoubleVectorOneTwoEvaluator extends DoubleVectorNormEvaluator +{ + + /** + * DoubleVectorOneTwoEvaluator Constructor + * + * @throws Exception Thrown if the Inputs are Invalid + */ + + public DoubleVectorOneTwoEvaluator() + throws Exception + { + super (1, 2); + } + + /** + * Compute the Norm of the R1Square Matrix + * + * @param r1Square R1Square Matrix + * + * @return Norm of the R1Square Matrix + * + * @throws Exception + */ + + @Override public double norm ( + final R1Square r1Square) + throws Exception + { + if (null == r1Square) { + throw new Exception ("DoubleVectorOneTwoEvaluator::norm => Invalid Inputs"); + } + + double[][] r1Grid = r1Square.transpose().r1Grid(); + + double maximumColumnNorm = Integer.MIN_VALUE; + + for (int i = 0; i < r1Grid.length; ++i) { + double columnNorm = 0.; + + for (int j = 0; j < r1Grid[i].length; ++j) { + columnNorm += r1Grid[i][j] * r1Grid[i][j]; + } + + columnNorm = Math.sqrt (columnNorm); + + maximumColumnNorm = maximumColumnNorm < columnNorm ? maximumColumnNorm : columnNorm; + } + + return maximumColumnNorm; + } +} diff --git a/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorTwoInfinityEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorTwoInfinityEvaluator.java new file mode 100644 index 00000000000..6cafebec39d --- /dev/null +++ b/src/main/java/org/drip/numerical/matrixnorm/DoubleVectorTwoInfinityEvaluator.java @@ -0,0 +1,169 @@ + +package org.drip.numerical.matrixnorm; + +import org.drip.numerical.matrix.R1Square; + +/* + * -*- 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. + */ + +/** + * DoubleVectorTwoInfinityEvaluator exposes the row/column alpha = 2/beta = Infinity Vector Norm of a + * R1 Square Matrix. The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class DoubleVectorTwoInfinityEvaluator extends DoubleVectorNormEvaluator +{ + + /** + * DoubleVectorTwoInfinityEvaluator Constructor + * + * @throws Exception Thrown if the Inputs are Invalid + */ + + public DoubleVectorTwoInfinityEvaluator() + throws Exception + { + super (2, Integer.MAX_VALUE); + } + + /** + * Compute the Norm of the R1Square Matrix + * + * @param r1Square R1Square Matrix + * + * @return Norm of the R1Square Matrix + * + * @throws Exception + */ + + @Override public double norm ( + final R1Square r1Square) + throws Exception + { + if (null == r1Square) { + throw new Exception ("DoubleVectorTwoInfinityEvaluator::norm => Invalid Inputs"); + } + + double[][] r1Grid = r1Square.r1Grid(); + + double maximumRowNorm = Integer.MIN_VALUE; + + for (int i = 0; i < r1Grid.length; ++i) { + double rowNorm = 0.; + + for (int j = 0; j < r1Grid[i].length; ++j) { + rowNorm += r1Grid[i][j] * r1Grid[i][j]; + } + + rowNorm = Math.sqrt (rowNorm); + + maximumRowNorm = maximumRowNorm < rowNorm ? maximumRowNorm : rowNorm; + } + + return maximumRowNorm; + } +} diff --git a/src/main/java/org/drip/numerical/matrixnorm/EntryWiseEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/EntryWiseEvaluator.java new file mode 100644 index 00000000000..006d1227f8e --- /dev/null +++ b/src/main/java/org/drip/numerical/matrixnorm/EntryWiseEvaluator.java @@ -0,0 +1,236 @@ + +package org.drip.numerical.matrixnorm; + +import org.drip.numerical.matrix.R1Square; + +/* + * -*- 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. + */ + +/** + * EntryWiseEvaluator computes the Entry-wise Norm of a R1Square Matrix. The References + * are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class EntryWiseEvaluator extends R1SquareEvaluator +{ + private int _p = Integer.MIN_VALUE; + private int _q = Integer.MIN_VALUE; + + /** + * Construct a L2, 1 Instance of EntryWiseEvaluator + * + * @return L2, 1 Instance of EntryWiseEvaluator + */ + + public static final EntryWiseEvaluator L2_1() + { + try { + return new EntryWiseEvaluator (2, 1); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Construct a Lp, p Instance of EntryWiseEvaluator + * + * @param p p Norm + * + * @return Lp, p Instance of EntryWiseEvaluator + */ + + public static final EntryWiseEvaluator Lp_p ( + final int p) + { + try { + return new EntryWiseEvaluator (p, p); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * EntryWiseEvaluator Constructor + * + * @param p p Norm + * @param q q Norm + * + * @throws Exception Thrown if the Inputs are Invalid + */ + + public EntryWiseEvaluator ( + final int p, + final int q) + throws Exception + { + if (0 >= (_p = p) || 0 >= (_q = q)) { + throw new Exception ("EntryWiseEvaluator Constructor => Invalid Inputs"); + } + } + + /** + * Retrieve the p Norm + * + * @return p Norm + */ + + public int p() + { + return _p; + } + + /** + * Retrieve the q Norm + * + * @return q Norm + */ + + public int q() + { + return _q; + } + + /** + * Compute the Norm of the R1Square Matrix + * + * @param r1Square R1Square Matrix + * + * @return Norm of the R1Square Matrix + * + * @throws Exception + */ + + @Override public double norm ( + final R1Square r1Square) + throws Exception + { + if (null == r1Square) { + throw new Exception ("EntryWiseEvaluator::norm => Invalid Inputs"); + } + + double[][] r1Grid = r1Square.transpose().r1Grid(); + + double pqNormCumulative = Integer.MIN_VALUE; + double qOverP = _q /_p; + + for (int i = 0; i < r1Grid.length; ++i) { + double pNormCumulative = 0.; + + for (int j = 0; j < r1Grid[i].length; ++j) { + pNormCumulative += Math.pow (Math.abs (r1Grid[i][j]), _p); + } + + pqNormCumulative += Math.pow (pNormCumulative, qOverP); + } + + return Math.pow (pqNormCumulative, 1. / _q); + } +} diff --git a/src/main/java/org/drip/numerical/matrixnorm/FrobeniusEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/FrobeniusEvaluator.java new file mode 100644 index 00000000000..ab8a9461063 --- /dev/null +++ b/src/main/java/org/drip/numerical/matrixnorm/FrobeniusEvaluator.java @@ -0,0 +1,192 @@ + +package org.drip.numerical.matrixnorm; + +import org.drip.numerical.matrix.R1Square; + +/* + * -*- 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. + */ + +/** + * FrobeniusEvaluator computes the Entry-wise L2 Norm of the Entries of the R1 + * Square Matrix. The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class FrobeniusEvaluator extends EntryWiseEvaluator +{ + + /** + * FrobeniusEvaluator Constructor + * + * @throws Exception Thrown if the Inputs are Invalid + */ + + public FrobeniusEvaluator() + throws Exception + { + super (2, 2); + } + + /** + * Compute the Norm of the R1 Square Matrix + * + * @param r1Square R1 Square Matrix + * + * @return Norm of the R1 Square Matrix + * + * @throws Exception Thrown if the Norm cannot be calculated + */ + + @Override public double norm ( + final R1Square r1Square) + throws Exception + { + if (null == r1Square) { + throw new Exception ("FrobeniusEvaluator::norm => Invalid Inputs"); + } + + double[][] r1Grid = r1Square.r1Grid(); + + double frobeniusNormCumulative = Integer.MIN_VALUE; + + for (int i = 0; i < r1Grid.length; ++i) { + for (int j = 0; j < r1Grid[i].length; ++j) { + frobeniusNormCumulative += r1Grid[i][j] * r1Grid[i][j]; + } + } + + return Math.sqrt (frobeniusNormCumulative); + } + + /** + * Compute the Trace-based Norm of the R1 Square Matrix + * + * @param r1Square R1 Square Matrix + * + * @return Trace-based Norm of the R1 Square Matrix + * + * @throws Exception Thrown if the Norm cannot be calculated + */ + + public double traceNorm ( + final R1Square r1Square) + throws Exception + { + if (null == r1Square) { + throw new Exception ("FrobeniusEvaluator::traceNorm => Invalid Inputs"); + } + + R1Square conjugareTransposeProduct = r1Square.transpose().multiply (r1Square); + + if (null == conjugareTransposeProduct) { + throw new Exception ( + "FrobeniusEvaluator::traceNorm => Cannot compute Conjugate Transpose Product" + ); + } + + return Math.sqrt (conjugareTransposeProduct.trace()); + } +} diff --git a/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluatorValidator.java b/src/main/java/org/drip/numerical/matrixnorm/R1SquareConsistencyValidator.java similarity index 73% rename from src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluatorValidator.java rename to src/main/java/org/drip/numerical/matrixnorm/R1SquareConsistencyValidator.java index f72a897d15a..da56a1a6083 100644 --- a/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluatorValidator.java +++ b/src/main/java/org/drip/numerical/matrixnorm/R1SquareConsistencyValidator.java @@ -76,7 +76,7 @@ */ /** - * R1SquareEvaluatorValidator contains the Validation Criteria of the Norm Evaluator of a + * R1SquareConsistencyValidator contains the Consistency Validation Checks for the Norm Evaluator of a * R1 Square Matrix. The References are: * *

@@ -115,13 +115,14 @@ * @author Lakshmi Krishnamurthy */ -public class R1SquareEvaluatorValidator +public class R1SquareConsistencyValidator { private boolean _definite = false; - private boolean _subAdditive = false; private boolean _positiveValued = false; - private boolean _subMultiplicative = false; private boolean _absolutelyHomogeneous = false; + private boolean _matrixMatrixSubAdditive = false; + private boolean _matrixMatrixSubMultiplicative = false; + private boolean _matrixVectorSubMultiplicative = false; /** * Indicate if the Norm is Positive Valued @@ -189,16 +190,16 @@ public static final boolean AbsolutelyHomogeneous ( } /** - * Indicate if the Norm is Sub-additive + * Indicate if the Norm is Matrix-Matrix Sub-additive * * @param normA Norm of Matrix A * @param normB Norm of Matrix B * @param normAPlusB Norm of Matrix A Plus B * - * @return TRUE - Norm is Sub-additive + * @return TRUE - Norm is Matrix-Matrix Sub-additive */ - public static final boolean SubAdditive ( + public static final boolean MatrixMatrixSubAdditive ( final double normA, final double normB, final double normAPlusB) @@ -208,16 +209,16 @@ public static final boolean SubAdditive ( } /** - * Indicate if the Norm is Sub-multiplicative + * Indicate if the Norm is Matrix-Matrix Sub-multiplicative * * @param normA Norm of Matrix A * @param normB Norm of Matrix B * @param normAB Norm of Matrix A.B * - * @return TRUE - Norm is Sub-multiplicative + * @return TRUE - Norm is Matrix-Matrix Sub-multiplicative */ - public static final boolean SubMultiplicative ( + public static final boolean MatrixMatrixSubMultiplicative ( final double normA, final double normB, final double normAB) @@ -227,27 +228,50 @@ public static final boolean SubMultiplicative ( } /** - * Construct a Standard Instance of R1SquareEvaluatorValidator + * Indicate if the Norm is Matrix-Vector Sub-multiplicative + * + * @param normA Norm of Matrix A + * @param normX Norm of Vector X + * @param normAX Norm of Matrix A.X + * + * @return TRUE - Norm is Matrix-Vector Sub-multiplicative + */ + + public static final boolean MatrixVectorSubMultiplicative ( + final double normA, + final double normX, + final double normAX) + { + return NumberUtil.IsValid (normA) && NumberUtil.IsValid (normX) && NumberUtil.IsValid (normAX) && + normAX <= normA * normX; + } + + /** + * Construct a Standard Instance of R1SquareConsistencyValidator * * @param normA Norm of Matrix A * @param a Matrix A * @param normB Norm of Matrix B * @param alphaNormA Norm of Alpha-Matrix A * @param alpha Alpha - * @param normAPlusB Norm of A and B Matrix Sum - * @param normAB Norm of A and B Matrix Product + * @param normAPlusB Norm of A and B Matrix-Matrix Sum + * @param normAB Norm of A and B Matrix-Matrix Product + * @param normV Norm of Vector V + * @param normAV Norm of A and V Matrix-Vector Product * - * @return Standard Instance of R1SquareEvaluatorValidator + * @return Standard Instance of R1SquareConsistencyValidator */ - public static final R1SquareEvaluatorValidator Standard ( + public static final R1SquareConsistencyValidator Standard ( final double normA, final double[][] a, final double normB, final double alphaNormA, final double alpha, final double normAPlusB, - final double normAB) + final double normAB, + final double normV, + final double normAV) { if (!NumberUtil.IsValid (normA) || null == a || 0 == a.length || 0 == a[0].length || @@ -255,7 +279,9 @@ public static final R1SquareEvaluatorValidator Standard ( !NumberUtil.IsValid (alphaNormA) || !NumberUtil.IsValid (alpha) || !NumberUtil.IsValid (normAPlusB) || - !NumberUtil.IsValid (normAB)) + !NumberUtil.IsValid (normAB) || + !NumberUtil.IsValid (normV) || + !NumberUtil.IsValid (normAV)) { return null; } @@ -277,37 +303,41 @@ public static final R1SquareEvaluatorValidator Standard ( } } - return new R1SquareEvaluatorValidator ( + return new R1SquareConsistencyValidator ( 0. >= normA, definite, alphaNormA == normA * Math.abs (alpha), normAPlusB <= normA + normB, - normAB <= normA * normB + normAB <= normA * normB, + normAV <= normA * normV ); } /** - * R1SquareEvaluatorValidator Constructor + * R1SquareConsistencyValidator Constructor * * @param positiveValued TRUE - Norm is Positive Valued * @param definite TRUE - Norm is Definite * @param absolutelyHomogeneous TRUE - Norm is Absolutely Homogeneous - * @param subAdditive TRUE - Norm is Sub-additive - * @param subMultiplicative TRUE - Norm is Sub-multiplicative + * @param matrixMatrixSubAdditive TRUE - Norm is Matrix-Matrix Sub-additive + * @param matrixMatrixSubMultiplicative TRUE - Norm is Matrix-Matrix Sub-multiplicative + * @param matrixVectorSubMultiplicative TRUE - Norm is Matrix-Vector Sub-multiplicative */ - public R1SquareEvaluatorValidator ( + public R1SquareConsistencyValidator ( final boolean positiveValued, final boolean definite, final boolean absolutelyHomogeneous, - final boolean subAdditive, - final boolean subMultiplicative) + final boolean matrixMatrixSubAdditive, + final boolean matrixMatrixSubMultiplicative, + final boolean matrixVectorSubMultiplicative) { _definite = definite; - _subAdditive = subAdditive; _positiveValued = positiveValued; - _subMultiplicative = subMultiplicative; _absolutelyHomogeneous = absolutelyHomogeneous; + _matrixMatrixSubAdditive = matrixMatrixSubAdditive; + _matrixMatrixSubMultiplicative = matrixMatrixSubMultiplicative; + _matrixVectorSubMultiplicative = matrixVectorSubMultiplicative; } /** @@ -344,25 +374,36 @@ public boolean absolutelyHomogeneous() } /** - * Indicate if the Norm is Sub-additive + * Indicate if the Norm is Matrix-Matrix Sub-additive + * + * @return TRUE - Norm is Matrix-Matrix Sub-additive + */ + + public boolean matrixMatrixSubAdditive() + { + return _matrixMatrixSubAdditive; + } + + /** + * Indicate if the Norm is Matrix-Matrix Sub-multiplicative * - * @return TRUE - Norm is Sub-additive + * @return TRUE - Norm is Matrix-Matrix Sub-multiplicative */ - public boolean subAdditive() + public boolean matrixMatrixSubMultiplicative() { - return _subAdditive; + return _matrixMatrixSubMultiplicative; } /** - * Indicate if the Norm is Sub-multiplicative + * Indicate if the Norm is Matrix-Vector Sub-multiplicative * - * @return TRUE - Norm is Sub-multiplicative + * @return TRUE - Norm is Matrix-Vector Sub-multiplicative */ - public boolean subMultiplicative() + public boolean matrixVectorSubMultiplicative() { - return _subMultiplicative; + return _matrixVectorSubMultiplicative; } /** @@ -373,6 +414,7 @@ public boolean subMultiplicative() public boolean validate() { - return _positiveValued && _definite && _absolutelyHomogeneous && _subAdditive && _subMultiplicative; + return _positiveValued && _definite && _absolutelyHomogeneous && _matrixMatrixSubAdditive && + _matrixMatrixSubMultiplicative && _matrixVectorSubMultiplicative; } } diff --git a/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluator.java b/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluator.java index 02685d9512e..3c4ea06ccfc 100644 --- a/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluator.java +++ b/src/main/java/org/drip/numerical/matrixnorm/R1SquareEvaluator.java @@ -1,6 +1,7 @@ package org.drip.numerical.matrixnorm; +import org.drip.numerical.common.NumberUtil; import org.drip.numerical.matrix.R1Square; /* @@ -132,25 +133,39 @@ public abstract double norm ( ) throws Exception; /** - * Construct a Norm Validator for the Suite of Inputs + * Construct a Norm Consistency Validator for the Suite of Inputs * * @param a Matrix A * @param b Matrix B + * @param v Vector V * @param alpha Alpha Scale + * @param p Vector Norm Index * - * @return The Norm Validator + * @return The Norm Consistency Validator */ - public R1SquareEvaluatorValidator validator ( + public R1SquareConsistencyValidator validator ( final R1Square a, final R1Square b, - final double alpha) + final double[] v, + final double alpha, + final int p) { + if (null == v || 0 == v.length || !NumberUtil.IsValid (v)) { + return null; + } + double normA = Double.NaN; double normB = Double.NaN; double normAB = Double.NaN; + double normAV = Double.NaN; double alphaNormA = Double.NaN; double normAPlusB = Double.NaN; + double normVExponentiated = 0.; + + for (int i = 0; i < v.length; ++i) { + normVExponentiated += Math.pow (Math.abs (v[i]), p); + } try { normA = norm (a); @@ -162,20 +177,24 @@ public R1SquareEvaluatorValidator validator ( normAB = norm (a.multiply (b)); alphaNormA = norm (a.scale (alpha)); + + normAV = norm (a.multiply (v)); } catch (Exception e) { e.printStackTrace(); return null; } - return R1SquareEvaluatorValidator.Standard ( + return R1SquareConsistencyValidator.Standard ( normA, a.r1Grid(), normB, alphaNormA, alpha, normAPlusB, - normAB + normAB, + Math.pow (normVExponentiated, 1. / p), + normAV ); } } diff --git a/src/main/java/org/drip/numerical/matrixnorm/P1Evaluator.java b/src/main/java/org/drip/numerical/matrixnorm/SingleVectorNorm1Evaluator.java similarity index 92% rename from src/main/java/org/drip/numerical/matrixnorm/P1Evaluator.java rename to src/main/java/org/drip/numerical/matrixnorm/SingleVectorNorm1Evaluator.java index 4f1eda200e4..7c38fa58866 100644 --- a/src/main/java/org/drip/numerical/matrixnorm/P1Evaluator.java +++ b/src/main/java/org/drip/numerical/matrixnorm/SingleVectorNorm1Evaluator.java @@ -76,7 +76,8 @@ */ /** - * P1Evaluator exposes the P1 Norm of a R1 Square Matrix. The References are: + * SingleVectorNorm1Evaluator exposes the Single Vector p = 1 Norm applicable to both Rows/Columns of + * a R1 Square Matrix. The References are: * *

*