LineEvolutionVerifierMetrics.java

  1. package org.drip.function.rdtor1descent;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

  77. /**
  78.  * <i>LineEvolutionVerifierMetrics</i> implements the Step Length Verification Criterion used for the Inexact
  79.  * Line Search Increment Generation. The References are:
  80.  * <br><br>
  81.  *  <ul>
  82.  *      <li>
  83.  *          Armijo, L. (1966): Minimization of Functions having Lipschitz-Continuous First Partial
  84.  *              Derivatives <i>Pacific Journal of Mathematics</i> <b>16 (1)</b> 1-3
  85.  *      </li>
  86.  *      <li>
  87.  *          Nocedal, J., and S. Wright (1999): <i>Numerical Optimization</i> <b>Wiley</b>
  88.  *      </li>
  89.  *      <li>
  90.  *          Wolfe, P. (1969): Convergence Conditions for Ascent Methods <i>SIAM Review</i> <b>11 (2)</b>
  91.  *              226-235
  92.  *      </li>
  93.  *      <li>
  94.  *          Wolfe, P. (1971): Convergence Conditions for Ascent Methods; II: Some Corrections <i>SIAM
  95.  *              Review</i> <b>13 (2)</b> 185-188
  96.  *      </li>
  97.  *  </ul>
  98.  *
  99.  *  <br><br>
  100.  *  <ul>
  101.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  102.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  103.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/function/README.md">R<sup>d</sup> To R<sup>d</sup> Function Analysis</a></li>
  104.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/function/rdtor1descent/README.md">R<sup>d</sup> To R<sup>1</sup> Gradient Descent Techniques</a></li>
  105.  *  </ul>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public abstract class LineEvolutionVerifierMetrics
  110. {
  111.     private double[] _currentVariateArray = null;
  112.     private double _stepLength = java.lang.Double.NaN;
  113.     private double[] _currentVariateFunctionJacobian = null;
  114.     private org.drip.function.definition.UnitVector _targetDirection = null;

  115.     protected LineEvolutionVerifierMetrics (
  116.         final org.drip.function.definition.UnitVector targetDirection,
  117.         final double[] currentVariateArray,
  118.         final double stepLength,
  119.         final double[] currentVariateFunctionJacobian)
  120.         throws java.lang.Exception
  121.     {
  122.         if (null == (_targetDirection = targetDirection) ||
  123.             null == (_currentVariateArray = currentVariateArray) ||
  124.             !org.drip.numerical.common.NumberUtil.IsValid (_stepLength = stepLength) ||
  125.             null == (_currentVariateFunctionJacobian = currentVariateFunctionJacobian) ||
  126.             _currentVariateArray.length != _currentVariateFunctionJacobian.length)
  127.         {
  128.             throw new java.lang.Exception ("LineEvolutionVerifierMetrics Constructor => Invalid Inputs");
  129.         }
  130.     }

  131.     /**
  132.      * Retrieve the Current Variate Array
  133.      *
  134.      * @return The Current Variate Array
  135.      */

  136.     public double[] currentVariateArray()
  137.     {
  138.         return _currentVariateArray;
  139.     }

  140.     /**
  141.      * Retrieve the Target Direction Unit Vector
  142.      *
  143.      * @return The Target Direction Unit Vector
  144.      */

  145.     public org.drip.function.definition.UnitVector targetDirection()
  146.     {
  147.         return _targetDirection;
  148.     }

  149.     /**
  150.      * Retrieve the Step Length
  151.      *
  152.      * @return The Step Length
  153.      */

  154.     public double stepLength()
  155.     {
  156.         return _stepLength;
  157.     }

  158.     /**
  159.      * Retrieve the Function Jacobian at the Current Variate
  160.      *
  161.      * @return The Function Jacobian at the Current Variate
  162.      */

  163.     public double[] currentVariateFunctionJacobian()
  164.     {
  165.         return _currentVariateFunctionJacobian;
  166.     }

  167.     @Override public java.lang.String toString()
  168.     {
  169.         double[] targetDirectionVector = _targetDirection.component();

  170.         java.lang.String string = "\t[";
  171.         int variateCount = _currentVariateArray.length;

  172.         for (int variateIndex = 0;
  173.             variateIndex < variateCount;
  174.             ++variateIndex)
  175.         {
  176.             string = string + org.drip.numerical.common.FormatUtil.FormatDouble (
  177.                 _currentVariateArray[variateIndex],
  178.                 2,
  179.                 3,
  180.                 1.
  181.             ) + " |";
  182.         }

  183.         string = string + "]" + org.drip.numerical.common.FormatUtil.FormatDouble (
  184.             _stepLength,
  185.             1,
  186.             3,
  187.             1.
  188.         ) + " || {";

  189.         for (int variateIndex = 0;
  190.             variateIndex < variateCount;
  191.             ++variateIndex)
  192.         {
  193.             string = string + org.drip.numerical.common.FormatUtil.FormatDouble (
  194.                 targetDirectionVector[variateIndex],
  195.                 1,
  196.                 2,
  197.                 1.
  198.             ) + " |";
  199.         }

  200.         return string + " }";
  201.     }

  202.     /**
  203.      * Indicate if the Evolution Criterion has been met
  204.      *
  205.      * @return TRUE - The Evolution Criterion has been met
  206.      */

  207.     public abstract boolean verify();
  208. }