KohlrauschPDFEstimate.java

  1. package org.drip.sample.scaledexponential;

  2. import org.drip.function.definition.R1ToR1;
  3. import org.drip.measure.continuous.R1UnivariateScaledExponential;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.specialfunction.definition.ScaledExponentialEstimator;
  7. import org.drip.specialfunction.gamma.EulerIntegralSecondKind;

  8. /*
  9.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  10.  */

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

  68. /**
  69.  * <i>KohlrauschPDFEstimate</i> illustrates the Construction and Usage of the Kohlrausch PDF Estimate
  70.  * Function. The References are:
  71.  *
  72.  * <br><br>
  73.  *  <ul>
  74.  *      <li>
  75.  *          Gradshteyn, I. S., I. M. Ryzhik, Y. V. Geronimus, M. Y. Tseytlin, and A. Jeffrey (2015):
  76.  *              <i>Tables of Integrals, Series, and Products</i> <b>Academic Press</b>
  77.  *      </li>
  78.  *      <li>
  79.  *          Hilfer, J. (2002): H-function Representations for Stretched Exponential Relaxation and non-Debye
  80.  *              Susceptibilities in Glassy Systems <i>Physical Review E</i> <b>65 (6)</b> 061510
  81.  *      </li>
  82.  *      <li>
  83.  *          Wikipedia (2019): Stretched Exponential Function
  84.  *              https://en.wikipedia.org/wiki/Stretched_exponential_function
  85.  *      </li>
  86.  *      <li>
  87.  *          Wuttke, J. (2012): Laplace-Fourier Transform of the Stretched Exponential Function: Analytic
  88.  *              Error-Bounds, Double Exponential Transform, and Open Source Implementation <i>libkw</i>
  89.  *              <i>Algorithm</i> <b>5 (4)</b> 604-628
  90.  *      </li>
  91.  *      <li>
  92.  *          Zorn, R. (2002): Logarithmic Moments of Relaxation Time Distributions <i>Journal of Chemical
  93.  *              Physics</i> <b>116 (8)</b> 3204-3209
  94.  *      </li>
  95.  *  </ul>
  96.  *
  97.  *  <br><br>
  98.  *  <ul>
  99.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  100.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  101.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/README.md">Special Function Project</a></li>
  102.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/ode/README.md">Special Function Ordinary Differential Equations</a></li>
  103.  *  </ul>
  104.  *
  105.  * @author Lakshmi Krishnamurthy
  106.  */

  107. public class KohlrauschPDFEstimate
  108. {

  109.     public static final void main (
  110.         final String[] argumentArray)
  111.         throws Exception
  112.     {
  113.         EnvManager.InitEnv ("");

  114.         double[] tArray =
  115.         {
  116.              0.1,
  117.              0.2,
  118.              0.3,
  119.              0.4,
  120.              0.5,
  121.              1.0,
  122.              2.0,
  123.              5.0,
  124.             10.0,
  125.         };
  126.         double[] betaArray =
  127.         {
  128.              0.1,
  129.              0.2,
  130.              0.3,
  131.              0.4,
  132.              0.5,
  133.              0.6,
  134.              0.7,
  135.              0.8,
  136.              0.9,
  137.         };
  138.         double[] pValueArray =
  139.         {
  140.              0.05,
  141.              0.10,
  142.              0.15,
  143.              0.20,
  144.              0.25,
  145.              0.30,
  146.              0.35,
  147.              0.40,
  148.              0.45,
  149.         };

  150.         R1ToR1 gammaEstimator = new EulerIntegralSecondKind (null);

  151.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  152.         System.out.println ("\t|                                             PROBABILITY DENSITY FUNCTION ESTIMATE                                            ||");

  153.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  154.         System.out.println ("\t|        L -> R:                                                                                                               ||");

  155.         System.out.println ("\t|                - Beta                                                                                                        ||");

  156.         System.out.println ("\t|                - Values for different t                                                                                      ||");

  157.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  158.         for (double beta : betaArray)
  159.         {
  160.             R1UnivariateScaledExponential r1UnivariateScaledExponential = new R1UnivariateScaledExponential (
  161.                 new ScaledExponentialEstimator (
  162.                     beta,
  163.                     1.
  164.                 ),
  165.                 gammaEstimator
  166.             );

  167.             String display = "\t| [" + FormatUtil.FormatDouble (beta, 1, 1, 1., false) + "] => ";

  168.             for (double t : tArray)
  169.             {
  170.                 display = display + " " + FormatUtil.FormatDouble (
  171.                     r1UnivariateScaledExponential.density (t), 1, 8, 1., false
  172.                 ) + " |";
  173.             }

  174.             System.out.println (display + "|");
  175.         }

  176.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  177.         System.out.println();

  178.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  179.         System.out.println ("\t|                                           CUMULATIVE DISTRIBUTION FUNCTION ESTIMATE                                          ||");

  180.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  181.         System.out.println ("\t|        L -> R:                                                                                                               ||");

  182.         System.out.println ("\t|                - Beta                                                                                                        ||");

  183.         System.out.println ("\t|                - Values for different t                                                                                      ||");

  184.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  185.         for (double beta : betaArray)
  186.         {
  187.             R1UnivariateScaledExponential r1UnivariateScaledExponential = new R1UnivariateScaledExponential (
  188.                 new ScaledExponentialEstimator (
  189.                     beta,
  190.                     1.
  191.                 ),
  192.                 gammaEstimator
  193.             );

  194.             String display = "\t| [" + FormatUtil.FormatDouble (beta, 1, 1, 1., false) + "] => ";

  195.             for (double t : tArray)
  196.             {
  197.                 display = display + " " + FormatUtil.FormatDouble (
  198.                     r1UnivariateScaledExponential.cumulative (t), 1, 8, 1., false
  199.                 ) + " |";
  200.             }

  201.             System.out.println (display + "|");
  202.         }

  203.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  204.         System.out.println();

  205.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  206.         System.out.println ("\t|                                       INVERSE CUMULATIVE DISTRIBUTION FUNCTION ESTIMATE                                      ||");

  207.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  208.         System.out.println ("\t|        L -> R:                                                                                                               ||");

  209.         System.out.println ("\t|                - Beta                                                                                                        ||");

  210.         System.out.println ("\t|                - Values for different p                                                                                      ||");

  211.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  212.         for (double beta : betaArray)
  213.         {
  214.             R1UnivariateScaledExponential r1UnivariateScaledExponential = new R1UnivariateScaledExponential (
  215.                 new ScaledExponentialEstimator (
  216.                     beta,
  217.                     1.
  218.                 ),
  219.                 gammaEstimator
  220.             );

  221.             String display = "\t| [" + FormatUtil.FormatDouble (beta, 1, 1, 1., false) + "] => ";

  222.             for (double p : pValueArray)
  223.             {
  224.                 display = display + " " + FormatUtil.FormatDouble (
  225.                     r1UnivariateScaledExponential.invCumulative (p), 1, 8, 1., false
  226.                 ) + " |";
  227.             }

  228.             System.out.println (display + "|");
  229.         }

  230.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  231.         EnvManager.TerminateEnv();
  232.     }
  233. }