GlivenkoCantelliFunctionSupremum.java

  1. package org.drip.sequence.custom;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

  66. /**
  67.  * <i>GlivenkoCantelliFunctionSupremum</i> contains the Implementation of the Supremum Class Objective
  68.  * Function dependent on Multivariate Random Variables where the Multivariate Function is a Linear
  69.  * Combination of Bounded Univariate Functions acting on each Random Variate.
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  74.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning Library</a></li>
  75.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sequence">Sequence</a></li>
  76.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sequence/custom">Custom</a></li>
  77.  *  </ul>
  78.  * <br><br>
  79.  *
  80.  * @author Lakshmi Krishnamurthy
  81.  */

  82. public class GlivenkoCantelliFunctionSupremum extends org.drip.sequence.functional.MultivariateRandom
  83.     implements org.drip.sequence.functional.SeparableMultivariateRandom {
  84.     private double[] _adblWeight = null;
  85.     private org.drip.sequence.functional.FunctionSupremumUnivariateRandom _fsur = null;

  86.     /**
  87.      * Construct an Instance of GlivenkoCantelliFunctionSupremum from the Sample
  88.      *
  89.      * @param fsur The Supremum Univariate Random Function
  90.      * @param iNumSample Number of Empirical Samples
  91.      *
  92.      * @return The GlivenkoCantelliFunctionSupremum Instance
  93.      */

  94.     public static final GlivenkoCantelliFunctionSupremum Create (
  95.         final org.drip.sequence.functional.FunctionSupremumUnivariateRandom fsur,
  96.         final int iNumSample)
  97.     {
  98.         try {
  99.             return new GlivenkoCantelliFunctionSupremum (fsur,
  100.                 org.drip.analytics.support.Helper.NormalizedEqualWeightedArray (iNumSample));
  101.         } catch (java.lang.Exception e) {
  102.             e.printStackTrace();
  103.         }

  104.         return null;
  105.     }

  106.     /**
  107.      * GlivenkoCantelliFunctionSupremum Constructor
  108.      *
  109.      * @param fsur The Supremum Univariate Random Function
  110.      * @param adblWeight Array of Variable Weights
  111.      *
  112.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  113.      */

  114.     public GlivenkoCantelliFunctionSupremum (
  115.         final org.drip.sequence.functional.FunctionSupremumUnivariateRandom fsur,
  116.         final double[] adblWeight)
  117.         throws java.lang.Exception
  118.     {
  119.         if (null == (_adblWeight = adblWeight) || 0 == _adblWeight.length || null == (_fsur = fsur))
  120.             throw new java.lang.Exception ("GlivenkoCantelliFunctionSupremum ctr: Invalid Inputs");
  121.     }

  122.     /**
  123.      * Retrieve the Supremum Univariate Random Function
  124.      *
  125.      * @return The Supremum Univariate Random Function
  126.      */

  127.     public org.drip.sequence.functional.FunctionSupremumUnivariateRandom separableUnivariateRandom()
  128.     {
  129.         return _fsur;
  130.     }

  131.     /**
  132.      * Retrieve the Weights
  133.      *
  134.      * @return The Weights
  135.      */

  136.     public double[] weights()
  137.     {
  138.         return _adblWeight;
  139.     }

  140.     @Override public int dimension()
  141.     {
  142.         return org.drip.function.definition.RdToR1.DIMENSION_NOT_FIXED;
  143.     }

  144.     @Override public double evaluate (
  145.         final double[] adblVariate)
  146.         throws java.lang.Exception
  147.     {
  148.         double dblValue = 0.;
  149.         int iNumVariate = adblVariate.length;

  150.         if (_adblWeight.length < iNumVariate)
  151.             throw new java.lang.Exception ("GlivenkoCantelliFunctionSupremum::evaluate => Invalid Inputs");

  152.         for (int i = 0; i < iNumVariate; ++i)
  153.             dblValue += _adblWeight[i] * _fsur.evaluate (adblVariate[i]);

  154.         return dblValue;
  155.     }

  156.     @Override public double targetVariateVariance (
  157.         final int iTargetVariateIndex)
  158.         throws java.lang.Exception
  159.     {
  160.         org.drip.sequence.metrics.SingleSequenceAgnosticMetrics ssam = _fsur.sequenceMetrics();

  161.         if (null == ssam)
  162.             throw new java.lang.Exception
  163.                 ("GlivenkoCantelliFunctionSupremum::targetVariateVariance => Cannot calculate Target Variate Metrics");

  164.         return _adblWeight[iTargetVariateIndex] * ssam.empiricalVariance();
  165.     }
  166. }