IntegralOperator.java

  1. package org.drip.learning.kernel;

  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>IntegralOperator</i> implements the R<sup>x</sup> L<sub>2</sub> To R<sup>x</sup> L<sub>2</sub> Mercer
  80.  *  Kernel Integral Operator defined by:
  81.  *
  82.  *      T_k [f(.)] := Integral Over Input Space {k (., y) * f(y) * d[Prob(y)]}
  83.  *  
  84.  * <br><br>
  85.  *  The References are:
  86.  * <br><br>
  87.  * <ul>
  88.  *  <li>
  89.  *      Ash, R. (1965): <i>Information Theory</i> <b>Inter-science</b> New York
  90.  *  </li>
  91.  *  <li>
  92.  *      Konig, H. (1986): <i>Eigenvalue Distribution of Compact Operators</i> <b>Birkhauser</b> Basel,
  93.  *          Switzerland
  94.  *  </li>
  95.  *  <li>
  96.  *      Smola, A. J., A. Elisseff, B. Scholkopf, and R. C. Williamson (2000): Entropy Numbers for Convex
  97.  *          Combinations and mlps, in: <i>Advances in Large Margin Classifiers, A. Smola, P. Bartlett, B.
  98.  *          Scholkopf, and D. Schuurmans - editors</i> <b>MIT Press</b> Cambridge, MA
  99.  *  </li>
  100.  * </ul>
  101.  *
  102.  *  <br><br>
  103.  *  <ul>
  104.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  105.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning</a></li>
  106.  *      <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>
  107.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/learning/kernel">Statistical Learning Banach Mercer Kernels</a></li>
  108.  *  </ul>
  109.  *
  110.  * @author Lakshmi Krishnamurthy
  111.  */

  112. public abstract class IntegralOperator {
  113.     private org.drip.measure.continuous.Rd _distRd = null;
  114.     private org.drip.function.definition.RdToR1 _funcRdToR1 = null;
  115.     private org.drip.spaces.metric.R1Normed _r1OperatorOutput = null;
  116.     private org.drip.learning.kernel.SymmetricRdToNormedR1Kernel _kernel = null;

  117.     /**
  118.      * IntegralOperator Constructor
  119.      *
  120.      * @param kernel The Symmetric Mercer Kernel - this should be R^x L2 X R^x L2 To R^1
  121.      * @param funcRdToR1 The R^d To R^1 Operator Function
  122.      * @param r1OperatorOutput The Kernel Integral Operator Output Space - this is R^1 L2
  123.      *
  124.      * @throws java.lang.Exception Thrown if the Inputs are invalid
  125.      */

  126.     public IntegralOperator (
  127.         final org.drip.learning.kernel.SymmetricRdToNormedR1Kernel kernel,
  128.         final org.drip.function.definition.RdToR1 funcRdToR1,
  129.         final org.drip.spaces.metric.R1Normed r1OperatorOutput)
  130.         throws java.lang.Exception
  131.     {
  132.         if (null == (_kernel = kernel) || null == (_funcRdToR1 = funcRdToR1) || null == (_r1OperatorOutput =
  133.             r1OperatorOutput) || null == (_distRd = _kernel.inputMetricVectorSpace().borelSigmaMeasure()))
  134.             throw new java.lang.Exception ("IntegralOperator ctr: Invalid Inputs");
  135.     }

  136.     /**
  137.      * Retrieve the Symmetric R^d To R^1 Kernel
  138.      *
  139.      * @return The Symmetric R^d To R^1 Kernel
  140.      */

  141.     public org.drip.learning.kernel.SymmetricRdToNormedR1Kernel kernel()
  142.     {
  143.         return _kernel;
  144.     }

  145.     /**
  146.      * Retrieve the R^d To R^1 Kernel Operator Function
  147.      *
  148.      * @return The R^d To R^1 Kernel Operator Function
  149.      */

  150.     public org.drip.function.definition.RdToR1 kernelOperatorFunction()
  151.     {
  152.         return _funcRdToR1;
  153.     }

  154.     /**
  155.      * Retrieve the Input Space Borel Sigma Measure
  156.      *
  157.      * @return The Input Space Borel Sigma Measure
  158.      */

  159.     public org.drip.measure.continuous.Rd inputSpaceBorelMeasure()
  160.     {
  161.         return _distRd;
  162.     }

  163.     /**
  164.      * Retrieve the Kernel Integral Operator Output Space
  165.      *
  166.      * @return The Kernel Integral Operator Output Space
  167.      */

  168.     public org.drip.spaces.metric.R1Normed outputVectorMetricSpace()
  169.     {
  170.         return _r1OperatorOutput;
  171.     }

  172.     /**
  173.      * Compute the Operator's Kernel Integral across the specified X Variate Instance
  174.      *
  175.      * @param adblX Validated Vector Instance X
  176.      *
  177.      * @return The Operator's Kernel Integral across the specified X Variate Instance
  178.      *
  179.      * @throws java.lang.Exception Thrown if the Inputs are invalid
  180.      */

  181.     public double computeOperatorIntegral (
  182.         final double[] adblX)
  183.         throws java.lang.Exception
  184.     {
  185.         org.drip.function.definition.RdToR1 funcRdToR1 = new org.drip.function.definition.RdToR1 (null) {
  186.             @Override public int dimension()
  187.             {
  188.                 return null == adblX ? 0 : adblX.length;
  189.             }

  190.             @Override public double evaluate (
  191.                 final double[] adblY)
  192.                 throws java.lang.Exception
  193.             {
  194.                 return _kernel.evaluate (adblX, adblY) * _funcRdToR1.evaluate (adblY);
  195.             }
  196.         };

  197.         return _kernel.inputMetricVectorSpace().borelMeasureSpaceExpectation (funcRdToR1);
  198.     }

  199.     /**
  200.      * Indicate the Kernel Operator Integral's Positive-definiteness across the specified X Variate Instance
  201.      *
  202.      * @param adblX Validated Vector Instance X
  203.      *
  204.      * @return TRUE - The Kernel Operator Integral is Positive Definite across the specified X Variate
  205.      *  Instance
  206.      */

  207.     public boolean isPositiveDefinite (
  208.         final double[] adblX)
  209.     {
  210.         try {
  211.             return 0 < computeOperatorIntegral (adblX);
  212.         } catch (java.lang.Exception e) {
  213.             e.printStackTrace();
  214.         }

  215.         return false;
  216.     }

  217.     /**
  218.      * Eigenize the Kernel Integral Operator
  219.      *
  220.      * @return The Eigenization Output
  221.      */

  222.     public abstract org.drip.learning.kernel.IntegralOperatorEigenContainer eigenize();
  223. }