GrahamSchmidtProcess.java

  1. package org.drip.sample.matrix;

  2. import org.drip.numerical.common.*;
  3. import org.drip.numerical.linearalgebra.Matrix;
  4. import org.drip.service.env.EnvManager;

  5. /*
  6.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  7.  */

  8. /*!
  9.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  10.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  14.  *
  15.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  16.  *      calculations, valuation adjustment, and portfolio construction within and across fixed income,
  17.  *      credit, commodity, equity, FX, and structured products.
  18.  *  
  19.  *      https://lakshmidrip.github.io/DROP/
  20.  *  
  21.  *  DROP is composed of three modules:
  22.  *  
  23.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  24.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  25.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  26.  *
  27.  *  DROP Analytics Core implements libraries for the following:
  28.  *  - Fixed Income Analytics
  29.  *  - Asset Backed Analytics
  30.  *  - XVA Analytics
  31.  *  - Exposure and Margin Analytics
  32.  *
  33.  *  DROP Portfolio Core implements libraries for the following:
  34.  *  - Asset Allocation Analytics
  35.  *  - Transaction Cost Analytics
  36.  *
  37.  *  DROP Numerical Core implements libraries for the following:
  38.  *  - Statistical Learning
  39.  *  - Numerical Optimizer
  40.  *  - Spline Builder
  41.  *  - Algorithm Support
  42.  *
  43.  *  Documentation for DROP is Spread Over:
  44.  *
  45.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  46.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  47.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  48.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  49.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  50.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  51.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  52.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  53.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  54.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  55.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  56.  *
  57.  *  Licensed under the Apache License, Version 2.0 (the "License");
  58.  *      you may not use this file except in compliance with the License.
  59.  *  
  60.  *  You may obtain a copy of the License at
  61.  *      http://www.apache.org/licenses/LICENSE-2.0
  62.  *  
  63.  *  Unless required by applicable law or agreed to in writing, software
  64.  *      distributed under the License is distributed on an "AS IS" BASIS,
  65.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  66.  *  
  67.  *  See the License for the specific language governing permissions and
  68.  *      limitations under the License.
  69.  */

  70. /**
  71.  * <i>GrahamSchmidtProcess</i> illustrates the Graham Schmidt Orthogonalization and Orthonormalization.
  72.  *  
  73.  * <br><br>
  74.  *  <ul>
  75.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  76.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalSupportLibrary.md">Numerical Support Library</a></li>
  77.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  78.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/matrix/README.md">Linear Algebra and Matrix Utilities</a></li>
  79.  *  </ul>
  80.  * <br><br>
  81.  *
  82.  * @author Lakshmi Krishnamurthy
  83.  */

  84. public class GrahamSchmidtProcess {

  85.     public static final void main (
  86.         final String[] astrArgs)
  87.         throws Exception
  88.     {
  89.         EnvManager.InitEnv ("");

  90.         double[][] aadblV = new double[][] {
  91.             {3, 1, 4, 9},
  92.             {2, 2, 6, 0},
  93.             {1, 8, 3, 5},
  94.             {7, 0, 4, 5}
  95.         };

  96.         double[][] aadblUOrthogonal = Matrix.GrahamSchmidtOrthogonalization (aadblV);

  97.         NumberUtil.PrintMatrix (
  98.             "ORTHOGONAL",
  99.             aadblUOrthogonal
  100.         );

  101.         System.out.println (
  102.             "ORTHOGONAL TEST: " +
  103.             FormatUtil.FormatDouble (
  104.                 Matrix.DotProduct (
  105.                     aadblUOrthogonal[0],
  106.                     aadblUOrthogonal[1]
  107.                 ),
  108.                 1, 1, 1.
  109.             )
  110.         );

  111.         double[][] aadblUOrthonormal = Matrix.GrahamSchmidtOrthonormalization (aadblV);

  112.         NumberUtil.PrintMatrix (
  113.             "ORTHONORMAL",
  114.             aadblUOrthonormal
  115.         );

  116.         System.out.println (
  117.             "ORTHONORMAL TEST: " +
  118.             FormatUtil.FormatDouble (
  119.                 Matrix.DotProduct (
  120.                     aadblUOrthonormal[0],
  121.                     aadblUOrthonormal[1]
  122.                 ),
  123.                 1, 1, 1.
  124.             )
  125.         );

  126.         EnvManager.TerminateEnv();
  127.     }
  128. }