ScaleSensitiveCoveringBounds.java

  1. package org.drip.spaces.cover;

  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>ScaleSensitiveCoveringBounds</i> implements the Lower/Upper Bounds for the General Class of Functions
  80.  * in terms of their scale-sensitive dimensions (i.e., the fat shattering coefficients). The References are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          N. Alon, S. Ben-David, N. Cesa-Bianchi, and D. Haussler (1993): Scale-sensitive Dimensions,
  86.  *              Uniform-Convergence, and Learnability <i>Proceedings of the ACM Symposium on the Foundations
  87.  *                  of Computer Science</i>
  88.  *      </li>
  89.  *      <li>
  90.  *          P. L. Bartlett, S. R. Kulkarni, and S. E. Posner (1997): Covering Numbers for Real-valued
  91.  *              Function Classes <i>IEEE Transactions on Information Theory</i> <b>43 (5)</b> 1721-1724
  92.  *      </li>
  93.  *      <li>
  94.  *          D. Pollard (1984): <i>Convergence of Stochastic Processes</i> <b>Springer</b> New York
  95.  *      </li>
  96.  *  </ul>
  97.  *
  98.  * <br><br>
  99.  *  <ul>
  100.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  101.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning Library</a></li>
  102.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spaces/README.md">R<sup>1</sup> and R<sup>d</sup> Vector/Tensor Spaces (Validated and/or Normed), and Function Classes</a></li>
  103.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spaces/cover/README.md">Vector Spaces Covering Number Estimator</a></li>
  104.  *  </ul>
  105.  * <br><br>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public class ScaleSensitiveCoveringBounds implements org.drip.spaces.cover.FunctionClassCoveringBounds {
  110.     private int _iSampleSize = -1;
  111.     private org.drip.function.definition.R1ToR1 _r1r1FatShatter = null;

  112.     /**
  113.      * ScaleSensitiveCoveringBounds Constructor
  114.      *
  115.      * @param r1r1FatShatter The Cover Fat Shattering Coefficient Function
  116.      * @param iSampleSize Sample Size
  117.      *
  118.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  119.      */

  120.     public ScaleSensitiveCoveringBounds (
  121.         final org.drip.function.definition.R1ToR1 r1r1FatShatter,
  122.         final int iSampleSize)
  123.         throws java.lang.Exception
  124.     {
  125.         if (null == (_r1r1FatShatter = r1r1FatShatter) || 0 >= (_iSampleSize = iSampleSize))
  126.             throw new java.lang.Exception ("ScaleSensitiveCoveringBounds ctr: Invalid Inputs");
  127.     }

  128.     /**
  129.      * Retrieve the Fat Shattering Coefficient Function
  130.      *
  131.      * @return The Fat Shattering Coefficient Function
  132.      */

  133.     public org.drip.function.definition.R1ToR1 fatShatteringFunction()
  134.     {
  135.         return _r1r1FatShatter;
  136.     }

  137.     /**
  138.      * Retrieve the Sample Size
  139.      *
  140.      * @return The Sample Size
  141.      */

  142.     public int sampleSize()
  143.     {
  144.         return _iSampleSize;
  145.     }

  146.     /**
  147.      * Compute the Minimum Sample Size required to Estimate the Cardinality corresponding to the Specified
  148.      *  Cover
  149.      *
  150.      * @param dblCover The Cover
  151.      *
  152.      * @return The Minimum Sample Size
  153.      *
  154.      * @throws java.lang.Exception Thrown if the Minimum Sample Size Cannot be computed
  155.      */

  156.     public double sampleSizeLowerBound (
  157.         final double dblCover)
  158.         throws java.lang.Exception
  159.     {
  160.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCover) || 0. == dblCover)
  161.             throw new java.lang.Exception
  162.                 ("ScaleSensitiveCoveringBounds::sampleSizeLowerBound => Invalid Inputs");

  163.         double dblLog2 = java.lang.Math.log (2.);

  164.         return 2. * _r1r1FatShatter.evaluate (0.25 * dblCover) * java.lang.Math.log (64. * java.lang.Math.E *
  165.             java.lang.Math.E / (dblCover * dblLog2)) / dblLog2;
  166.     }

  167.     /**
  168.      * Compute the Cardinality for the Subset T (|x) that possesses the Specified Cover for the Restriction
  169.      *  of the Input Function Class Family F (|x).
  170.      *  
  171.      * @param dblCover The Specified Cover
  172.      *
  173.      * @return The Restricted Subset Cardinality
  174.      *
  175.      * @throws java.lang.Exception Thrown if the Restricted Subset Cardinality cannot be computed
  176.      */

  177.     public double restrictedSubsetCardinality (
  178.         final double dblCover)
  179.         throws java.lang.Exception
  180.     {
  181.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCover) || 0. == dblCover)
  182.             throw new java.lang.Exception
  183.                 ("ScaleSensitiveCoveringBounds::restrictedSubsetCardinality => Invalid Inputs");

  184.         double dblLog2 = java.lang.Math.log (2.);

  185.         double dblFatShatteringCoefficient = _r1r1FatShatter.evaluate (0.25 * dblCover);

  186.         if (_iSampleSize < 2. * dblFatShatteringCoefficient * java.lang.Math.log (64. * java.lang.Math.E *
  187.             java.lang.Math.E / (dblCover * dblLog2)) / dblLog2)
  188.             throw new java.lang.Exception
  189.                 ("ScaleSensitiveCoveringBounds::restrictedSubsetCardinality => Invalid Inputs");

  190.         return 6. * dblFatShatteringCoefficient * java.lang.Math.log (16. / dblCover) * java.lang.Math.log
  191.             (32. * java.lang.Math.E * _iSampleSize / (dblFatShatteringCoefficient * dblCover)) / dblLog2 +
  192.                 dblLog2;
  193.     }

  194.     /**
  195.      * Compute the Log of the Weight Loading Coefficient for the Maximum Cover Term in:
  196.      *
  197.      *  {Probability that the Empirical Error .gt. Cover} .lte. 4 * exp (-m * Cover^2 / 128) *
  198.      *      [[Max Covering Number Over the Specified Sample]]
  199.      *
  200.      * Reference is:
  201.      *
  202.      *  - D. Haussler (1995): Sphere Packing Numbers for Subsets of the Boolean n-Cube with Bounded
  203.      *      Vapnik-Chervonenkis Dimension, Journal of the COmbinatorial Theory A 69 (2) 217.
  204.      *
  205.      * @param dblCover The Specified Cover
  206.      *
  207.      * @return Log of the Weight Loading Coefficient for the Maximum Cover Term
  208.      *
  209.      * @throws java.lang.Exception Thrown if the Log of the Weight Loading Coefficient cannot be computed
  210.      */

  211.     public double upperProbabilityBoundWeight (
  212.         final double dblCover)
  213.         throws java.lang.Exception
  214.     {
  215.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCover) || 0. == dblCover)
  216.             throw new java.lang.Exception
  217.                 ("ScaleSensitiveCoveringBounds::upperProbabilityBoundWeight => Invalid Inputs");

  218.         return java.lang.Math.log (4.) - (dblCover * dblCover * _iSampleSize / 128.);
  219.     }

  220.     @Override public double logLowerBound (
  221.         final double dblCover)
  222.         throws java.lang.Exception
  223.     {
  224.         return restrictedSubsetCardinality (dblCover);
  225.     }

  226.     @Override public double logUpperBound (
  227.         final double dblCover)
  228.         throws java.lang.Exception
  229.     {
  230.         return _r1r1FatShatter.evaluate (4. * dblCover) / 32.;
  231.     }
  232. }