From 9ab34b56bc6cf661f643906081410b0b7a885892 Mon Sep 17 00:00:00 2001 From: Lakshmi Krishnamurthy Date: Sat, 10 Aug 2024 22:24:06 -0400 Subject: [PATCH] Features: - Implementation of R1/C1 Matrices (8, 9) - Numerical R^1 Square Matrix Re-work (10, 11, 12) - Numerical R^1 Tridiagonal Matrix Re-work (13, 14) - Numerical R^1 Non-periodic Tridiagonal Matrix Re-work (15, 16) - Numerical R^1 Periodic Tridiagonal Matrix Re-work (17, 18) - Numerical R^1 Triangular Matrix Re-work (19, 20, 21) - Linear Algebra R^1 Matrix Util (22, 23, 24) - Implementation of Complex Number Suite (25) - Numerical Complex C1 Shell #1 (26, 27, 28) - Numerical Complex C1 Shell #2 (29, 30, 31) - Numerical Complex Cartesian C1 Re-work (32, 33, 34) - Numerical Complex C1 Cartesian Re-work (35, 36) - C1 Matrix Util Add #1 (37, 38, 39) - C1 Matrix Util Add #2 (40, 41, 42) - C1 Matrix Util Add #3 (43, 44, 45) - C1 Matrix Util Add #4 (46, 47, 48) - C1 Matrix Util Scale #1 (49, 50, 51) - C1 Matrix Util Scale #2 (52, 53, 54) - C1 Matrix Util Scale #3 (55, 56, 57) - C1 Matrix Util Scale #4 (58, 59, 60) - C1 Matrix Util Subtract #1 (61, 62, 63) - C1 Matrix Util Subtract #2 (64, 65, 66) - C1 Matrix Util Subtract #3 (67, 68, 69) - C1 Matrix Util Subtract #4 (70, 71, 72) - C1 Matrix Util Multiply #1 (73, 74, 75) - C1 Matrix Util Multiply #2 (76, 77, 78) - C1 Matrix Util Multiply #3 (79, 80, 81) - C1 Matrix Util Multiply #4 (82, 83, 84) - C1 Matrix Util Divide #1 (85, 86, 87) - C1 Matrix Util Divide #2 (88, 89, 90) - C1 Matrix Util Divide #3 (91, 92, 93) - C1 Matrix Util Divide #4 (94, 95, 96) - C1 Matrix Util Square #1 (97, 98, 99) - C1 Matrix Util Square #2 (100, 101, 102) - C1 Matrix Util Square #3 (103, 104, 105) - C1 Matrix Util Square #4 (106, 107, 108) - C1 Matrix Util Square Root #1 (109, 110, 111) - C1 Matrix Util Square Root #2 (112, 113, 114) - C1 Matrix Util Square Root #3 (115, 116, 117) - C1 Matrix Util Square Root #4 (118, 119, 120) Bug Fixes/Re-organization: Samples: IdeaDRIP: - Unitary Matrix Elementary Constructions - 2x2 (1-7) --- IdeaDRIP/NumericalAnalysis/NA_v0.08 | 211 +++++++ ReleaseNotes/03_13_2024.txt | 52 ++ .../dynamics/kolmogorov/RdFokkerPlanck.java | 6 +- .../dynamics/process/RdStochasticEvolver.java | 2 +- .../definition/CartesianComplexNumber.java | 587 ------------------ .../org/drip/function/definition/R2ToZ1.java | 2 +- .../java/org/drip/function/matrix/Square.java | 8 +- .../ArmijoEvolutionVerifierMetrics.java | 2 +- .../CurvatureEvolutionVerifierMetrics.java | 4 +- .../WolfeEvolutionVerifierMetrics.java | 6 +- .../rdtor1solver/NewtonFixedPointFinder.java | 4 +- .../ProjectionDistributionLoading.java | 4 +- ...R1MultivariateNormalConvolutionEngine.java | 8 +- .../bayesian/TheilMixedEstimationModel.java | 96 +-- .../measure/crng/RandomMatrixGenerator.java | 38 +- .../drip/measure/crng/RdRandomSequence.java | 4 +- .../CorrelatedPathVertexDimension.java | 2 +- .../measure/discrete/QuadraticResampler.java | 4 +- .../measure/discrete/SequenceGenerator.java | 10 +- .../org/drip/measure/gaussian/Covariance.java | 2 +- .../drip/numerical/complex/C1MatrixUtil.java | 452 ++++++++++++++ .../drip/numerical/complex/CartesianC1.java | 385 ++++++++++++ .../drip/numerical/complex/package-info.java | 8 + .../PowerIterationComponentExtractor.java | 6 +- .../eigen/QREigenComponentExtractor.java | 20 +- .../drip/numerical/fourier/PhaseAdjuster.java | 8 +- .../SuccessiveOverRelaxation.java | 10 +- ...siveOverRelaxationConvergenceAnalyzer.java | 6 +- .../SymmetricSuccessiveOverRelaxation.java | 14 +- .../linearalgebra/GershgorinAnalyzer.java | 17 +- .../{MatrixUtil.java => R1MatrixUtil.java} | 41 +- .../linearalgebra/SylvesterEquation.java | 14 +- .../org/drip/numerical/linearalgebra/UD.java | 8 +- .../linearsolver/BartelsStewartScheme.java | 18 +- .../numerical/linearsolver/LinearSystem.java | 4 +- .../NonPeriodicTridiagonalScheme.java | 10 +- .../PeriodicTridiagonalScheme.java | 4 +- .../linearsolver/RyabenkiiTsynkovScheme.java | 10 +- .../linearsolver/ShermanMorrisonScheme.java | 20 +- .../linearsolver/TriangularScheme.java | 12 +- .../linearsolver/TridiagonalScheme.java | 8 +- .../R1NonPeriodicTridiagonal.java} | 18 +- .../R1PeriodicTridiagonal.java} | 17 +- .../R1Square.java} | 44 +- .../R1Triangular.java} | 20 +- .../R1Tridiagonal.java} | 12 +- .../drip/numerical/matrix/package-info.java | 8 + .../constrained/OptimizationFramework.java | 14 +- .../ForwardReverseHoldingsAllocation.java | 10 +- .../allocator/HoldingsAllocation.java | 2 +- .../BlackLittermanCombinationEngine.java | 20 +- .../HestonStochasticVolatilityAlgorithm.java | 215 +++---- .../EnsembleTradeFlowAdjustment.java | 4 +- .../EnsembleVariationMarginEstimate.java | 6 +- .../FixFloatAggressiveLong.java | 4 +- .../FixFloatAggressiveShort.java | 4 +- .../FixFloatClassicalMinusLong.java | 4 +- .../FixFloatClassicalMinusShort.java | 4 +- .../FixFloatClassicalPlusLong.java | 4 +- .../FixFloatClassicalPlusShort.java | 4 +- .../FixFloatConservativeLong.java | 4 +- .../FixFloatConservativeShort.java | 4 +- .../PathTradeFlowAdjustment.java | 4 +- .../blacklitterman/DaJagannathan2005d.java | 4 +- .../blacklitterman/IdzorekAndrogue2003.java | 4 +- .../sample/blacklitterman/OToole2013.java | 4 +- .../blacklitterman/Soontornkit2010.java | 4 +- .../CorrelatedNumeraireXVAAttribution.java | 4 +- .../CorrelatedNumeraireXVAExplain.java | 4 +- .../CorrelatedNumeraireXVAGreeks.java | 4 +- ...latedNumeraireXVAReplicationPortfolio.java | 4 +- .../drip/sample/burgard2011/XVAExplain.java | 4 +- .../drip/sample/burgard2011/XVAGreeks.java | 4 +- .../burgard2011/XVAMarketGeneration.java | 4 +- .../burgard2011/XVAReplicationPortfolio.java | 4 +- .../EulerTrajectoryEvolutionScheme.java | 4 +- ...ralCSACollateralizedFundingStochastic.java | 4 +- ...lCSAUncollateralizedFundingStochastic.java | 4 +- ...eralCSAZeroThresholdFundingStochastic.java | 4 +- ...cationCollateralizedFundingStochastic.java | 4 +- ...tionUncollateralizedFundingStochastic.java | 4 +- ...icationZeroThresholdFundingStochastic.java | 4 +- ...cationCollateralizedFundingStochastic.java | 4 +- ...tionUncollateralizedFundingStochastic.java | 4 +- ...icationZeroThresholdFundingStochastic.java | 4 +- ...SetOffCollateralizedFundingStochastic.java | 4 +- ...tOffUncollateralizedFundingStochastic.java | 4 +- .../SetOffZeroThresholdFundingStochastic.java | 4 +- ...ralCSACollateralizedFundingStochastic.java | 4 +- ...lCSAUncollateralizedFundingStochastic.java | 4 +- ...eralCSAZeroThresholdFundingStochastic.java | 4 +- .../conditionnumber/TriangleMatrix.java | 4 +- .../sample/digamma/UnitImaginaryEstimate.java | 4 +- .../helitterman/Table4DetailedBlowout.java | 28 +- .../sample/matrix/CholeskyFactorization.java | 8 +- .../sample/matrix/GershgorinAnalysis.java | 6 +- .../sample/matrix/GrahamSchmidtProcess.java | 18 +- .../org/drip/sample/matrix/LinearAlgebra.java | 4 +- .../drip/sample/matrix/QRDecomposition.java | 6 +- .../drip/sample/matrix/RayleighQuotient.java | 12 +- .../SylvesterInterpolantReconciler.java | 12 +- .../OTCPayerAggressiveTimeline.java | 4 +- .../OTCPayerClassicalMinusTimeline.java | 4 +- .../OTCPayerClassicalPlusTimeline.java | 4 +- .../OTCPayerConservativeTimeline.java | 4 +- .../OTCReceiverAggressiveTimeline.java | 4 +- .../OTCReceiverClassicalMinusTimeline.java | 4 +- .../OTCReceiverClassicalPlusTimeline.java | 4 +- .../OTCReceiverConservativeTimeline.java | 4 +- .../OTCPayerCSAAggressive.java | 4 +- .../OTCPayerCSAClassicalMinus.java | 4 +- .../OTCPayerCSAClassicalPlus.java | 4 +- .../OTCPayerCSAConservative.java | 4 +- .../OTCReceiverCSAAggressive.java | 4 +- .../OTCReceiverCSAClassicalMinus.java | 4 +- .../OTCReceiverCSAClassicalPlus.java | 4 +- .../OTCReceiverCSAConservative.java | 4 +- .../LongFixedAggressiveTimeline.java | 4 +- .../LongFixedClassicalMinusTimeline.java | 4 +- .../LongFixedClassicalPlusTimeline.java | 4 +- .../LongFixedConservativeTimeline.java | 4 +- .../LongFloatAggressiveTimeline.java | 4 +- .../LongFloatClassicalMinusTimeline.java | 4 +- .../LongFloatClassicalPlusTimeline.java | 4 +- .../LongFloatConservativeTimeline.java | 4 +- .../ShortFixedAggressiveTimeline.java | 4 +- .../ShortFixedClassicalMinusTimeline.java | 4 +- .../ShortFixedClassicalPlusTimeline.java | 4 +- .../ShortFixedConservativeTimeline.java | 4 +- .../ShortFloatAggressiveTimeline.java | 4 +- .../ShortFloatClassicalMinusTimeline.java | 4 +- .../ShortFloatClassicalPlusTimeline.java | 4 +- .../ShortFloatConservativeTimeline.java | 4 +- .../PortfolioPathAggregationCorrelated.java | 4 +- .../sample/numeraire/R1JointDiffusion.java | 4 +- .../numeraire/R1JointJumpDiffusion.java | 4 +- .../ExposurePathBrownianBridge.java | 4 +- .../pykhtin2009/ExposurePathFixFloat.java | 4 +- .../ExposurePathLocalVolatility.java | 4 +- .../drip/sample/securitysuite/Bhilwara.java | 4 +- .../org/drip/sample/securitysuite/Dhule.java | 4 +- .../org/drip/sample/securitysuite/Korba.java | 4 +- .../org/drip/sample/securitysuite/Rohtak.java | 4 +- .../drip/sample/securitysuite/Tirupati.java | 4 +- .../CrossGroupPrincipalCovariance.java | 6 +- .../org/drip/sample/sor/DULDecomposition.java | 10 +- .../sample/sor/MatrixConditioningChecks.java | 14 +- .../triangular/AtomicLowerUnitriangular.java | 4 +- .../triangular/AtomicUpperUnitriangular.java | 4 +- .../org/drip/sample/triangular/Diagonal.java | 4 +- .../org/drip/sample/triangular/Lower.java | 4 +- .../sample/triangular/LowerSolverSuite.java | 10 +- .../sample/triangular/LowerUnitriangular.java | 4 +- .../drip/sample/triangular/StrictlyLower.java | 4 +- .../drip/sample/triangular/StrictlyUpper.java | 4 +- .../org/drip/sample/triangular/Upper.java | 4 +- .../sample/triangular/UpperSolverSuite.java | 10 +- .../sample/triangular/UpperUnitriangular.java | 4 +- .../tridiagonal/NonPeriodicSolverSuite.java | 4 +- .../PeriodicRyabenkiiTsynkovSolverSuite.java | 4 +- .../PeriodicShermanMorrisonSolverSuite.java | 4 +- ...llateralizedCollateralGroupCorrelated.java | 4 +- ...llateralizedCollateralGroupCorrelated.java | 4 +- ...eroThresholdCollateralGroupCorrelated.java | 4 +- ...ateralizedCollateralNeutralStochastic.java | 4 +- ...ateralizedCollateralPayableStochastic.java | 4 +- ...ralizedCollateralReceivableStochastic.java | 4 +- ...ollateralizedFundingNeutralStochastic.java | 4 +- ...ollateralizedFundingPayableStochastic.java | 4 +- ...ateralizedFundingReceivableStochastic.java | 4 +- ...ollateralizedNettingNeutralStochastic.java | 4 +- ...ollateralizedNettingPayableStochastic.java | 4 +- ...ateralizedNettingReceivableStochastic.java | 4 +- ...ateralizedCollateralNeutralStochastic.java | 4 +- ...ateralizedCollateralPayableStochastic.java | 4 +- ...ralizedCollateralReceivableStochastic.java | 4 +- ...ollateralizedFundingNeutralStochastic.java | 4 +- ...ollateralizedFundingPayableStochastic.java | 4 +- ...ateralizedFundingReceivableStochastic.java | 4 +- ...ollateralizedNettingNeutralStochastic.java | 4 +- ...ollateralizedNettingPayableStochastic.java | 4 +- ...ateralizedNettingReceivableStochastic.java | 4 +- ...oThresholdCollateralNeutralStochastic.java | 4 +- ...oThresholdCollateralPayableStochastic.java | 4 +- ...resholdCollateralReceivableStochastic.java | 4 +- ...ZeroThresholdFundingNeutralStochastic.java | 4 +- ...ZeroThresholdFundingPayableStochastic.java | 4 +- ...oThresholdFundingReceivableStochastic.java | 4 +- ...ZeroThresholdNettingNeutralStochastic.java | 4 +- ...ZeroThresholdNettingPayableStochastic.java | 4 +- ...oThresholdNettingReceivableStochastic.java | 4 +- .../CPGACollateralizedCorrelated.java | 4 +- .../CPGAUncollateralizedCorrelated.java | 4 +- .../CPGAZeroThresholdCorrelated.java | 4 +- .../AlbaneseAndersenBaselProxy.java | 4 +- .../xvafixfloat/GoldPlatedBaselProxy.java | 4 +- .../xvafixfloat/HedgeErrorBaselProxy.java | 4 +- .../sample/xvafixfloat/OneWayBaselProxy.java | 4 +- .../SemiReplicationBaselProxy.java | 4 +- .../sample/xvafixfloat/SetOffBaselProxy.java | 4 +- .../random/MultivariateSequenceGenerator.java | 2 +- .../RiskGroupPrincipalCovariance.java | 6 +- .../definition/HankelFirstKindEstimator.java | 10 +- .../definition/HankelSecondKindEstimator.java | 10 +- .../definition/RiccatiBesselXeeEstimator.java | 6 +- .../RiccatiBesselZitaEstimator.java | 6 +- .../SphericalHankelFirstKindEstimator.java | 6 +- .../SphericalHankelSecondKindEstimator.java | 6 +- .../digamma/SpecialValues.java | 6 +- .../group/MonodromyTransform2F1.java | 26 +- .../specialfunction/hankel/BigH1FromBigJ.java | 6 +- .../hankel/BigH1FromBigJBigY.java | 6 +- .../specialfunction/hankel/BigH2FromBigJ.java | 6 +- .../hankel/BigH2FromBigJBigY.java | 6 +- .../drip/specialfunction/hankel/SmallH1.java | 6 +- .../drip/specialfunction/hankel/SmallH2.java | 6 +- .../specialfunction/hankel/XeeFromBigH1.java | 9 +- .../specialfunction/hankel/XeeFromSC.java | 6 +- .../hankel/XeeFromSmallH1.java | 9 +- .../specialfunction/hankel/ZitaFromBigH2.java | 9 +- .../specialfunction/hankel/ZitaFromSC.java | 6 +- .../hankel/ZitaFromSmallH2.java | 9 +- .../org/drip/xva/dynamics/PathSimulator.java | 6 +- 223 files changed, 1945 insertions(+), 1422 deletions(-) create mode 100644 IdeaDRIP/NumericalAnalysis/NA_v0.08 create mode 100644 ReleaseNotes/03_13_2024.txt delete mode 100644 src/main/java/org/drip/function/definition/CartesianComplexNumber.java create mode 100644 src/main/java/org/drip/numerical/complex/C1MatrixUtil.java create mode 100644 src/main/java/org/drip/numerical/complex/CartesianC1.java create mode 100644 src/main/java/org/drip/numerical/complex/package-info.java rename src/main/java/org/drip/numerical/linearalgebra/{MatrixUtil.java => R1MatrixUtil.java} (96%) rename src/main/java/org/drip/numerical/{linearalgebra/NonPeriodicTridiagonalMatrix.java => matrix/R1NonPeriodicTridiagonal.java} (89%) rename src/main/java/org/drip/numerical/{linearalgebra/PeriodicTridiagonalMatrix.java => matrix/R1PeriodicTridiagonal.java} (89%) rename src/main/java/org/drip/numerical/{linearalgebra/SquareMatrix.java => matrix/R1Square.java} (89%) rename src/main/java/org/drip/numerical/{linearalgebra/TriangularMatrix.java => matrix/R1Triangular.java} (95%) rename src/main/java/org/drip/numerical/{linearalgebra/TridiagonalMatrix.java => matrix/R1Tridiagonal.java} (92%) create mode 100644 src/main/java/org/drip/numerical/matrix/package-info.java diff --git a/IdeaDRIP/NumericalAnalysis/NA_v0.08 b/IdeaDRIP/NumericalAnalysis/NA_v0.08 new file mode 100644 index 000000000000..71552a141405 --- /dev/null +++ b/IdeaDRIP/NumericalAnalysis/NA_v0.08 @@ -0,0 +1,211 @@ + + -------------------------- + #1 - Successive Over-Relaxation + -------------------------- + -------------------------- + 1.1) Successive Over-Relaxation Method for A.x = b; A - n x n square matrix, x - unknown vector, b - RHS vector + 1.2) Decompose A into Diagonal, Lower, and upper Triangular Matrices; A = D + L + U + 1.3) SOR Scheme uses omega input + 1.4) Forward subsitution scheme to iteratively determine the x_i's + 1.5) SOR Scheme Linear System Convergence: Inputs A and D, Jacobi Iteration Matrix Spectral Radius, omega + - Construct Jacobi Iteration Matrix: C_Jacobian = I - (Inverse D) A + - Convergence Verification #1: Ensure that Jacobi Iteration Matrix Spectral Radius is < 1 + - Convergence Verification #2: Ensure omega between 0 and 2 + - Optimal Relaxation Parameter Expression in terms of Jacobi Iteration Matrix Spectral Radius + - Omega Based Convergence Rate Expression + - Gauss-Seidel omega = 1; corresponding Convergence Rate + - Optimal Omega Convergence Rate + 1.6) Generic Iterative Solver Method: + - Inputs: Iterator Function(x) and omega + - Unrelaxed Iterated variable: x_n+1 = f(x_n) + - SOR Based Iterated variable: x_n+1 = (1-omega).x_n + omega.f(x_n) + - SOR Based Iterated variable for Unknown Vector x: x_n+1 = (1-omega).x_n + omega.(L_star inverse)(b - U.x_n) + -------------------------- + + -------------------------- + #2 - Successive Over-Relaxation + -------------------------- + -------------------------- + 2.1) SSOR Algorithm - Inputs; A, omega, and gamma + - Decompose into D and L + - Pre-conditioner Matrix: Expression from SSOR + - Finally SSOR Iteration Formula + -------------------------- + + ---------------------------- + #7 - Tridiagonal matrix algorithm + ---------------------------- + ---------------------------- + 7.1) Is Tridiagonal Check + 7.2) Core Algorithm: + - C Prime's and D Prime's Calculation + - Back Substitution for the Result + - Modified better Book-keeping algorithm + 7.3) Sherman-Morrison Algorithm: + - Choice of gamma + - Construct Tridiagonal B from A and gamma + - u Column from gamma and c_n + - v Column from a_1 and gamma + - Solve for y from By=d + - Solve for q from Bq=u + - Use Sherman Morrison Formula to extract x + 7.4) Alternate Boundary Condition Algorithm: + - Solve Au=d for u + - Solve Av={-a_2, 0, ..., -c_n} for v + - Full solution is x_i = u_i + x_1 * v_i + - x_1 if computed using formula + ---------------------------- + + ---------------------------- + #8 - Triangular Matrix + ---------------------------- + ---------------------------- + 8.1) Description: + - Lower/Left Triangular Verification + - Upper/Right Triangular Verification + - Diagonal Matrix Verification + - Upper/Lower Trapezoidal Verification + 8.2) Forward/Back Substitution: + - Inputs => L and b + - Forward Substitution + - Inputs => U and b + - Back Substitution + 8.3) Properties: + - Is Matrix Normal, i.e., A times A transpose = A transpose times A + - Characteristic Polynomial + - Determinant/Permanent + 8.4) Special Forms: + - Upper/Lower Unitriangular Matrix Verification + - Upper/Lower Strictly Matrix Verification + - Upper/Lower Atomic Matrix Verification + ---------------------------- + + ---------------------------- + #9 - Sylvester Equation + ---------------------------- + ---------------------------- + 9.1) Matrix Form: + - Inputs: A, B, and C + - Size Constraints Verification + 9.2) Solution Criteria: + - Co-joint EigenSpectrum between A and B + 9.3) Numerical Solution: + - Decomposition of A/B using Schur Decomposition into Triangular Form + - Forward/Back Substitution + ---------------------------- + + ---------------------------- + #10 - Bartels-Stewart Algorithm + ---------------------------- + ---------------------------- + 10.1) Matrix Form: + - Inputs: A, B, and C + - Size Constraints Verification + 10.2) Schur Decompositions: + - R = U^T A U - emits U and R + - S = V^T B^T V - emits V and S + - F = U^T C V + - Y = U^T X V + - Solution to R.Y - Y.S^T = F + - Finally X = U.Y.V^T + 10.3) Computational Costs: + - Flops cost for Schur decomposition + - Flops cost overall + 10.4) Hessenberg-Schur Decompositions: + - R = U^T A U becomes H = Q^T A Q - thus emits Q and H (Upper Hessenberg) + - Computational Costs + ---------------------------- + + ---------------------------- + #11 - Gershgorin Circle Theorem + ---------------------------- + ---------------------------- + 11.1) Gershgorin Disc: + - Diagonal Entry + - Radius + - One disc per Row/Column in Square Matrix + - Optimal Disc based on Row/Column + 11.2) Tolerance based Gershgorin Convergence Criterion + 11.3) Joint and Disjoint Discs + 11.4) Gershgorin Strengthener + 11.5) Row/Column Diagonal Dominance + ---------------------------- + + ---------------------------- + #12 - Condition Number + ---------------------------- + ---------------------------- + 12.1) Condition Number Calculation: + - Absolute Error + - Relative Error + - Absolute Condition Number + - Relative Condition Number + 12.2) Matrix Condition Number Calculation: + - Condition Number as a Product of Regular and Inverse Norms + - L2 Norm + - L2 Norm for Normal Matrix + - L2 Norm for Unitary Matrix + - Default Condition Number + - L Infinity Norm + - L Infinity Norm Triangular Matrix + 12.3) Non-linear + - One Variable + - Basic Formula + - Condition Numbers for Common Functions + - Multi Variables + ---------------------------- + + ---------------------------- + #13 - Unitary Matrix + ---------------------------- + ---------------------------- + 13.1) Properties: + - U.U conjugate = I defines unitary matrix + - U.U conjugate = U conjugate.U = I + - det U = 1 + - Eigenvectors are orthogonal + - U conjugate = U inverse + - Norm (U.x) = Norm (x) + - Normal Matrix U + 13.2) 2x2 Elementary Matrices + - Wiki Representation #1 + - Wiki Representation #2 + - Wiki Representation #3 + - Wiki Representation #4 + ---------------------------- + + -------------------------- + #14 - Crank–Nicolson method + -------------------------- + -------------------------- + 14.1) von Neumann Stability Validator - Inputs; time-step, diffusivity, space step + - 1D => time step * diffusivity / space step ^2 < 0.5 + - nD => time step * diffusivity / (space step hypotenuse) ^ 2 < 0.5 + 14.2) Set up: + - Input: Spatial variable x + - Input: Time variable t + - Inputs: State variable u, du/dx, d2u/dx2 - all at time t + - Second Order, 1D => du/dt = F (u, x, t, du/dx, d2u/dx2) + 14.3) Finite Difference Evolution Scheme: + - Time Step delta_t, space step delta_x + - Forward Difference: F calculated at x + - Backward Difference: F calculated at x + delta_x + - Crank Nicolson: Average of Forward/Backward + 14.4) 1D Diffusion: + - Inputs: 1D von Neumann Stability Validator, Number of time/space steps + - Time Index n, Space Index i + - Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n + - Non-linear diffusion coefficient: + - Linearization across x_i and x_i+1 + - Quasi-explicit forms accommodation + 14.5) 2D Diffusion: + - Inputs: 2D von Neumann Stability Validator, Number of time/space steps + - Time Index n, Space Index i, j + - Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n + - Explicit Solution using the Alternative Difference Implicit Scheme + 14.6) Extension to Iterative Solver Schemes above: + - Input: State Space "velocity" dF/du + - Input: State "Step Size" delta_u + - Fixed Point Iterative Location Scheme + - Relaxation Scheme based Robustness => Input: Relaxation Parameter + -------------------------- diff --git a/ReleaseNotes/03_13_2024.txt b/ReleaseNotes/03_13_2024.txt new file mode 100644 index 000000000000..16be225688ee --- /dev/null +++ b/ReleaseNotes/03_13_2024.txt @@ -0,0 +1,52 @@ + +Features: + + - Implementation of R1/C1 Matrices (8, 9) + - Numerical R^1 Square Matrix Re-work (10, 11, 12) + - Numerical R^1 Tridiagonal Matrix Re-work (13, 14) + - Numerical R^1 Non-periodic Tridiagonal Matrix Re-work (15, 16) + - Numerical R^1 Periodic Tridiagonal Matrix Re-work (17, 18) + - Numerical R^1 Triangular Matrix Re-work (19, 20, 21) + - Linear Algebra R^1 Matrix Util (22, 23, 24) + - Implementation of Complex Number Suite (25) + - Numerical Complex C1 Shell #1 (26, 27, 28) + - Numerical Complex C1 Shell #2 (29, 30, 31) + - Numerical Complex Cartesian C1 Re-work (32, 33, 34) + - Numerical Complex C1 Cartesian Re-work (35, 36) + - C1 Matrix Util Add #1 (37, 38, 39) + - C1 Matrix Util Add #2 (40, 41, 42) + - C1 Matrix Util Add #3 (43, 44, 45) + - C1 Matrix Util Add #4 (46, 47, 48) + - C1 Matrix Util Scale #1 (49, 50, 51) + - C1 Matrix Util Scale #2 (52, 53, 54) + - C1 Matrix Util Scale #3 (55, 56, 57) + - C1 Matrix Util Scale #4 (58, 59, 60) + - C1 Matrix Util Subtract #1 (61, 62, 63) + - C1 Matrix Util Subtract #2 (64, 65, 66) + - C1 Matrix Util Subtract #3 (67, 68, 69) + - C1 Matrix Util Subtract #4 (70, 71, 72) + - C1 Matrix Util Multiply #1 (73, 74, 75) + - C1 Matrix Util Multiply #2 (76, 77, 78) + - C1 Matrix Util Multiply #3 (79, 80, 81) + - C1 Matrix Util Multiply #4 (82, 83, 84) + - C1 Matrix Util Divide #1 (85, 86, 87) + - C1 Matrix Util Divide #2 (88, 89, 90) + - C1 Matrix Util Divide #3 (91, 92, 93) + - C1 Matrix Util Divide #4 (94, 95, 96) + - C1 Matrix Util Square #1 (97, 98, 99) + - C1 Matrix Util Square #2 (100, 101, 102) + - C1 Matrix Util Square #3 (103, 104, 105) + - C1 Matrix Util Square #4 (106, 107, 108) + - C1 Matrix Util Square Root #1 (109, 110, 111) + - C1 Matrix Util Square Root #2 (112, 113, 114) + - C1 Matrix Util Square Root #3 (115, 116, 117) + - C1 Matrix Util Square Root #4 (118, 119, 120) + + +Bug Fixes/Re-organization: + +Samples: + +IdeaDRIP: + + - Unitary Matrix Elementary Constructions - 2x2 (1-7) diff --git a/src/main/java/org/drip/dynamics/kolmogorov/RdFokkerPlanck.java b/src/main/java/org/drip/dynamics/kolmogorov/RdFokkerPlanck.java index 6117bea35619..e601cf9ae60c 100644 --- a/src/main/java/org/drip/dynamics/kolmogorov/RdFokkerPlanck.java +++ b/src/main/java/org/drip/dynamics/kolmogorov/RdFokkerPlanck.java @@ -346,7 +346,7 @@ public org.drip.function.definition.RdToR1 steadyStatePDF() ); final double[][] omegaInverse = - org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination ( + org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination ( omega ); @@ -406,9 +406,9 @@ public org.drip.function.definition.RdToR1 steadyStatePDF() throws java.lang.Exception { return rdNormalizerFinal * r1ToR1Exponential.evaluate ( - org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( xArray, - org.drip.numerical.linearalgebra.MatrixUtil.Product ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( omegaInverse, xArray ) diff --git a/src/main/java/org/drip/dynamics/process/RdStochasticEvolver.java b/src/main/java/org/drip/dynamics/process/RdStochasticEvolver.java index ed65ae717c07..c165e6abab95 100644 --- a/src/main/java/org/drip/dynamics/process/RdStochasticEvolver.java +++ b/src/main/java/org/drip/dynamics/process/RdStochasticEvolver.java @@ -306,7 +306,7 @@ public org.drip.dynamics.ito.TimeRdVertex evolve ( return null; } - double[] volatilityShiftArray = org.drip.numerical.linearalgebra.MatrixUtil.Product ( + double[] volatilityShiftArray = org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( pointVolatilityGrid ( currentVertex ), diff --git a/src/main/java/org/drip/function/definition/CartesianComplexNumber.java b/src/main/java/org/drip/function/definition/CartesianComplexNumber.java deleted file mode 100644 index 8deeb5dcf039..000000000000 --- a/src/main/java/org/drip/function/definition/CartesianComplexNumber.java +++ /dev/null @@ -1,587 +0,0 @@ - -package org.drip.function.definition; - -/* - * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - */ - -/*! - * Copyright (C) 2022 Lakshmi Krishnamurthy - * Copyright (C) 2021 Lakshmi Krishnamurthy - * Copyright (C) 2020 Lakshmi Krishnamurthy - * Copyright (C) 2019 Lakshmi Krishnamurthy - * Copyright (C) 2018 Lakshmi Krishnamurthy - * Copyright (C) 2017 Lakshmi Krishnamurthy - * Copyright (C) 2016 Lakshmi Krishnamurthy - * Copyright (C) 2015 Lakshmi Krishnamurthy - * Copyright (C) 2014 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. - */ - -/** - * CartesianComplexNumber implements the functionality for dealing with the Cartesian Form of Complex - * Numbers. - * - *

