R1Central.java

  1. package org.drip.measure.chisquare;

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

  74. /**
  75.  * <i>R1Central</i> implements the Probability Density Function for the R<sup>1</sup> Central Chi-Square
  76.  *  Distribution. The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  82.  *              on Mathematics</b>
  83.  *      </li>
  84.  *      <li>
  85.  *          Backstrom, T., and J. Fischer (2018): Fast Randomization for Distributed Low Bit-rate Coding of
  86.  *              Speech and Audio <i>IEEE/ACM Transactions on Audio, Speech, and Language Processing</i> <b>26
  87.  *              (1)</b> 19-30
  88.  *      </li>
  89.  *      <li>
  90.  *          Chi-Squared Distribution (2019): Chi-Squared Function
  91.  *              https://en.wikipedia.org/wiki/Chi-squared_distribution
  92.  *      </li>
  93.  *      <li>
  94.  *          Johnson, N. L., S. Kotz, and N. Balakrishnan (1994): <i>Continuous Univariate Distributions
  95.  *              2<sup>nd</sup> Edition</i> <b>John Wiley and Sons</b>
  96.  *      </li>
  97.  *      <li>
  98.  *          National Institute of Standards and Technology (2019): Chi-Squared Distribution
  99.  *              https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  100.  *      </li>
  101.  *  </ul>
  102.  *
  103.  *  <br><br>
  104.  *  <ul>
  105.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  106.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  107.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure/README.md">R<sup>d</sup> Continuous/Discrete Probability Measures</a></li>
  108.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure/chisquare/README.md">Chi-Square Distribution Implementation/Properties</a></li>
  109.  *  </ul>
  110.  *
  111.  * @author Lakshmi Krishnamurthy
  112.  */

  113. public class R1Central extends org.drip.measure.continuous.R1Univariate
  114. {
  115.     private double _degreesOfFreedom = -1;
  116.     private double _cdfScaler = java.lang.Double.NaN;
  117.     private double _normalizer = java.lang.Double.NaN;
  118.     private org.drip.function.definition.R1ToR1 _gammaEstimator = null;
  119.     private org.drip.function.definition.R1ToR1 _digammaEstimator = null;
  120.     private org.drip.function.definition.R2ToR1 _lowerIncompleteGammaEstimator = null;

  121.     /**
  122.      * Generate a Consolidated Chi-squared Distribution from Independent Component Distributions
  123.      *
  124.      * @param chiSquaredDistributionArray Independent Component Distribution Array
  125.      *
  126.      * @return Consolidated Chi-squared Distribution
  127.      */

  128.     public static final R1Central FromIndependentChiSquared (
  129.         final org.drip.measure.chisquare.R1Central[] chiSquaredDistributionArray)
  130.     {
  131.         if (null == chiSquaredDistributionArray || 0 == chiSquaredDistributionArray.length)
  132.         {
  133.             return null;
  134.         }

  135.         double degreesOfFreedom = 0;

  136.         for (org.drip.measure.chisquare.R1Central chiSquaredDistribution :
  137.             chiSquaredDistributionArray)
  138.         {
  139.             if (null == chiSquaredDistribution)
  140.             {
  141.                 return null;
  142.             }

  143.             degreesOfFreedom = degreesOfFreedom + chiSquaredDistribution.degreesOfFreedom();
  144.         }

  145.         try
  146.         {
  147.             return new R1Central (
  148.                 degreesOfFreedom,
  149.                 chiSquaredDistributionArray[0].gammaEstimator(),
  150.                 chiSquaredDistributionArray[0].digammaEstimator(),
  151.                 chiSquaredDistributionArray[0].lowerIncompleteGammaEstimator()
  152.             );
  153.         }
  154.         catch (java.lang.Exception e)
  155.         {
  156.             e.printStackTrace();
  157.         }

  158.         return null;
  159.     }

  160.     /**
  161.      * R1Central Constructor
  162.      *
  163.      * @param degreesOfFreedom Degrees of Freedom
  164.      * @param gammaEstimator Gamma Estimator
  165.      * @param digammaEstimator Digamma Estimator
  166.      * @param lowerIncompleteGammaEstimator Lower Incomplete Gamma Estimator
  167.      *
  168.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  169.      */

  170.     public R1Central (
  171.         final double degreesOfFreedom,
  172.         final org.drip.function.definition.R1ToR1 gammaEstimator,
  173.         final org.drip.function.definition.R1ToR1 digammaEstimator,
  174.         final org.drip.function.definition.R2ToR1 lowerIncompleteGammaEstimator)
  175.         throws java.lang.Exception
  176.     {
  177.         if (!org.drip.numerical.common.NumberUtil.IsValid (
  178.                 _degreesOfFreedom = degreesOfFreedom
  179.             ) || 0. >= _degreesOfFreedom ||
  180.             null == (_gammaEstimator = gammaEstimator) ||
  181.             null == (_digammaEstimator = digammaEstimator) ||
  182.             null == (_lowerIncompleteGammaEstimator = lowerIncompleteGammaEstimator))
  183.         {
  184.             throw new java.lang.Exception ("R1Central Constructor => Invalid Inputs");
  185.         }

  186.         double halfDOF = 0.5 * _degreesOfFreedom;

  187.         _normalizer = (_cdfScaler = 1. / _gammaEstimator.evaluate (halfDOF)) * java.lang.Math.pow (
  188.             2.,
  189.             -1. * halfDOF
  190.         );
  191.     }

  192.     /**
  193.      * Retrieve the Degrees of Freedom
  194.      *
  195.      * @return The Degrees of Freedom
  196.      */

  197.     public double degreesOfFreedom()
  198.     {
  199.         return _degreesOfFreedom;
  200.     }

  201.     /**
  202.      * Retrieve the Gamma Estimator
  203.      *
  204.      * @return Gamma Estimator
  205.      */

  206.     public org.drip.function.definition.R1ToR1 gammaEstimator()
  207.     {
  208.         return _gammaEstimator;
  209.     }

  210.     /**
  211.      * Retrieve the Digamma Estimator
  212.      *
  213.      * @return Digamma Estimator
  214.      */

  215.     public org.drip.function.definition.R1ToR1 digammaEstimator()
  216.     {
  217.         return _digammaEstimator;
  218.     }

  219.     /**
  220.      * Retrieve the Lower Incomplete Gamma Estimator
  221.      *
  222.      * @return Lower Incomplete Gamma Estimator
  223.      */

  224.     public org.drip.function.definition.R2ToR1 lowerIncompleteGammaEstimator()
  225.     {
  226.         return _lowerIncompleteGammaEstimator;
  227.     }

  228.     @Override public double[] support()
  229.     {
  230.         return new double[]
  231.         {
  232.             0.,
  233.             java.lang.Double.POSITIVE_INFINITY
  234.         };
  235.     }

  236.     @Override public double density (
  237.         final double t)
  238.         throws java.lang.Exception
  239.     {
  240.         if (!supported (t))
  241.         {
  242.             throw new java.lang.Exception ("R1Central::density => Variate not in Range");
  243.         }

  244.         return _normalizer * java.lang.Math.pow (
  245.             t,
  246.             0.5 * _degreesOfFreedom - 1.
  247.         ) * java.lang.Math.exp (-0.5 * t);
  248.     }

  249.     @Override public double cumulative (
  250.         final double t)
  251.         throws java.lang.Exception
  252.     {
  253.         if (!supported (t))
  254.         {
  255.             throw new java.lang.Exception ("R1Central::cumulative => Invalid Inputs");
  256.         }

  257.         return _cdfScaler * _lowerIncompleteGammaEstimator.evaluate (
  258.             0.5 * _degreesOfFreedom,
  259.             0.5 * t
  260.         );
  261.     }

  262.     @Override public double mean()
  263.         throws java.lang.Exception
  264.     {
  265.         return _degreesOfFreedom;
  266.     }

  267.     @Override public double median()
  268.         throws java.lang.Exception
  269.     {
  270.         double oneMinus_twoOver_9dof__ = 1. - (2. / (9. * _degreesOfFreedom));

  271.         return _degreesOfFreedom * oneMinus_twoOver_9dof__ * oneMinus_twoOver_9dof__ *
  272.             oneMinus_twoOver_9dof__;
  273.     }

  274.     @Override public double mode()
  275.         throws java.lang.Exception
  276.     {
  277.         return java.lang.Math.max (
  278.             _degreesOfFreedom - 2.,
  279.             0.
  280.         );
  281.     }

  282.     @Override public double variance()
  283.         throws java.lang.Exception
  284.     {
  285.         return 2. * _degreesOfFreedom;
  286.     }

  287.     @Override public double skewness()
  288.         throws java.lang.Exception
  289.     {
  290.         return java.lang.Math.sqrt (8. / _degreesOfFreedom);
  291.     }

  292.     @Override public double excessKurtosis()
  293.         throws java.lang.Exception
  294.     {
  295.         return 12. / _degreesOfFreedom;
  296.     }

  297.     @Override public double differentialEntropy()
  298.         throws java.lang.Exception
  299.     {
  300.         double halfDOF = 0.5 * _degreesOfFreedom;

  301.         return halfDOF + java.lang.Math.log (2. * _gammaEstimator.evaluate (halfDOF)) +
  302.             (1. - halfDOF) * _digammaEstimator.evaluate (halfDOF);
  303.     }

  304.     @Override public org.drip.function.definition.R1ToR1 momentGeneratingFunction()
  305.     {
  306.         return new org.drip.function.definition.R1ToR1 (null)
  307.         {
  308.             @Override public double evaluate (
  309.                 final double t)
  310.                 throws java.lang.Exception
  311.             {
  312.                 if (!org.drip.numerical.common.NumberUtil.IsValid (t) || t > 0.5)
  313.                 {
  314.                     throw new java.lang.Exception
  315.                         ("R1Central::momentGeneratingFunction::evaluate => Invalid Input");
  316.                 }

  317.                 return java.lang.Math.pow (
  318.                     1. - 2. * t,
  319.                     -0.5 * _degreesOfFreedom
  320.                 );
  321.             }
  322.         };
  323.     }

  324.     @Override public org.drip.function.definition.R1ToR1 probabilityGeneratingFunction()
  325.     {
  326.         return new org.drip.function.definition.R1ToR1 (null)
  327.         {
  328.             @Override public double evaluate (
  329.                 final double t)
  330.                 throws java.lang.Exception
  331.             {
  332.                 if (!org.drip.numerical.common.NumberUtil.IsValid (t) ||
  333.                     t <= 0. || t > java.lang.Math.sqrt (java.lang.Math.E))
  334.                 {
  335.                     throw new java.lang.Exception
  336.                         ("R1Central::probabilityGeneratingFunction::evaluate => Invalid Input");
  337.                 }

  338.                 return java.lang.Math.pow (
  339.                     1. - 2. * java.lang.Math.log (t),
  340.                     -0.5 * _degreesOfFreedom
  341.                 );
  342.             }
  343.         };
  344.     }

  345.     @Override public double random()
  346.         throws java.lang.Exception
  347.     {
  348.         double sumOfStandardNormalSquares = 0.;

  349.         for (int drawIndex = 0; drawIndex < _degreesOfFreedom; ++drawIndex)
  350.         {
  351.             double randomStandardNormal = org.drip.measure.gaussian.NormalQuadrature.InverseCDF
  352.                 (java.lang.Math.random());

  353.             sumOfStandardNormalSquares = sumOfStandardNormalSquares +
  354.                 randomStandardNormal * randomStandardNormal;
  355.         }

  356.         return sumOfStandardNormalSquares;
  357.     }

  358.     /**
  359.      * Retrieve the Normalizer
  360.      *
  361.      * @return Normalizer
  362.      */

  363.     public double normalizer()
  364.     {
  365.         return _normalizer;
  366.     }

  367.     /**
  368.      * Retrieve the CDF Scaler
  369.      *
  370.      * @return CDF Scaler
  371.      */

  372.     public double cdfScaler()
  373.     {
  374.         return _cdfScaler;
  375.     }

  376.     /**
  377.      * Compute the Chernoff Upper Bound
  378.      *
  379.      * @param x A
  380.      *
  381.      * @return The Chernoff Upper Bound
  382.      *
  383.      * @throws java.lang.Exception Thrown if the Chernoff Upper Bound cannot be calculated
  384.      */

  385.     public double chernoffBound (
  386.         final double x)
  387.         throws java.lang.Exception
  388.     {
  389.         if (!org.drip.numerical.common.NumberUtil.IsValid (x) || 0. >= x)
  390.         {
  391.             throw new java.lang.Exception ("R1Central::chernoffBound => Invalid Inputs");
  392.         }

  393.         double z = x / _degreesOfFreedom;

  394.         if (1. == z)
  395.         {
  396.             throw new java.lang.Exception ("R1Central::chernoffBound => Invalid Inputs");
  397.         }

  398.         double _zExponent_OneMinusZ__powerHalfDegreesOfFreedom = java.lang.Math.pow (
  399.             z * java.lang.Math.exp (1. - z),
  400.             0.5 * _degreesOfFreedom
  401.         );

  402.         return 1. > z ? _zExponent_OneMinusZ__powerHalfDegreesOfFreedom : 1. -
  403.             _zExponent_OneMinusZ__powerHalfDegreesOfFreedom;
  404.     }

  405.     /**
  406.      * Compute the Non-central Moment about Zero
  407.      *
  408.      * @param m Non-central Moment Index
  409.      *
  410.      * @return The Non-central Moment about Zero
  411.      *
  412.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  413.      */

  414.     public double nonCentralMoment (
  415.         final int m)
  416.         throws java.lang.Exception
  417.     {
  418.         if (0 > m)
  419.         {
  420.             throw new java.lang.Exception ("R1Central::nonCentralMoment => Invalid Inputs");
  421.         }

  422.         double halfDOF = 0.5 * _degreesOfFreedom;

  423.         return java.lang.Math.pow (
  424.             2.,
  425.             m
  426.         ) * _gammaEstimator.evaluate (m + halfDOF) / _gammaEstimator.evaluate (halfDOF);
  427.     }

  428.     /**
  429.      * Compute the Cumulant
  430.      *
  431.      * @param n Cumulant Index
  432.      *
  433.      * @return The Cumulant
  434.      *
  435.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  436.      */

  437.     public double cumulant (
  438.         final int n)
  439.         throws java.lang.Exception
  440.     {
  441.         if (0 > n)
  442.         {
  443.             throw new java.lang.Exception ("R1Central::cumulant => Invalid Inputs");
  444.         }

  445.         return _degreesOfFreedom * java.lang.Math.pow (
  446.             2.,
  447.             n - 1.
  448.         ) * _gammaEstimator.evaluate (n);
  449.     }

  450.     /**
  451.      * Retrieve the Central Limit Theorem Equivalent Normal Distribution Proxy
  452.      *
  453.      * @return The Central Limit Theorem Equivalent Normal Distribution Proxy
  454.      */

  455.     public org.drip.measure.gaussian.R1UnivariateNormal cltProxy()
  456.     {
  457.         try
  458.         {
  459.             return new org.drip.measure.gaussian.R1UnivariateNormal (
  460.                 _degreesOfFreedom,
  461.                 2. * _degreesOfFreedom
  462.             );
  463.         }
  464.         catch (java.lang.Exception e)
  465.         {
  466.             e.printStackTrace();
  467.         }

  468.         return null;
  469.     }

  470.     /**
  471.      * Indicate if the Current Distribution is a Valid Proxy as a CLT
  472.      *
  473.      * @return TRUE - The Current Distribution is a Valid Proxy as a CLT
  474.      */

  475.     public boolean validCLTProxy()
  476.     {
  477.         return 50. <= _degreesOfFreedom;
  478.     }

  479.     /**
  480.      * Generate a Gamma-distribution off of the Scaled Chi-Square Distribution
  481.      *
  482.      * @param scale The Scale
  483.      *
  484.      * @return The Gamma Distribution
  485.      */

  486.     public org.drip.measure.gamma.R1ShapeScaleDistribution gammaDistribution (
  487.         final double scale)
  488.     {
  489.         try
  490.         {
  491.             return new org.drip.measure.gamma.R1ShapeScaleDistribution (
  492.                 new org.drip.measure.gamma.ShapeScaleParameters (
  493.                     0.5 * _degreesOfFreedom,
  494.                     2. * scale
  495.                 ),
  496.                 _gammaEstimator,
  497.                 _digammaEstimator,
  498.                 _lowerIncompleteGammaEstimator
  499.             );
  500.         }
  501.         catch (java.lang.Exception e)
  502.         {
  503.             e.printStackTrace();
  504.         }

  505.         return null;
  506.     }

  507.     /**
  508.      * Generate Logarithm Proxy Based Random Number - Proxy to Univariate Normal Distribution
  509.      *
  510.      * @return Logarithm Proxy Based Random Number - Proxy to Univariate Normal Distribution
  511.      *
  512.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  513.      */

  514.     public double randomLogProxy()
  515.         throws java.lang.Exception
  516.     {
  517.         return java.lang.Math.log (_degreesOfFreedom);
  518.     }

  519.     /**
  520.      * Generate CLT Proxy Based Random Number - Proxy to Univariate Normal Distribution
  521.      *
  522.      * @return CLT Proxy Based Random Number - Proxy to Univariate Normal Distribution
  523.      *
  524.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  525.      */

  526.     public double randomCLTProxy()
  527.         throws java.lang.Exception
  528.     {
  529.         return (random() - _degreesOfFreedom) / java.lang.Math.sqrt (2. * _degreesOfFreedom);
  530.     }

  531.     /**
  532.      * Generate Fisher Proxy Random Number - Proxy to Univariate Normal Distribution
  533.      *
  534.      * @return Fisher Proxy Random Number - Proxy to Univariate Normal Distribution
  535.      *
  536.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  537.      */

  538.     public double randomFisherProxy()
  539.         throws java.lang.Exception
  540.     {
  541.         return java.lang.Math.sqrt (2. * random());
  542.     }

  543.     /**
  544.      * Generate Wilson-Hilferty Proxy Random Number - Proxy to Univariate Normal Distribution
  545.      *
  546.      * @return Wilson-Hilferty Proxy Random Number - Proxy to Univariate Normal Distribution
  547.      *
  548.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  549.      */

  550.     public double randomWilsonHilferty()
  551.         throws java.lang.Exception
  552.     {
  553.         return java.lang.Math.pow (
  554.             random() / _degreesOfFreedom,
  555.             1. / 3.
  556.         );
  557.     }

  558.     /**
  559.      * Generate Gamma Distributed Random Number
  560.      *
  561.      * @param c The Scale Parameter
  562.      *
  563.      * @return Gamma Distributed Random Number
  564.      *
  565.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  566.      */

  567.     public double randomGamma (
  568.         final double c)
  569.         throws java.lang.Exception
  570.     {
  571.         if (!org.drip.numerical.common.NumberUtil.IsValid (c) || 0. >= c)
  572.         {
  573.             throw new java.lang.Exception ("R1Central::randomGamma => Invalid Inputs");
  574.         }

  575.         return random() * c;
  576.     }

  577.     /**
  578.      * Generate the Chi Distributed Random Number
  579.      *
  580.      * @return Chi Distributed Random Number
  581.      *
  582.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  583.      */

  584.     public double randomChi()
  585.         throws java.lang.Exception
  586.     {
  587.         return java.lang.Math.sqrt (random());
  588.     }

  589.     /**
  590.      * Generate Exponential (0.5) Distributed Random Number
  591.      *
  592.      * @return Exponential (0.5) Distributed Random Number
  593.      *
  594.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  595.      */

  596.     public double randomExponentialHalf()
  597.         throws java.lang.Exception
  598.     {
  599.         if (2. != _degreesOfFreedom)
  600.         {
  601.             throw new java.lang.Exception ("R1Central::randomExponentialHalf => Invalid Inputs");
  602.         }

  603.         return random();
  604.     }

  605.     /**
  606.      * Generate Rayleigh (1) Distributed Random Number
  607.      *
  608.      * @return Rayleigh (1) Distributed Random Number
  609.      *
  610.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  611.      */

  612.     public double randomRayleigh1()
  613.         throws java.lang.Exception
  614.     {
  615.         if (2. != _degreesOfFreedom)
  616.         {
  617.             throw new java.lang.Exception ("R1Central::randomRayleigh1 => Invalid Inputs");
  618.         }

  619.         return random();
  620.     }

  621.     /**
  622.      * Generate Maxwell (1) Distributed Random Number
  623.      *
  624.      * @return Maxwell (1) Distributed Random Number
  625.      *
  626.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  627.      */

  628.     public double randomMaxwell1()
  629.         throws java.lang.Exception
  630.     {
  631.         if (3. != _degreesOfFreedom)
  632.         {
  633.             throw new java.lang.Exception ("R1Central::randomMaxwell1 => Invalid Inputs");
  634.         }

  635.         return random();
  636.     }
  637. }