ExecutionInitializationOutput.java

  1. package org.drip.function.r1tor1solver;

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

  81. /**
  82.  * <i>ExecutionInitializationOutput</i> holds the output of the root initializer calculation.
  83.  * <br><br>
  84.  * The following are the fields held by ExecutionInitializationOutput:
  85.  * <br>
  86.  * <ul>
  87.  *  <li>
  88.  *      Whether the initialization completed successfully
  89.  *  </li>
  90.  *  <li>
  91.  *      The number of iterations, the number of objective function calculations, and the time taken for the
  92.  *          initialization
  93.  *  </li>
  94.  *  <li>
  95.  *      The starting variate from the initialization
  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/r1tor1solver/README.md">Built-in R<sup>1</sup> To R<sup>1</sup> Solvers</a></li>
  105.  *  </ul>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public abstract class ExecutionInitializationOutput {
  110.     private int _iNumOFCalcs = 0;
  111.     private long _lStartTime = 0L;
  112.     private boolean _bDone = false;
  113.     private int _iNumIterations = 0;
  114.     private int _iNumOFDerivCalcs = 0;
  115.     private double _dblTime = java.lang.Double.NaN;
  116.     private double _dblStartingVariate = java.lang.Double.NaN;

  117.     protected ExecutionInitializationOutput()
  118.     {
  119.         _lStartTime = System.nanoTime();
  120.     }

  121.     protected ExecutionInitializationOutput (
  122.         final ExecutionInitializationOutput eiopOther)
  123.         throws java.lang.Exception
  124.     {
  125.         if (null == eiopOther)
  126.             throw new java.lang.Exception ("ExecutionInitializationOutput constructor: Invalid inputs!");

  127.         _iNumOFCalcs = eiopOther._iNumOFCalcs;
  128.         _lStartTime = eiopOther._lStartTime;
  129.         _bDone = eiopOther._bDone;
  130.         _iNumIterations = eiopOther._iNumIterations;
  131.         _iNumOFDerivCalcs = eiopOther._iNumOFDerivCalcs;
  132.         _dblTime = eiopOther._dblTime;
  133.         _dblStartingVariate = eiopOther._dblStartingVariate;
  134.     }

  135.     protected boolean done()
  136.     {
  137.         _dblTime = (System.nanoTime() - _lStartTime) * 0.000001;

  138.         return _bDone = true;
  139.     }

  140.     /**
  141.      * Increment the Number of Iterations
  142.      *
  143.      * @return TRUE - Successfully incremented
  144.      */

  145.     public final boolean incrIterations()
  146.     {
  147.         ++_iNumIterations;
  148.         return true;
  149.     }

  150.     /**
  151.      * Return The number of Iterations consumed
  152.      *
  153.      * @return Number of Iterations consumed
  154.      */

  155.     public final int getNumIterations()
  156.     {
  157.         return _iNumIterations;
  158.     }

  159.     /**
  160.      * Increment the Number of Objective Function Evaluations
  161.      *
  162.      * @return TRUE - Successfully incremented
  163.      */

  164.     public final boolean incrOFCalcs()
  165.     {
  166.         ++_iNumOFCalcs;
  167.         return true;
  168.     }

  169.     /**
  170.      * Retrieve the number of objective function calculations needed
  171.      *
  172.      * @return Number of objective function calculations needed
  173.      */

  174.     public final int getNumOFCalcs()
  175.     {
  176.         return _iNumOFCalcs;
  177.     }

  178.     /**
  179.      * Increment the number of Objective Function Derivative evaluations
  180.      *
  181.      * @return TRUE - Successfully incremented
  182.      */

  183.     public final boolean incrOFDerivCalcs()
  184.     {
  185.         ++_iNumOFDerivCalcs;
  186.         return true;
  187.     }

  188.     /**
  189.      * Retrieve the number of objective function derivative calculations needed
  190.      *
  191.      * @return Number of objective function derivative calculations needed
  192.      */

  193.     public final int getNumOFDerivCalcs()
  194.     {
  195.         return _iNumOFDerivCalcs;
  196.     }

  197.     /**
  198.      * Indicate if the execution initialization is done
  199.      *
  200.      * @return TRUE - Execution initialization is done
  201.      */

  202.     public final boolean isDone()
  203.     {
  204.         return _bDone;
  205.     }

  206.     /**
  207.      * Return the time elapsed for the execution initialization operation
  208.      *
  209.      * @return execution initialization time
  210.      */

  211.     public final double time()
  212.     {
  213.         return _dblTime;
  214.     }

  215.     /**
  216.      * Set the Starting Variate
  217.      *
  218.      * @param dblStartingVariate Starting Variate
  219.      *
  220.      * @return TRUE - Starting Variate set successfully
  221.      */

  222.     public boolean setStartingVariate (
  223.         final double dblStartingVariate)
  224.     {
  225.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblStartingVariate)) return false;

  226.         _dblStartingVariate = dblStartingVariate;
  227.         return true;
  228.     }

  229.     /**
  230.      * Return the Starting Variate
  231.      *
  232.      * @return Starting Variate
  233.      */

  234.     public double getStartingVariate()
  235.     {
  236.         return _dblStartingVariate;
  237.     }

  238.     /**
  239.      * Return a string form of the Initializer output
  240.      *
  241.      * @return String form of the Initializer output
  242.      */

  243.     public java.lang.String displayString()
  244.     {
  245.         java.lang.StringBuffer sb = new java.lang.StringBuffer();

  246.         sb.append ("\t\tInitialization Done? " + isDone() + " [" + time() + " msec]");

  247.         sb.append ("\n\t\tNum Iterations: " + getNumIterations());

  248.         sb.append ("\n\t\tNum OF Calculations: " + getNumOFCalcs());

  249.         sb.append ("\n\t\tNum OF Derivative Calculations: " + getNumOFDerivCalcs());

  250.         sb.append ("\n\t\tStarting Variate: " + getStartingVariate());

  251.         return sb.toString();
  252.     }
  253. }