- * - *

- * - * @author Lakshmi Krishnamurthy - */ - -public class CartesianComplexNumber -{ - private double _real = java.lang.Double.NaN; - private double _imaginary = java.lang.Double.NaN; - - /** - * Add the 2 Complex Numbers - * - * @param complexNumber1 The First Complex Number - * @param complexNumber2 The Second Complex Number - * - * @return The Complex Number instance that is a sum of the two - */ - - public static final CartesianComplexNumber Add ( - final CartesianComplexNumber complexNumber1, - final CartesianComplexNumber complexNumber2) - { - if (null == complexNumber1 || null == complexNumber2) - { - return null; - } - - try - { - return new CartesianComplexNumber ( - complexNumber1.real() + complexNumber2.real(), - complexNumber1.imaginary() + complexNumber2.imaginary() - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Scale the Complex Number with the factor - * - * @param complexNumber The Complex Number - * @param scale The Scaling Factor - * - * @return The Scaled Complex Number - */ - - public static final CartesianComplexNumber Scale ( - final CartesianComplexNumber complexNumber, - final double scale) - { - if (null == complexNumber || !org.drip.numerical.common.NumberUtil.IsValid (scale)) - { - return null; - } - - try - { - return new CartesianComplexNumber ( - scale * complexNumber.real(), - scale * complexNumber.imaginary() - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Subtract the Second Complex Number from the First - * - * @param complexNumber1 The First Complex Number - * @param complexNumber2 The Second Complex Number - * - * @return The "Difference" Complex Number - */ - - public static final CartesianComplexNumber Subtract ( - final CartesianComplexNumber complexNumber1, - final CartesianComplexNumber complexNumber2) - { - if (null == complexNumber1 || null == complexNumber2) - { - return null; - } - - try { - return new CartesianComplexNumber ( - complexNumber1.real() - complexNumber2.real(), - complexNumber1.imaginary() - complexNumber2.imaginary() - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Multiply the 2 Complex Numbers - * - * @param complexNumber1 The First Complex Number - * @param complexNumber2 The Second Complex Number - * - * @return The Complex Number instance that is a product of the two - */ - - public static final CartesianComplexNumber Multiply ( - final CartesianComplexNumber complexNumber1, - final CartesianComplexNumber complexNumber2) - { - if (null == complexNumber1 || null == complexNumber2) - { - return null; - } - - double real1 = complexNumber1.real(); - - double real2 = complexNumber2.real(); - - double imaginary1 = complexNumber1.imaginary(); - - double imaginary2 = complexNumber2.imaginary(); - - try - { - return new CartesianComplexNumber ( - real1 * real2 - imaginary1 * imaginary2, - real1 * imaginary2 + real2 * imaginary1 - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Divide the Numerator Complex Number by the Denominator Complex Number - * - * @param numerator The Numerator Complex Number - * @param denominator The Denominator Complex Number - * - * @return The "Divided" Complex Number - */ - - public static final CartesianComplexNumber Divide ( - final CartesianComplexNumber numerator, - final CartesianComplexNumber denominator) - { - if (null == numerator || null == denominator) - { - return null; - } - - double numeratorReal = numerator.real(); - - double denominatorReal = denominator.real(); - - double numeratorImaginary = numerator.imaginary(); - - double denominatorImaginary = denominator.imaginary(); - - if (0. == denominatorReal && 0. == denominatorImaginary) - { - return null; - } - - double inverseDenominatorModulus = 1. / denominator.modulus(); - - try - { - return new CartesianComplexNumber ( - (numeratorReal * denominatorReal + numeratorImaginary * denominatorImaginary) * - inverseDenominatorModulus, - (denominatorReal * numeratorImaginary - numeratorReal * denominatorImaginary) * - inverseDenominatorModulus - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Square the Complex Number - * - * @param complexNumber The Complex Number - * - * @return The Squared Complex Number Instance - */ - - public static final CartesianComplexNumber Square ( - final CartesianComplexNumber complexNumber) - { - if (null == complexNumber) - { - return null; - } - - double modulus = complexNumber.modulus(); - - if (0. == modulus) - { - try - { - return new CartesianComplexNumber ( - 0., - 0. - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - double argument = 2. * complexNumber.argument(); - - try - { - return new CartesianComplexNumber ( - modulus * java.lang.Math.cos (argument), - modulus * java.lang.Math.sin (argument) - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Compute the Square Root of the Complex Number - * - * @param complexNumber The Complex Number - * - * @return The Square Root Complex Number Instance - */ - - public static final CartesianComplexNumber SquareRoot ( - final CartesianComplexNumber complexNumber) - { - if (null == complexNumber) - { - return null; - } - - double modulus = java.lang.Math.sqrt (complexNumber.modulus()); - - if (0. == modulus) - { - try - { - return new CartesianComplexNumber ( - 0., - 0. - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - double argument = 0.5 * complexNumber.argument(); - - try - { - return new CartesianComplexNumber ( - modulus * java.lang.Math.cos (argument), - modulus * java.lang.Math.sin (argument) - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Exponentiate the Complex Number - * - * @param complexNumber The Complex Number - * - * @return The Exponentiated Complex Number Instance - */ - - public static final CartesianComplexNumber Exponentiate ( - final CartesianComplexNumber complexNumber) - { - if (null == complexNumber) - { - return null; - } - - double argument = complexNumber.imaginary(); - - double modulus = java.lang.Math.exp (complexNumber.real()); - - try - { - return new CartesianComplexNumber ( - modulus * java.lang.Math.cos (argument), - modulus * java.lang.Math.sin (argument) - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Compute Logarithm of the Complex Number - * - * @param complexNumber The Complex Number - * - * @return The Complex Number Logarithm Instance - */ - - public static final CartesianComplexNumber Logarithm ( - final CartesianComplexNumber complexNumber) - { - if (null == complexNumber) - { - return null; - } - - double modulus = complexNumber.modulus(); - - if (0. == modulus) - { - return null; - } - - try - { - return new CartesianComplexNumber ( - 0.5 * java.lang.Math.log (modulus), - complexNumber.argument() - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * Construct the Complex Number from its Polar Representation - * - * @param r r - * @param theta theta - * - * @return Complex Number from its Polar Representation - */ - - public static final CartesianComplexNumber FromPolar ( - final double r, - final double theta) - { - try - { - return !org.drip.numerical.common.NumberUtil.IsValid (r) || - !org.drip.numerical.common.NumberUtil.IsValid (theta) ? null : - new CartesianComplexNumber ( - r * java.lang.Math.cos (theta), - r * java.lang.Math.sin (theta) - ); - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * CartesianComplexNumber constructor - * - * @param real Real Part - * @param imaginary Imaginary Part - * - * @throws java.lang.Exception Thrown if the Inputs are invalid - */ - - public CartesianComplexNumber ( - final double real, - final double imaginary) - throws java.lang.Exception - { - if (!org.drip.numerical.common.NumberUtil.IsValid (_real = real) || - !org.drip.numerical.common.NumberUtil.IsValid (_imaginary = imaginary)) - { - throw new java.lang.Exception ("CartesianComplexNumber Constructor => Invalid Inputs"); - } - } - - /** - * Retrieve the Real Part - * - * @return The Real Part - */ - - public double real() - { - return _real; - } - - /** - * Retrieve the Imaginary Part - * - * @return The Imaginary Part - */ - - public double imaginary() - { - return _imaginary; - } - - /** - * Retrieve the Modulus - * - * @return The Modulus - */ - - public double modulus() - { - return _real * _real + _imaginary * _imaginary; - } - - /** - * Retrieve the Absolute Value - * - * @return The Absolute Value - */ - - public double abs() - { - return java.lang.Math.sqrt (modulus()); - } - - /** - * Retrieve the Argument - * - * @return The Argument - */ - - public double argument() - { - return 0. == _real && 0. == _imaginary ? 0. : java.lang.Math.atan (_imaginary / _real); - } - - /** - * Display the Real/Imaginary Contents - * - * @return The Real/Imaginary Contents - */ - - public java.lang.String display() - { - return "\t[" + _real + ", " + _imaginary + "]"; - } -} diff --git a/src/main/java/org/drip/function/definition/R2ToZ1.java b/src/main/java/org/drip/function/definition/R2ToZ1.java index 4938afee0acb..3a86b897c652 100644 --- a/src/main/java/org/drip/function/definition/R2ToZ1.java +++ b/src/main/java/org/drip/function/definition/R2ToZ1.java @@ -126,7 +126,7 @@ public interface R2ToZ1 * @return Returns the Calculated Complex Value */ - public abstract org.drip.function.definition.CartesianComplexNumber evaluate ( + public abstract org.drip.numerical.complex.CartesianC1 evaluate ( final double x, final double y); } diff --git a/src/main/java/org/drip/function/matrix/Square.java b/src/main/java/org/drip/function/matrix/Square.java index f0d4ca4058e5..1d9f685b2f7f 100644 --- a/src/main/java/org/drip/function/matrix/Square.java +++ b/src/main/java/org/drip/function/matrix/Square.java @@ -272,15 +272,15 @@ public org.drip.function.matrix.FrobeniusCovariance frobeniusCovariance() if (null == frobeniusComponentMatrix) { - frobeniusComponentMatrix = org.drip.numerical.linearalgebra.MatrixUtil.Scale2D ( + frobeniusComponentMatrix = org.drip.numerical.linearalgebra.R1MatrixUtil.Scale2D ( eigenShadowArray[eigenIndex], 1. / (componentEigenValue - eigenValueArray[eigenIndex]) ); } else { - frobeniusComponentMatrix = org.drip.numerical.linearalgebra.MatrixUtil.Scale2D ( - org.drip.numerical.linearalgebra.MatrixUtil.Product ( + frobeniusComponentMatrix = org.drip.numerical.linearalgebra.R1MatrixUtil.Scale2D ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( frobeniusComponentMatrix, eigenShadowArray[eigenIndex] ), @@ -343,7 +343,7 @@ public double[][] evaluate ( try { - frobeniusComponentFunctionProjection = org.drip.numerical.linearalgebra.MatrixUtil.Scale2D ( + frobeniusComponentFunctionProjection = org.drip.numerical.linearalgebra.R1MatrixUtil.Scale2D ( componentMapEntry.getValue().grid(), r1ToR1Function.evaluate ( componentMapEntry.getKey() diff --git a/src/main/java/org/drip/function/rdtor1descent/ArmijoEvolutionVerifierMetrics.java b/src/main/java/org/drip/function/rdtor1descent/ArmijoEvolutionVerifierMetrics.java index 967309d6caad..a3eacbccf162 100644 --- a/src/main/java/org/drip/function/rdtor1descent/ArmijoEvolutionVerifierMetrics.java +++ b/src/main/java/org/drip/function/rdtor1descent/ArmijoEvolutionVerifierMetrics.java @@ -209,7 +209,7 @@ public boolean verify() try { double gradientUpdatedFunctionValue = _currentVariateFunctionValue + - _armijoParameter * stepLength() * org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + _armijoParameter * stepLength() * org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirection().component(), currentVariateFunctionJacobian() ); diff --git a/src/main/java/org/drip/function/rdtor1descent/CurvatureEvolutionVerifierMetrics.java b/src/main/java/org/drip/function/rdtor1descent/CurvatureEvolutionVerifierMetrics.java index 3578c4dc13fb..d1f0d907e40e 100644 --- a/src/main/java/org/drip/function/rdtor1descent/CurvatureEvolutionVerifierMetrics.java +++ b/src/main/java/org/drip/function/rdtor1descent/CurvatureEvolutionVerifierMetrics.java @@ -200,13 +200,13 @@ public boolean verify() try { - double nextFunctionIncrement = org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + double nextFunctionIncrement = org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirectionVector, _nextVariateFunctionJacobian ); double parametrizedCurrentFunctionIncrement = - _curvatureParameter * org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + _curvatureParameter * org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirectionVector, currentVariateFunctionJacobian() ); diff --git a/src/main/java/org/drip/function/rdtor1descent/WolfeEvolutionVerifierMetrics.java b/src/main/java/org/drip/function/rdtor1descent/WolfeEvolutionVerifierMetrics.java index aaa7a09f8c8b..9ba3a77bea1e 100644 --- a/src/main/java/org/drip/function/rdtor1descent/WolfeEvolutionVerifierMetrics.java +++ b/src/main/java/org/drip/function/rdtor1descent/WolfeEvolutionVerifierMetrics.java @@ -270,7 +270,7 @@ public boolean verify() try { double gradientUpdatedFunctionValue = _currentVariateFunctionValue + - _armijoParameter * stepLength() * org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + _armijoParameter * stepLength() * org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirectionVector, currentVariateFunctionJacobian ); @@ -281,13 +281,13 @@ public boolean verify() return false; } - double nextFunctionIncrement = org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + double nextFunctionIncrement = org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirectionVector, _nextVariateFunctionJacobian ); double parametrizedCurrentFunctionIncrement = _curvatureParameter * - org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( targetDirectionVector, currentVariateFunctionJacobian ); diff --git a/src/main/java/org/drip/function/rdtor1solver/NewtonFixedPointFinder.java b/src/main/java/org/drip/function/rdtor1solver/NewtonFixedPointFinder.java index 0b3598049ab6..e6c698785c47 100644 --- a/src/main/java/org/drip/function/rdtor1solver/NewtonFixedPointFinder.java +++ b/src/main/java/org/drip/function/rdtor1solver/NewtonFixedPointFinder.java @@ -133,8 +133,8 @@ public NewtonFixedPointFinder ( org.drip.function.definition.RdToR1 objectiveFunction = objectiveFunction(); - double[] variateIncrementArray = org.drip.numerical.linearalgebra.MatrixUtil.Product ( - org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination ( + double[] variateIncrementArray = org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( + org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination ( objectiveFunction.hessian ( variateArray ) diff --git a/src/main/java/org/drip/measure/bayesian/ProjectionDistributionLoading.java b/src/main/java/org/drip/measure/bayesian/ProjectionDistributionLoading.java index e22dfcf31a2f..0e09c5a5ce27 100644 --- a/src/main/java/org/drip/measure/bayesian/ProjectionDistributionLoading.java +++ b/src/main/java/org/drip/measure/bayesian/ProjectionDistributionLoading.java @@ -127,8 +127,8 @@ public static final double[][] ProjectionCovariance ( for (int j = 0; j < iNumProjection; ++j) { try { aadblProjectionCovariance[i][j] = i != j ? 0. : dblTau * - org.drip.numerical.linearalgebra.MatrixUtil.DotProduct (aadblScopingLoading[i], - org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblScopingCovariance, + org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct (aadblScopingLoading[i], + org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingCovariance, aadblScopingLoading[j])); } catch (java.lang.Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/drip/measure/bayesian/R1MultivariateNormalConvolutionEngine.java b/src/main/java/org/drip/measure/bayesian/R1MultivariateNormalConvolutionEngine.java index d1ecda204382..bf9bc64d167c 100644 --- a/src/main/java/org/drip/measure/bayesian/R1MultivariateNormalConvolutionEngine.java +++ b/src/main/java/org/drip/measure/bayesian/R1MultivariateNormalConvolutionEngine.java @@ -133,12 +133,12 @@ public R1MultivariateNormalConvolutionEngine() if (aadblPriorPrecision.length != iNumVariate) return null; - double[] adblPrecisionWeightedPriorMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblPrecisionWeightedPriorMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblPriorPrecision, r1mnPrior.mean()); if (null == adblPrecisionWeightedPriorMean) return null; - double[] adblPrecisionWeightedConditionalMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblPrecisionWeightedConditionalMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblConditionalPrecision, r1mnConditional.mean()); if (null == adblPrecisionWeightedConditionalMean) return null; @@ -150,10 +150,10 @@ public R1MultivariateNormalConvolutionEngine() aadblJointPrecision[i][j] = aadblPriorPrecision[i][j] + aadblConditionalPrecision[i][j]; } - double[][] aadblJointCovariance = org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination + double[][] aadblJointCovariance = org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination (aadblJointPrecision); - double[] adblJointPosteriorMean = org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblJointCovariance, + double[] adblJointPosteriorMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblJointCovariance, adblJointMean); double[][] aadblUnconditionalCovariance = r1mnUnconditional.covariance().covarianceMatrix(); diff --git a/src/main/java/org/drip/measure/bayesian/TheilMixedEstimationModel.java b/src/main/java/org/drip/measure/bayesian/TheilMixedEstimationModel.java index d58aa5416681..ace3cef4dd43 100644 --- a/src/main/java/org/drip/measure/bayesian/TheilMixedEstimationModel.java +++ b/src/main/java/org/drip/measure/bayesian/TheilMixedEstimationModel.java @@ -147,26 +147,26 @@ public static final org.drip.measure.bayesian.R1MultivariateConvolutionMetrics G double[][] aadblScopingLoading2 = pdl2.scopingLoading(); - double[][] aadblScopingWeightedPrecision1 = org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblScopingLoading1), + double[][] aadblScopingWeightedPrecision1 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading1), r1mn1.covariance().precisionMatrix()); - double[][] aadblScopingWeightedPrecision2 = org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblScopingLoading2), + double[][] aadblScopingWeightedPrecision2 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading2), r1mn2.covariance().precisionMatrix()); - double[][] aadblScopingSpacePrecision1 = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[][] aadblScopingSpacePrecision1 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingWeightedPrecision1, aadblScopingLoading1); - double[][] aadblScopingSpacePrecision2 = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[][] aadblScopingSpacePrecision2 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingWeightedPrecision2, aadblScopingLoading2); if (null == aadblScopingSpacePrecision1 || null == aadblScopingSpacePrecision2) return null; - double[] adblPrecisionWeightedMean1 = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblPrecisionWeightedMean1 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingWeightedPrecision1, r1mn1.mean()); - double[] adblPrecisionWeightedMean2 = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblPrecisionWeightedMean2 = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingWeightedPrecision2, r1mn2.mean()); if (null == adblPrecisionWeightedMean1 || null == adblPrecisionWeightedMean2) return null; @@ -180,10 +180,10 @@ public static final org.drip.measure.bayesian.R1MultivariateConvolutionMetrics G aadblScopingSpacePrecision2[i][j]; } - double[][] aadblJointCovariance = org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination + double[][] aadblJointCovariance = org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination (aadblJointPrecision); - double[] adblJointPosteriorMean = org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblJointCovariance, + double[] adblJointPosteriorMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblJointCovariance, adblJointPrecisionWeightedMean); double[][] aadblUnconditionalCovariance = r1mnUnconditional.covariance().covarianceMatrix(); @@ -276,7 +276,7 @@ public static final double[] ProjectionSpaceScopingMean ( org.drip.measure.bayesian.ProjectionDistributionLoading pdl = spvd.projectionDistributionLoading (strProjection); - return null == pdl ? null : org.drip.numerical.linearalgebra.MatrixUtil.Product (pdl.scopingLoading(), + return null == pdl ? null : org.drip.numerical.linearalgebra.R1MatrixUtil.Product (pdl.scopingLoading(), spvd.scopingDistribution().mean()); } @@ -300,7 +300,7 @@ public static final double[] ProjectionSpaceScopingDifferential ( if (null == pdl) return null; - double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (pdl.scopingLoading(), spvd.scopingDistribution().mean()); if (null == adblProjectionSpaceScopingMean) return null; @@ -347,10 +347,10 @@ public static final org.drip.measure.gaussian.Covariance ProjectionSpaceScopingC double[][] aadblScopingLoading = pdl.scopingLoading(); try { - return new org.drip.measure.gaussian.Covariance (org.drip.numerical.linearalgebra.MatrixUtil.Product - (aadblScopingLoading, org.drip.numerical.linearalgebra.MatrixUtil.Product + return new org.drip.measure.gaussian.Covariance (org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (aadblScopingLoading, org.drip.numerical.linearalgebra.R1MatrixUtil.Product (r1mnScoping.covariance().covarianceMatrix(), - org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblScopingLoading)))); + org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading)))); } catch (java.lang.Exception e) { e.printStackTrace(); } @@ -380,9 +380,9 @@ public static final double[][] ShadowScopingProjectionTranspose ( org.drip.measure.bayesian.ProjectionDistributionLoading pdl = spvd.projectionDistributionLoading (strProjection); - return null == pdl ? null : org.drip.numerical.linearalgebra.MatrixUtil.Product + return null == pdl ? null : org.drip.numerical.linearalgebra.R1MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) r1mScoping).covariance().covarianceMatrix(), - org.drip.numerical.linearalgebra.MatrixUtil.Transpose (pdl.scopingLoading())); + org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (pdl.scopingLoading())); } /** @@ -406,7 +406,7 @@ public static final double[][] ShadowScopingProjection ( (strProjection); return !(r1mScoping instanceof org.drip.measure.gaussian.R1MultivariateNormal) || null == pdl ? null - : org.drip.numerical.linearalgebra.MatrixUtil.Product (pdl.scopingLoading(), + : org.drip.numerical.linearalgebra.R1MatrixUtil.Product (pdl.scopingLoading(), ((org.drip.measure.gaussian.R1MultivariateNormal) r1mScoping).covariance().covarianceMatrix()); } @@ -434,7 +434,7 @@ public static final double[] ProjectionPrecisionMeanProduct ( org.drip.measure.continuous.R1Multivariate r1mProjection = pdl.distribution(); return !(r1mProjection instanceof org.drip.measure.gaussian.R1MultivariateNormal) ? null : - org.drip.numerical.linearalgebra.MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) + org.drip.numerical.linearalgebra.R1MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) r1mProjection).covariance().precisionMatrix(), r1mProjection.mean()); } @@ -467,11 +467,11 @@ public static final double[] ProjectionInducedScopingDeviation ( double[][] aadblScopingLoading = pdl.scopingLoading(); - double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.MatrixUtil.Product - (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.MatrixUtil.Transpose + double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading)); - double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, r1mScoping.mean()); if (null == adblProjectionSpaceScopingMean) return null; @@ -485,10 +485,10 @@ public static final double[] ProjectionInducedScopingDeviation ( adblProjectionSpaceScopingDifferential[i] = adblProjectionMean[i] - adblProjectionSpaceScopingMean[i]; - return org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblProjectionScopingShadow, - org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination - (org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblScopingLoading, + return org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblProjectionScopingShadow, + org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination + (org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, aadblProjectionScopingShadow)), adblProjectionSpaceScopingDifferential)); } @@ -525,11 +525,11 @@ public static final double[] ProjectionInducedScopingMean ( double[][] aadblScopingLoading = pdl.scopingLoading(); - double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.MatrixUtil.Product - (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.MatrixUtil.Transpose + double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading)); - double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, adblScopingMean); if (null == adblProjectionSpaceScopingMean) return null; @@ -544,10 +544,10 @@ public static final double[] ProjectionInducedScopingMean ( adblProjectionSpaceScopingDifferential[i] = adblProjectionMean[i] - adblProjectionSpaceScopingMean[i]; - double[] adblProjectionInducedScopingDeviation = org.drip.numerical.linearalgebra.MatrixUtil.Product - (aadblProjectionScopingShadow, org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination - (org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblScopingLoading, + double[] adblProjectionInducedScopingDeviation = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (aadblProjectionScopingShadow, org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination + (org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, aadblProjectionScopingShadow)), adblProjectionSpaceScopingDifferential)); if (null == adblProjectionInducedScopingDeviation) return null; @@ -585,8 +585,8 @@ public static final double[][] AssetSpaceProjectionCovariance ( double[][] aadblScopingLoading = pdl.scopingLoading(); - return org.drip.numerical.linearalgebra.MatrixUtil.Product (org.drip.numerical.linearalgebra.MatrixUtil.Transpose - (aadblScopingLoading), org.drip.numerical.linearalgebra.MatrixUtil.Product + return org.drip.numerical.linearalgebra.R1MatrixUtil.Product (org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose + (aadblScopingLoading), org.drip.numerical.linearalgebra.R1MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) r1mProjection).covariance().covarianceMatrix(), aadblScopingLoading)); } @@ -617,9 +617,9 @@ public static final double[][] ProjectionSpaceAssetCovariance ( double[][] aadblScopingLoading = pdl.scopingLoading(); - return org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblScopingLoading, - org.drip.numerical.linearalgebra.MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) - r1mScoping).covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.MatrixUtil.Transpose + return org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, + org.drip.numerical.linearalgebra.R1MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) + r1mScoping).covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading))); } @@ -658,11 +658,11 @@ public static final org.drip.measure.gaussian.R1MultivariateNormal ProjectionInd double[][] aadblScopingLoading = pdl.scopingLoading(); - double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.MatrixUtil.Product - (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.MatrixUtil.Transpose + double[][] aadblProjectionScopingShadow = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (r1mnScoping.covariance().covarianceMatrix(), org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading)); - double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.MatrixUtil.Product + double[] adblProjectionSpaceScopingMean = org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, adblScopingMean); if (null == adblProjectionSpaceScopingMean) return null; @@ -677,10 +677,10 @@ public static final org.drip.measure.gaussian.R1MultivariateNormal ProjectionInd adblProjectionSpaceScopingDifferential[i] = adblProjectionMean[i] - adblProjectionSpaceScopingMean[i]; - double[] adblProjectionInducedScopingDeviation = org.drip.numerical.linearalgebra.MatrixUtil.Product - (aadblProjectionScopingShadow, org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination - (org.drip.numerical.linearalgebra.MatrixUtil.Product (aadblScopingLoading, + double[] adblProjectionInducedScopingDeviation = org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (aadblProjectionScopingShadow, org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination + (org.drip.numerical.linearalgebra.R1MatrixUtil.Product (aadblScopingLoading, aadblProjectionScopingShadow)), adblProjectionSpaceScopingDifferential)); if (null == adblProjectionInducedScopingDeviation) return null; @@ -696,9 +696,9 @@ public static final org.drip.measure.gaussian.R1MultivariateNormal ProjectionInd try { return new org.drip.measure.gaussian.R1MultivariateNormal (r1mnUnconditional.meta(), adblProjectionInducedScopingMean, new org.drip.measure.gaussian.Covariance - (org.drip.numerical.linearalgebra.MatrixUtil.Product - (org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblScopingLoading), - org.drip.numerical.linearalgebra.MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.Product + (org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblScopingLoading), + org.drip.numerical.linearalgebra.R1MatrixUtil.Product (((org.drip.measure.gaussian.R1MultivariateNormal) r1mProjection).covariance().covarianceMatrix(), aadblScopingLoading)))); } catch (java.lang.Exception e) { diff --git a/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java b/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java index ae15416970e4..786765a5998f 100644 --- a/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java +++ b/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java @@ -1,7 +1,7 @@ package org.drip.measure.crng; -import org.drip.numerical.linearalgebra.TriangularMatrix; +import org.drip.numerical.matrix.R1Triangular; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -126,7 +126,7 @@ public class RandomMatrixGenerator * @return Lower Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix LowerTriangular ( + public static final R1Triangular LowerTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -139,7 +139,7 @@ public static final TriangularMatrix LowerTriangular ( } } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -152,7 +152,7 @@ public static final TriangularMatrix LowerTriangular ( * @return Upper Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix UpperTriangular ( + public static final R1Triangular UpperTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -165,7 +165,7 @@ public static final TriangularMatrix UpperTriangular ( } } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -178,7 +178,7 @@ public static final TriangularMatrix UpperTriangular ( * @return Diagonal Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix Diagonal ( + public static final R1Triangular Diagonal ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -193,7 +193,7 @@ public static final TriangularMatrix Diagonal ( } } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -206,7 +206,7 @@ public static final TriangularMatrix Diagonal ( * @return Lower Unitriangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix LowerUnitriangular ( + public static final R1Triangular LowerUnitriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -223,7 +223,7 @@ public static final TriangularMatrix LowerUnitriangular ( r2Array[i][i] = 1.; } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -236,7 +236,7 @@ public static final TriangularMatrix LowerUnitriangular ( * @return Upper Unitriangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix UpperUnitriangular ( + public static final R1Triangular UpperUnitriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -253,7 +253,7 @@ public static final TriangularMatrix UpperUnitriangular ( r2Array[i][i] = 1.; } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -266,7 +266,7 @@ public static final TriangularMatrix UpperUnitriangular ( * @return Strictly Lower Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix StrictlyLowerTriangular ( + public static final R1Triangular StrictlyLowerTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -283,7 +283,7 @@ public static final TriangularMatrix StrictlyLowerTriangular ( r2Array[i][i] = 0.; } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -296,7 +296,7 @@ public static final TriangularMatrix StrictlyLowerTriangular ( * @return Strictly Upper Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix StrictlyUpperTriangular ( + public static final R1Triangular StrictlyUpperTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -313,7 +313,7 @@ public static final TriangularMatrix StrictlyUpperTriangular ( r2Array[i][i] = 0.; } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -326,7 +326,7 @@ public static final TriangularMatrix StrictlyUpperTriangular ( * @return Atomic Lower Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix AtomicLowerTriangular ( + public static final R1Triangular AtomicLowerTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -357,7 +357,7 @@ public static final TriangularMatrix AtomicLowerTriangular ( } } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } /** @@ -370,7 +370,7 @@ public static final TriangularMatrix AtomicLowerTriangular ( * @return Atomic Upper Triangular Matrix of Random Elements up to the Maximum Value */ - public static final TriangularMatrix AtomicUpperTriangular ( + public static final R1Triangular AtomicUpperTriangular ( final int elementCount, final double maximumElement, final boolean isEntryInteger) @@ -401,6 +401,6 @@ public static final TriangularMatrix AtomicUpperTriangular ( } } - return TriangularMatrix.Standard (r2Array); + return R1Triangular.Standard (r2Array); } } diff --git a/src/main/java/org/drip/measure/crng/RdRandomSequence.java b/src/main/java/org/drip/measure/crng/RdRandomSequence.java index d5049c374d2b..dd3559908d22 100644 --- a/src/main/java/org/drip/measure/crng/RdRandomSequence.java +++ b/src/main/java/org/drip/measure/crng/RdRandomSequence.java @@ -1,7 +1,7 @@ package org.drip.measure.crng; -import org.drip.numerical.linearalgebra.MatrixUtil; +import org.drip.numerical.linearalgebra.R1MatrixUtil; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -211,7 +211,7 @@ public static final double[][] PeriodicTridiagonal ( for (int i = 0; i < tridiagonalMatrix.length; ++i) { for (int j = 0; j < tridiagonalMatrix.length; ++j) { if (j <= i - 2 || j >= i + 2) { - if (!MatrixUtil.TopRight (i, j, elementCount) && !MatrixUtil.BottomLeft (i, j, elementCount)) { + if (!R1MatrixUtil.TopRight (i, j, elementCount) && !R1MatrixUtil.BottomLeft (i, j, elementCount)) { tridiagonalMatrix[i][j] = 0.; } } diff --git a/src/main/java/org/drip/measure/discrete/CorrelatedPathVertexDimension.java b/src/main/java/org/drip/measure/discrete/CorrelatedPathVertexDimension.java index 3c6a596b7ae3..a88ef7bb138c 100644 --- a/src/main/java/org/drip/measure/discrete/CorrelatedPathVertexDimension.java +++ b/src/main/java/org/drip/measure/discrete/CorrelatedPathVertexDimension.java @@ -130,7 +130,7 @@ public CorrelatedPathVertexDimension ( _qr = qr; _bApplyAntithetic = bApplyAntithetic; - if (null == (_aadblCholesky = org.drip.numerical.linearalgebra.MatrixUtil.CholeskyBanachiewiczFactorization + if (null == (_aadblCholesky = org.drip.numerical.linearalgebra.R1MatrixUtil.CholeskyBanachiewiczFactorization (_aadblCorrelation = aadblCorrelation))) throw new java.lang.Exception ("CorrelatedPathVertexDimension Constructor => Invalid Inputs"); } diff --git a/src/main/java/org/drip/measure/discrete/QuadraticResampler.java b/src/main/java/org/drip/measure/discrete/QuadraticResampler.java index e4af63f3dd57..f7cf4e9eaab5 100644 --- a/src/main/java/org/drip/measure/discrete/QuadraticResampler.java +++ b/src/main/java/org/drip/measure/discrete/QuadraticResampler.java @@ -188,7 +188,7 @@ public double[] transform ( public double[][] transform ( final double[][] aadblSequence) { - double[][] aadblFlippedSequence = org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblSequence); + double[][] aadblFlippedSequence = org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblSequence); if (null == aadblFlippedSequence) return null; @@ -198,6 +198,6 @@ public double[][] transform ( for (int i = 0; i < iDimension; ++i) aadblFlippedTransformedSequence[i] = transform (aadblFlippedSequence[i]); - return org.drip.numerical.linearalgebra.MatrixUtil.Transpose (aadblFlippedTransformedSequence); + return org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose (aadblFlippedTransformedSequence); } } diff --git a/src/main/java/org/drip/measure/discrete/SequenceGenerator.java b/src/main/java/org/drip/measure/discrete/SequenceGenerator.java index c54328dddcea..96329d9c7e1d 100644 --- a/src/main/java/org/drip/measure/discrete/SequenceGenerator.java +++ b/src/main/java/org/drip/measure/discrete/SequenceGenerator.java @@ -216,7 +216,7 @@ public static final double[][] GaussianJoint ( { if (0 >= iCount) return null; - double[][] aadblCholesky = org.drip.numerical.linearalgebra.MatrixUtil.CholeskyBanachiewiczFactorization + double[][] aadblCholesky = org.drip.numerical.linearalgebra.R1MatrixUtil.CholeskyBanachiewiczFactorization (aadblCorrelation); if (null == aadblCholesky) return null; @@ -584,9 +584,9 @@ public static final double[] RankReducedChiSquare ( { try { - rankReducedChiSquare[index] = org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + rankReducedChiSquare[index] = org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( gaussianJointArray[index], - org.drip.numerical.linearalgebra.MatrixUtil.Product ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( precisionMatrix, gaussianJointArray[index] ) @@ -666,9 +666,9 @@ public static final double[] PillaiSpecialChiSquare ( try { - pillaiSpecialChiSquare[index] = 1. / org.drip.numerical.linearalgebra.MatrixUtil.DotProduct ( + pillaiSpecialChiSquare[index] = 1. / org.drip.numerical.linearalgebra.R1MatrixUtil.DotProduct ( pillaiVector, - org.drip.numerical.linearalgebra.MatrixUtil.Product ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( covarianceMatrix, pillaiVector ) diff --git a/src/main/java/org/drip/measure/gaussian/Covariance.java b/src/main/java/org/drip/measure/gaussian/Covariance.java index b6a04644c9fe..4fa60a333ee6 100644 --- a/src/main/java/org/drip/measure/gaussian/Covariance.java +++ b/src/main/java/org/drip/measure/gaussian/Covariance.java @@ -123,7 +123,7 @@ public Covariance ( throw new java.lang.Exception ("R1MultivariateNormal Constructor => Invalid Inputs!"); } - if (null == (_aadblPrecision = org.drip.numerical.linearalgebra.MatrixUtil.InvertUsingGaussianElimination + if (null == (_aadblPrecision = org.drip.numerical.linearalgebra.R1MatrixUtil.InvertUsingGaussianElimination (_aadblCovariance))) throw new java.lang.Exception ("R1MultivariateNormal Constructor => Invalid Inputs!"); } diff --git a/src/main/java/org/drip/numerical/complex/C1MatrixUtil.java b/src/main/java/org/drip/numerical/complex/C1MatrixUtil.java new file mode 100644 index 000000000000..e4d870729bf3 --- /dev/null +++ b/src/main/java/org/drip/numerical/complex/C1MatrixUtil.java @@ -0,0 +1,452 @@ + +package org.drip.numerical.complex; + +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. + */ + +/** + * C1MatrixUtil implements a C1 Complex Number Manipulation Utilities. The References are: + * + *

+ * + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class C1MatrixUtil +{ + + /** + * Add the 2 Complex Numbers. Unsafe Methods do not validate the Input Arguments, so use caution + * in applying these Methods + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The Complex Number instance that is a sum of the two + */ + + public static final CartesianC1 UnsafeAdd ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + try { + return new CartesianC1 ( + firstCartesianC1.real() + secondCartesianC1.real(), + firstCartesianC1.imaginary() + secondCartesianC1.imaginary() + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Scale the Complex Number with the factor. Unsafe Methods do not validate the Input Arguments, so + * use caution in applying these Methods + * + * @param cartesianC1 The Complex Number + * @param scale The Scaling Factor + * + * @return The Scaled Complex Number + */ + + public static final CartesianC1 UnsafeScale ( + final CartesianC1 cartesianC1, + final double scale) + { + try { + return new CartesianC1 (scale * cartesianC1.real(), scale * cartesianC1.imaginary()); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Subtract the Second Complex Number from the First. Unsafe Methods do not validate the Input Arguments, + * so use caution in applying these Methods + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The "Difference" Complex Number + */ + + public static final CartesianC1 UnsafeSubtract ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + try { + return new CartesianC1 ( + firstCartesianC1.real() - secondCartesianC1.real(), + firstCartesianC1.imaginary() - secondCartesianC1.imaginary() + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Multiply the 2 Complex Numbers. Unsafe Methods do not validate the Input Arguments, so use + * caution in applying these Methods + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The Complex Number instance that is a product of the two + */ + + public static final CartesianC1 UnsafeMultiply ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + double real1 = firstCartesianC1.real(); + + double real2 = secondCartesianC1.real(); + + double imaginary1 = firstCartesianC1.imaginary(); + + double imaginary2 = secondCartesianC1.imaginary(); + + try { + return new CartesianC1 ( + real1 * real2 - imaginary1 * imaginary2, + real1 * imaginary2 + real2 * imaginary1 + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Divide the Numerator Complex Number by the Denominator Complex Number. Unsafe Methods do not validate + * the Input Arguments, so use caution in applying these Methods + * + * @param numeratorC1 The Numerator Complex Number + * @param denominatorC1 The Denominator Complex Number + * + * @return The "Divided" Complex Number + */ + + public static final CartesianC1 UnsafeDivide ( + final CartesianC1 numeratorC1, + final CartesianC1 denominatorC1) + { + double numeratorReal = numeratorC1.real(); + + double denominatorReal = denominatorC1.real(); + + double numeratorImaginary = numeratorC1.imaginary(); + + double denominatorImaginary = denominatorC1.imaginary(); + + if (0. == denominatorReal && 0. == denominatorImaginary) { + return null; + } + + double inverseDenominatorModulus = 1. / denominatorC1.modulus(); + + try { + return new CartesianC1 ( + (numeratorReal * denominatorReal + numeratorImaginary * denominatorImaginary) * + inverseDenominatorModulus, + (denominatorReal * numeratorImaginary - numeratorReal * denominatorImaginary) * + inverseDenominatorModulus + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Square the Complex Number. Unsafe Methods do not validate the Input Arguments, so use caution + * in applying these Methods + * + * @param c1 The Complex Number + * + * @return The Squared Complex Number Instance + */ + + public static final CartesianC1 UnsafeSquare ( + final CartesianC1 c1) + { + double modulus = c1.modulus(); + + if (0. == modulus) { + try { + return new CartesianC1 (0., 0.); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + double argument = 2. * c1.argument(); + + try { + return new CartesianC1 (modulus * Math.cos (argument), modulus * Math.sin (argument)); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Compute the Square Root of the Complex Number. Unsafe Methods do not validate the Input Arguments, so + * use caution in applying these Methods + * + * @param complexNumber The Complex Number + * + * @return The Square Root Complex Number Instance + */ + + public static final CartesianC1 UnsafeSquareRoot ( + final CartesianC1 complexNumber) + { + double modulus = java.lang.Math.sqrt (complexNumber.modulus()); + + if (0. == modulus) { + try { + return new CartesianC1 (0., 0.); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + double argument = 0.5 * complexNumber.argument(); + + try { + return new CartesianC1 (modulus * Math.cos (argument), modulus * Math.sin (argument)); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * Add the 2 Complex Numbers + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The Complex Number instance that is a sum of the two + */ + + public static final CartesianC1 Add ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + return null == firstCartesianC1 || null == secondCartesianC1 ? null : + UnsafeAdd (firstCartesianC1, secondCartesianC1); + } + + /** + * Scale the Complex Number with the factor + * + * @param cartesianC1 The Complex Number + * @param scale The Scaling Factor + * + * @return The Scaled Complex Number + */ + + public static final CartesianC1 Scale ( + final CartesianC1 cartesianC1, + final double scale) + { + return null == cartesianC1 || !NumberUtil.IsValid (scale) ? null : + UnsafeScale (cartesianC1, scale); + } + + /** + * Subtract the Second Complex Number from the First + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The "Difference" Complex Number + */ + + public static final CartesianC1 Subtract ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + return null == firstCartesianC1 || null == secondCartesianC1 ? null : + UnsafeSubtract (firstCartesianC1, secondCartesianC1); + } + + /** + * Multiply the 2 Complex Numbers + * + * @param firstCartesianC1 The First Complex Number + * @param secondCartesianC1 The Second Complex Number + * + * @return The Complex Number instance that is a product of the two + */ + + public static final CartesianC1 Multiply ( + final CartesianC1 firstCartesianC1, + final CartesianC1 secondCartesianC1) + { + return null == firstCartesianC1 || null == secondCartesianC1 ? null : + UnsafeMultiply (firstCartesianC1, secondCartesianC1); + } + + /** + * Divide the Numerator Complex Number by the Denominator Complex Number + * + * @param numeratorC1 The Numerator Complex Number + * @param denominatorC1 The Denominator Complex Number + * + * @return The "Divided" Complex Number + */ + + public static final CartesianC1 Divide ( + final CartesianC1 numeratorC1, + final CartesianC1 denominatorC1) + { + return null == numeratorC1 || null == denominatorC1 ? null : + UnsafeMultiply (numeratorC1, denominatorC1); + } + + /** + * Square the Complex Number + * + * @param c1 The Complex Number + * + * @return The Squared Complex Number Instance + */ + + public static final CartesianC1 Square ( + final CartesianC1 c1) + { + return null == c1 ? null : UnsafeSquare (c1); + } + + /** + * Compute the Square Root of the Complex Number + * + * @param complexNumber The Complex Number + * + * @return The Square Root Complex Number Instance + */ + + public static final CartesianC1 SquareRoot ( + final CartesianC1 complexNumber) + { + return null == complexNumber ? null : UnsafeSquareRoot (complexNumber); + } +} diff --git a/src/main/java/org/drip/numerical/complex/CartesianC1.java b/src/main/java/org/drip/numerical/complex/CartesianC1.java new file mode 100644 index 000000000000..55e91f7233e4 --- /dev/null +++ b/src/main/java/org/drip/numerical/complex/CartesianC1.java @@ -0,0 +1,385 @@ + +package org.drip.numerical.complex; + +import org.drip.numerical.common.NumberUtil; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2022 Lakshmi Krishnamurthy + * Copyright (C) 2021 Lakshmi Krishnamurthy + * Copyright (C) 2020 Lakshmi Krishnamurthy + * Copyright (C) 2019 Lakshmi Krishnamurthy + * Copyright (C) 2018 Lakshmi Krishnamurthy + * Copyright (C) 2017 Lakshmi Krishnamurthy + * Copyright (C) 2016 Lakshmi Krishnamurthy + * Copyright (C) 2015 Lakshmi Krishnamurthy + * Copyright (C) 2014 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. + */ + +/** + * CartesianC1 implements the functionality for dealing with the Cartesian Form of Complex Numbers. + * + *

+ * + *

+ * + * @author Lakshmi Krishnamurthy + */ + +public class CartesianC1 +{ + private double _real = Double.NaN; + private double _imaginary = Double.NaN; + + /** + * Exponentiate the Complex Number + * + * @param complexNumber The Complex Number + * + * @return The Exponentiated Complex Number Instance + */ + + public static final CartesianC1 Exponentiate ( + final CartesianC1 complexNumber) + { + if (null == complexNumber) + { + return null; + } + + double argument = complexNumber.imaginary(); + + double modulus = java.lang.Math.exp (complexNumber.real()); + + try + { + return new CartesianC1 ( + modulus * java.lang.Math.cos (argument), + modulus * java.lang.Math.sin (argument) + ); + } + catch (java.lang.Exception e) + { + e.printStackTrace(); + } + + return null; + } + + /** + * Compute Logarithm of the Complex Number + * + * @param complexNumber The Complex Number + * + * @return The Complex Number Logarithm Instance + */ + + public static final CartesianC1 Logarithm ( + final CartesianC1 complexNumber) + { + if (null == complexNumber) + { + return null; + } + + double modulus = complexNumber.modulus(); + + if (0. == modulus) + { + return null; + } + + try + { + return new CartesianC1 ( + 0.5 * java.lang.Math.log (modulus), + complexNumber.argument() + ); + } + catch (java.lang.Exception e) + { + e.printStackTrace(); + } + + return null; + } + + /** + * Construct the Complex Number from its Polar Representation + * + * @param r r + * @param theta theta + * + * @return Complex Number from its Polar Representation + */ + + public static final CartesianC1 FromPolar ( + final double r, + final double theta) + { + try + { + return !org.drip.numerical.common.NumberUtil.IsValid (r) || + !org.drip.numerical.common.NumberUtil.IsValid (theta) ? null : + new CartesianC1 ( + r * java.lang.Math.cos (theta), + r * java.lang.Math.sin (theta) + ); + } + catch (java.lang.Exception e) + { + e.printStackTrace(); + } + + return null; + } + + /** + * CartesianComplexNumber constructor + * + * @param real Real Part + * @param imaginary Imaginary Part + * + * @throws Exception Thrown if the Inputs are invalid + */ + + public CartesianC1 ( + final double real, + final double imaginary) + throws Exception + { + if (!NumberUtil.IsValid (_real = real) || !NumberUtil.IsValid (_imaginary = imaginary)) { + throw new Exception ("CartesianC1 Constructor => Invalid Inputs"); + } + } + + /** + * Retrieve the Real Part + * + * @return The Real Part + */ + + public double real() + { + return _real; + } + + /** + * Retrieve the Imaginary Part + * + * @return The Imaginary Part + */ + + public double imaginary() + { + return _imaginary; + } + + /** + * Retrieve the Modulus + * + * @return The Modulus + */ + + public double modulus() + { + return _real * _real + _imaginary * _imaginary; + } + + /** + * Retrieve the Absolute Value + * + * @return The Absolute Value + */ + + public double abs() + { + return Math.sqrt (modulus()); + } + + /** + * Retrieve the Argument + * + * @return The Argument + */ + + public double argument() + { + return 0. == _real && 0. == _imaginary ? 0. : Math.atan (_imaginary / _real); + } + + /** + * Add the Input Cartesian C1 to the current Instance + * + * @param cartesianC1 Input Cartesian C1 + * + * @return Output Cartesian C1 + */ + + public CartesianC1 add ( + final CartesianC1 cartesianC1) + { + return null == cartesianC1 ? this : C1MatrixUtil.UnsafeAdd (this, cartesianC1); + } + + /** + * Scale the Complex Number with the factor + * + * @param scale The Scaling Factor + * + * @return Output Cartesian C1 + */ + + public CartesianC1 scale ( + final double scale) + { + return NumberUtil.IsValid (scale) ? null : C1MatrixUtil.UnsafeScale (this, scale); + } + + /** + * Subtract the Input Cartesian C1 from the current Instance + * + * @param cartesianC1 Input Cartesian C1 + * + * @return Output Cartesian C1 + */ + + public CartesianC1 subtract ( + final CartesianC1 cartesianC1) + { + return null == cartesianC1 ? this : C1MatrixUtil.UnsafeSubtract (this, cartesianC1); + } + + /** + * Multiply the Input Cartesian C1 with the current Instance + * + * @param cartesianC1 Input Cartesian C1 + * + * @return Output Cartesian C1 + */ + + public CartesianC1 multiply ( + final CartesianC1 cartesianC1) + { + return null == cartesianC1 ? this : C1MatrixUtil.UnsafeMultiply (this, cartesianC1); + } + + /** + * Divide the Current Instance by the Input Cartesian C1 + * + * @param cartesianC1 Input Cartesian C1 + * + * @return Output Cartesian C1 + */ + + public CartesianC1 divide ( + final CartesianC1 cartesianC1) + { + return null == cartesianC1 ? this : C1MatrixUtil.UnsafeDivide (this, cartesianC1); + } + + /** + * Compute the Square of the Complex Number + * + * @return The Square Complex Number Instance + */ + + public CartesianC1 square() + { + return C1MatrixUtil.UnsafeSquare (this); + } + + /** + * Compute the Square Root of the Complex Number + * + * @return The Square Root Complex Number Instance + */ + + public CartesianC1 squareRoot() + { + return C1MatrixUtil.UnsafeSquareRoot (this); + } + + /** + * Display the Real/Imaginary Contents + * + * @return The Real/Imaginary Contents + */ + + public String display() + { + return "\t[" + _real + ", " + _imaginary + "]"; + } +} diff --git a/src/main/java/org/drip/numerical/complex/package-info.java b/src/main/java/org/drip/numerical/complex/package-info.java new file mode 100644 index 000000000000..0ac5f24e2a69 --- /dev/null +++ b/src/main/java/org/drip/numerical/complex/package-info.java @@ -0,0 +1,8 @@ + +/** + * Implementation of Complex Number Suite + * + * @author Lakshmi Krishnamurthy + */ + +package org.drip.numerical.complex; diff --git a/src/main/java/org/drip/numerical/eigen/PowerIterationComponentExtractor.java b/src/main/java/org/drip/numerical/eigen/PowerIterationComponentExtractor.java index 556f5388e1b9..f20fa3c6fb87 100644 --- a/src/main/java/org/drip/numerical/eigen/PowerIterationComponentExtractor.java +++ b/src/main/java/org/drip/numerical/eigen/PowerIterationComponentExtractor.java @@ -192,7 +192,7 @@ public boolean isToleranceAbsolute() eigenVector[componentIndex] = 1.; } - eigenVector = org.drip.numerical.linearalgebra.MatrixUtil.Normalize ( + eigenVector = org.drip.numerical.linearalgebra.R1MatrixUtil.Normalize ( eigenVector ); @@ -217,12 +217,12 @@ public boolean isToleranceAbsolute() } } - eigenVectorArray = org.drip.numerical.linearalgebra.MatrixUtil.Normalize ( + eigenVectorArray = org.drip.numerical.linearalgebra.R1MatrixUtil.Normalize ( eigenVectorArray ); try { - eigenValue = org.drip.numerical.linearalgebra.MatrixUtil.RayleighQuotient ( + eigenValue = org.drip.numerical.linearalgebra.R1MatrixUtil.RayleighQuotient ( a, eigenVectorArray ); diff --git a/src/main/java/org/drip/numerical/eigen/QREigenComponentExtractor.java b/src/main/java/org/drip/numerical/eigen/QREigenComponentExtractor.java index 527a09627c57..a141aef49f52 100644 --- a/src/main/java/org/drip/numerical/eigen/QREigenComponentExtractor.java +++ b/src/main/java/org/drip/numerical/eigen/QREigenComponentExtractor.java @@ -156,7 +156,7 @@ public int maxIterations() @Override public org.drip.numerical.eigen.EigenOutput eigenize ( final double[][] a) { - org.drip.numerical.linearalgebra.QR qr = org.drip.numerical.linearalgebra.MatrixUtil.QRDecomposition ( + org.drip.numerical.linearalgebra.QR qr = org.drip.numerical.linearalgebra.R1MatrixUtil.QRDecomposition ( a ); @@ -167,7 +167,7 @@ public int maxIterations() double[][] q = qr.q(); - double[][] qTranspose = org.drip.numerical.linearalgebra.MatrixUtil.Transpose ( + double[][] qTranspose = org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose ( q ); @@ -201,16 +201,16 @@ public int maxIterations() } while (iterationIndex++ < _maxIterations && - org.drip.numerical.linearalgebra.TriangularMatrix.NON_TRIANGULAR == - org.drip.numerical.linearalgebra.TriangularMatrix.Type ( + org.drip.numerical.matrix.R1Triangular.NON_TRIANGULAR == + org.drip.numerical.matrix.R1Triangular.Type ( v ) ) { - if (null == (qr = org.drip.numerical.linearalgebra.MatrixUtil.QRDecomposition ( - v = org.drip.numerical.linearalgebra.MatrixUtil.Product ( + if (null == (qr = org.drip.numerical.linearalgebra.R1MatrixUtil.QRDecomposition ( + v = org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( qTranspose, - org.drip.numerical.linearalgebra.MatrixUtil.Product ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( v, q ) @@ -220,11 +220,11 @@ public int maxIterations() return null; } - qTranspose = org.drip.numerical.linearalgebra.MatrixUtil.Transpose ( + qTranspose = org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose ( q = qr.q() ); - b = org.drip.numerical.linearalgebra.MatrixUtil.Product ( + b = org.drip.numerical.linearalgebra.R1MatrixUtil.Product ( b, q ); @@ -245,7 +245,7 @@ public int maxIterations() try { return new org.drip.numerical.eigen.EigenOutput ( - org.drip.numerical.linearalgebra.MatrixUtil.Transpose ( + org.drip.numerical.linearalgebra.R1MatrixUtil.Transpose ( b ), eigenvalueArray diff --git a/src/main/java/org/drip/numerical/fourier/PhaseAdjuster.java b/src/main/java/org/drip/numerical/fourier/PhaseAdjuster.java index eee1c27eb039..5b58cdd14d58 100644 --- a/src/main/java/org/drip/numerical/fourier/PhaseAdjuster.java +++ b/src/main/java/org/drip/numerical/fourier/PhaseAdjuster.java @@ -128,9 +128,9 @@ public class PhaseAdjuster { * @return The Branch Switching Log Adjustment */ - public static final org.drip.function.definition.CartesianComplexNumber PowerLogPhaseTracker ( - final org.drip.function.definition.CartesianComplexNumber cnGNumerator, - final org.drip.function.definition.CartesianComplexNumber cnGDenominator, + public static final org.drip.numerical.complex.CartesianC1 PowerLogPhaseTracker ( + final org.drip.numerical.complex.CartesianC1 cnGNumerator, + final org.drip.numerical.complex.CartesianC1 cnGDenominator, final int iN, final int iM) { @@ -141,7 +141,7 @@ public static final org.drip.function.definition.CartesianComplexNumber PowerLog if (0. == dblAbsDenominator) return null; try { - return new org.drip.function.definition.CartesianComplexNumber (java.lang.Math.log (cnGNumerator.abs() / + return new org.drip.numerical.complex.CartesianC1 (java.lang.Math.log (cnGNumerator.abs() / dblAbsDenominator), cnGNumerator.argument() - cnGDenominator.argument() + 2. * java.lang.Math.PI * (iN - iM)); } catch (java.lang.Exception e) { diff --git a/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxation.java b/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxation.java index c994e4b86fc3..326ba28fa1fe 100644 --- a/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxation.java +++ b/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxation.java @@ -2,7 +2,7 @@ package org.drip.numerical.iterativesolver; import org.drip.numerical.common.NumberUtil; -import org.drip.numerical.linearalgebra.MatrixUtil; +import org.drip.numerical.linearalgebra.R1MatrixUtil; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -198,7 +198,7 @@ public SuccessiveOverRelaxation ( throws Exception { if (null == (_iteratorSetting = iteratorSetting) || - !MatrixUtil.IsSquare (_squareMatrix = squareMatrix) || + !R1MatrixUtil.IsSquare (_squareMatrix = squareMatrix) || null == (_rhsArray = rhsArray)) { throw new Exception ("SuccessiveOverRelaxation Construction => Invalid Inputs"); @@ -228,7 +228,7 @@ public double[][] squareMatrix() public double[][] diagonalMatrix() { - return MatrixUtil.Diagonal (_squareMatrix); + return R1MatrixUtil.Diagonal (_squareMatrix); } /** @@ -239,7 +239,7 @@ public double[][] diagonalMatrix() public double[][] strictlyLowerTriangularMatrix() { - return MatrixUtil.StrictlyLowerTriangular (_squareMatrix); + return R1MatrixUtil.StrictlyLowerTriangular (_squareMatrix); } /** @@ -250,7 +250,7 @@ public double[][] strictlyLowerTriangularMatrix() public double[][] strictlyUpperTriangularMatrix() { - return MatrixUtil.StrictlyUpperTriangular (_squareMatrix); + return R1MatrixUtil.StrictlyUpperTriangular (_squareMatrix); } /** diff --git a/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxationConvergenceAnalyzer.java b/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxationConvergenceAnalyzer.java index eb0750580ba6..7ea8da3d0c28 100644 --- a/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxationConvergenceAnalyzer.java +++ b/src/main/java/org/drip/numerical/iterativesolver/SuccessiveOverRelaxationConvergenceAnalyzer.java @@ -2,7 +2,7 @@ package org.drip.numerical.iterativesolver; import org.drip.numerical.common.NumberUtil; -import org.drip.numerical.linearalgebra.MatrixUtil; +import org.drip.numerical.linearalgebra.R1MatrixUtil; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -170,7 +170,7 @@ public SuccessiveOverRelaxationConvergenceAnalyzer ( final double jacobiIterationMatrixSpectralRadius) throws Exception { - if (!MatrixUtil.IsSquare (_squareMatrix = squareMatrix) || + if (!R1MatrixUtil.IsSquare (_squareMatrix = squareMatrix) || !NumberUtil.IsValid (_relaxationParameter = relaxationParameter) || !NumberUtil.IsValid (_jacobiIterationMatrixSpectralRadius = jacobiIterationMatrixSpectralRadius)) { @@ -221,7 +221,7 @@ public double jacobiIterationMatrixSpectralRadius() public double[][] jacobiIterationMatrix() { - return MatrixUtil.JacobiIteration (_squareMatrix); + return R1MatrixUtil.JacobiIteration (_squareMatrix); } /** diff --git a/src/main/java/org/drip/numerical/iterativesolver/SymmetricSuccessiveOverRelaxation.java b/src/main/java/org/drip/numerical/iterativesolver/SymmetricSuccessiveOverRelaxation.java index beb1433e9b6e..df8db0ddd0ad 100644 --- a/src/main/java/org/drip/numerical/iterativesolver/SymmetricSuccessiveOverRelaxation.java +++ b/src/main/java/org/drip/numerical/iterativesolver/SymmetricSuccessiveOverRelaxation.java @@ -2,7 +2,7 @@ package org.drip.numerical.iterativesolver; import org.drip.numerical.common.NumberUtil; -import org.drip.numerical.linearalgebra.MatrixUtil; +import org.drip.numerical.linearalgebra.R1MatrixUtil; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -142,7 +142,7 @@ public SymmetricSuccessiveOverRelaxation ( { super (iteratorSetting, squareMatrix, rhsArray); - if (!MatrixUtil.IsSquareSymmetric (squareMatrix)) { + if (!R1MatrixUtil.IsSquareSymmetric (squareMatrix)) { throw new Exception ("SymmetricSuccessiveOverRelaxation Construction => Invalid Inputs"); } } @@ -173,9 +173,9 @@ public double[][] preConditioner() } } - double[][] preConditionerMatrix = MatrixUtil.Product ( + double[][] preConditionerMatrix = R1MatrixUtil.Product ( dOverOmegaPlusL, - MatrixUtil.Transpose (dOverOmegaPlusL) + R1MatrixUtil.Transpose (dOverOmegaPlusL) ); double relaxationParameterScaler = relaxationParameter/ (2. - relaxationParameter); @@ -203,7 +203,7 @@ public double[] preConditioningIteration ( return null; } - double[][] preConditionerMatrixInverse = MatrixUtil.Invert (preConditioner(), "GaussianElimination"); + double[][] preConditionerMatrixInverse = R1MatrixUtil.Invert (preConditioner(), "GaussianElimination"); if (null == preConditionerMatrixInverse) { return null; @@ -227,7 +227,7 @@ public double[] preConditioningIteration ( previousUnknownArray[i] = updatedUnknownArray[i]; } - if (null == (updatedUnknownArray = MatrixUtil.Product (squareMatrix, updatedUnknownArray))) { + if (null == (updatedUnknownArray = R1MatrixUtil.Product (squareMatrix, updatedUnknownArray))) { return null; } @@ -236,7 +236,7 @@ public double[] preConditioningIteration ( } if (null == ( - updatedUnknownArray = MatrixUtil.Product (preConditionerMatrixInverse, updatedUnknownArray) + updatedUnknownArray = R1MatrixUtil.Product (preConditionerMatrixInverse, updatedUnknownArray) )) { return null; diff --git a/src/main/java/org/drip/numerical/linearalgebra/GershgorinAnalyzer.java b/src/main/java/org/drip/numerical/linearalgebra/GershgorinAnalyzer.java index 0c481c2aa4d8..1aaab65da459 100644 --- a/src/main/java/org/drip/numerical/linearalgebra/GershgorinAnalyzer.java +++ b/src/main/java/org/drip/numerical/linearalgebra/GershgorinAnalyzer.java @@ -3,6 +3,7 @@ import org.drip.numerical.common.NumberUtil; import org.drip.numerical.common.R1ClosenessVerifier; +import org.drip.numerical.matrix.R1Square; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -118,7 +119,7 @@ public class GershgorinAnalyzer { - private SquareMatrix _squareMatrix = null; + private R1Square _squareMatrix = null; private GershgorinDisc[] _gershgorinDiscArray = null; /** @@ -131,7 +132,7 @@ public class GershgorinAnalyzer */ public static final GershgorinAnalyzer FromSquareMatrix ( - final SquareMatrix squareMatrix, + final R1Square squareMatrix, final boolean useRow) { try { @@ -156,7 +157,7 @@ public static final GershgorinAnalyzer FromSquareMatrix ( */ public GershgorinAnalyzer ( - final SquareMatrix squareMatrix, + final R1Square squareMatrix, final R1ClosenessVerifier r1ClosenessVerifier) throws Exception { @@ -186,7 +187,7 @@ public GershgorinAnalyzer ( * @return Square Matrix */ - public SquareMatrix squareMatrix() + public R1Square squareMatrix() { return _squareMatrix; } @@ -227,7 +228,7 @@ public boolean isDiagonallyDominant() * @return "Gershgorin Strengthened" Square Matrix */ - public SquareMatrix Strengthen ( + public R1Square Strengthen ( final double t) { if (!NumberUtil.IsValid (t) || 0. > t || 1. < t) { @@ -246,7 +247,7 @@ public SquareMatrix Strengthen ( } } - return SquareMatrix.Standard (r2ArrayStrengthened); + return R1Square.Standard (r2ArrayStrengthened); } public static void main ( @@ -261,7 +262,7 @@ public static void main ( }; GershgorinAnalyzer gershgorinRowAnalyzer = GershgorinAnalyzer.FromSquareMatrix ( - SquareMatrix.Standard (r2Array), + R1Square.Standard (r2Array), true ); @@ -276,7 +277,7 @@ public static void main ( GershgorinAnalyzer gershgorinColumnAnalyzer = GershgorinAnalyzer.FromSquareMatrix ( - SquareMatrix.Standard (r2Array), + R1Square.Standard (r2Array), true ); diff --git a/src/main/java/org/drip/numerical/linearalgebra/MatrixUtil.java b/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java similarity index 96% rename from src/main/java/org/drip/numerical/linearalgebra/MatrixUtil.java rename to src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java index 33a2d31e096f..de34dca45dda 100644 --- a/src/main/java/org/drip/numerical/linearalgebra/MatrixUtil.java +++ b/src/main/java/org/drip/numerical/linearalgebra/R1MatrixUtil.java @@ -85,7 +85,8 @@ */ /** - * MatrixUtil implements Matrix manipulation routines. It exports the following functionality: + * R1MatrixUtil implements R1 Matrix manipulation routines. It exports the following + * functionality: *