CoveringNumberLossBound.java

  1. package org.drip.learning.bound;

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

  78. /**
  79.  * <i>CoveringNumberLossBound provides</i> the Upper Probability Bound that the Loss/Deviation of the
  80.  * Empirical from the Actual Mean of the given Learner Class exceeds 'epsilon', using the Covering Number
  81.  * Generalization Bounds. This is expressed as
  82.  * <br><br>
  83.  *                          C1 (n) * N (epsilon, n) * exp (-n.epsilon^b/C2)
  84.  * <br><br>
  85.  * where:
  86.  * <ul>
  87.  *  <li>
  88.  *      n is the Size of the Sample
  89.  *  </li>
  90.  *  <li>
  91.  *      'epsilon' is the Deviation Empirical Mean from the Population Mean
  92.  *  </li>
  93.  *  <li>
  94.  *      C1 (n) is the sample coefficient function
  95.  *  </li>
  96.  *  <li>
  97.  *      C2 is an exponent scaling constant
  98.  *  </li>
  99.  *  <li>
  100.  *      'b' an exponent ((i.e., the Epsilon Exponent) that depends on the setting (i.e.,
  101.  *          agnostic/classification/regression/convex etc)
  102.  *  </li>
  103.  * </ul>
  104.  * <br><br>
  105.  *  
  106.  *  The References are:
  107.  *  
  108.  * <br><br>
  109.  * <ul>
  110.  *  <li>
  111.  *      Alon, N., S. Ben-David, N. Cesa Bianchi, and D. Haussler (1997): Scale-sensitive Dimensions, Uniform
  112.  *          Convergence, and Learnability <i>Journal of Association of Computational Machinery</i> <b>44
  113.  *          (4)</b> 615-631
  114.  *  </li>
  115.  *  <li>
  116.  *      Anthony, M., and P. L. Bartlett (1999): <i>Artificial Neural Network Learning - Theoretical
  117.  *          Foundations</i> <b>Cambridge University Press</b> Cambridge, UK
  118.  *  </li>
  119.  *  <li>
  120.  *      Kearns, M. J., R. E. Schapire, and L. M. Sellie (1994): <i>Towards Efficient Agnostic Learning</i>
  121.  *          Machine Learning <b>17 (2)</b> 115-141
  122.  *  </li>
  123.  *  <li>
  124.  *      Lee, W. S., P. L. Bartlett, and R. C. Williamson (1998): The Importance of Convexity in Learning with
  125.  *          Squared Loss <i>IEEE Transactions on Information Theory</i> <b>44</b> 1974-1980
  126.  *  </li>
  127.  *  <li>
  128.  *      Vapnik, V. N. (1998): <i>Statistical learning Theory</i> <b>Wiley</b> New York
  129.  *  </li>
  130.  * </ul>
  131.  *
  132.  *  <br><br>
  133.  *  <ul>
  134.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  135.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning</a></li>
  136.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/learning">Agnostic Learning Bounds under Empirical Loss Minimization Schemes</a></li>
  137.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/learning/bound">Covering Numbers, Concentration, Lipschitz Bounds</a></li>
  138.  *  </ul>
  139.  *
  140.  * @author Lakshmi Krishnamurthy
  141.  */

  142. public class CoveringNumberLossBound {
  143.     private double _dblExponentScaler = java.lang.Double.NaN;
  144.     private double _dblEpsilonExponent = java.lang.Double.NaN;
  145.     private org.drip.function.definition.R1ToR1 _funcSampleCoefficient = null;

  146.     /**
  147.      * CoveringNumberLossBound Constructor
  148.      *
  149.      * @param funcSampleCoefficient The Sample Coefficient Function
  150.      * @param dblEpsilonExponent The Epsilon Exponent
  151.      * @param dblExponentScaler The Exponent Scaler
  152.      *
  153.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  154.      */

  155.     public CoveringNumberLossBound (
  156.         final org.drip.function.definition.R1ToR1 funcSampleCoefficient,
  157.         final double dblEpsilonExponent,
  158.         final double dblExponentScaler)
  159.         throws java.lang.Exception
  160.     {
  161.         if (null == (_funcSampleCoefficient = funcSampleCoefficient) ||
  162.             !org.drip.numerical.common.NumberUtil.IsValid (_dblEpsilonExponent = dblEpsilonExponent) ||
  163.                 !org.drip.numerical.common.NumberUtil.IsValid (_dblExponentScaler = dblExponentScaler))
  164.             throw new java.lang.Exception ("CoveringNumberLossBound ctr: Invalid Inputs");
  165.     }

  166.     /**
  167.      * Retrieve the Sample Coefficient Function
  168.      *
  169.      * @return The Sample Coefficient Function
  170.      */

  171.     public org.drip.function.definition.R1ToR1 sampleCoefficient()
  172.     {
  173.         return _funcSampleCoefficient;
  174.     }

  175.     /**
  176.      * Retrieve the Exponential Epsilon Exponent
  177.      *
  178.      * @return The Exponential Epsilon Exponent
  179.      */

  180.     public double epsilonExponent()
  181.     {
  182.         return _dblEpsilonExponent;
  183.     }

  184.     /**
  185.      * Retrieve the Exponent Scaler
  186.      *
  187.      * @return The Exponent Scaler
  188.      */

  189.     public double exponentScaler()
  190.     {
  191.         return _dblExponentScaler;
  192.     }

  193.     /**
  194.      * Compute the Upper Bound of the Probability of the Absolute Deviation between the Empirical and the
  195.      *  Population Means
  196.      *
  197.      * @param iSampleSize The Sample Size
  198.      * @param dblEpsilon The Deviation between Population and Empirical Means
  199.      *
  200.      * @return The Upper Bound of the Probability of the Deviation between the Empirical and the Population
  201.      *  Means
  202.      *
  203.      * @throws java.lang.Exception Thrown if the Upper Bound of the Probability cannot be computed
  204.      */

  205.     public double deviationProbabilityUpperBound (
  206.         final int iSampleSize,
  207.         final double dblEpsilon)
  208.         throws java.lang.Exception
  209.     {
  210.         if (0 >= iSampleSize || !org.drip.numerical.common.NumberUtil.IsValid (dblEpsilon) || 0. >= dblEpsilon)
  211.             throw new java.lang.Exception
  212.                 ("CoveringNumberLossBound::deviationProbabilityUpperBound => Invalid Inputs");

  213.         return _funcSampleCoefficient.evaluate (iSampleSize) * java.lang.Math.exp (-1. * iSampleSize *
  214.             java.lang.Math.pow (dblEpsilon, _dblEpsilonExponent) / _dblExponentScaler);
  215.     }
  216. }