NecessarySufficientConditions.java

  1. package org.drip.optimization.constrained;

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

  77. /**
  78.  * <i>NecessarySufficientConditions</i> holds the Results of the Verification of the Necessary and the
  79.  * Sufficient Conditions at the specified (possibly) Optimal Variate and the corresponding Fritz John
  80.  * Multiplier Suite. The References are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Boyd, S., and L. van den Berghe (2009): <i>Convex Optimization</i> <b>Cambridge University
  86.  *              Press</b> Cambridge UK
  87.  *      </li>
  88.  *      <li>
  89.  *          Eustaquio, R., E. Karas, and A. Ribeiro (2008): <i>Constraint Qualification for Nonlinear
  90.  *              Programming</i> <b>Federal University of Parana</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Karush, A. (1939): <i>Minima of Functions of Several Variables with Inequalities as Side
  94.  *          Constraints</i> <b>University of Chicago</b> Chicago IL
  95.  *      </li>
  96.  *      <li>
  97.  *          Kuhn, H. W., and A. W. Tucker (1951): Nonlinear Programming <i>Proceedings of the Second Berkeley
  98.  *              Symposium</i> <b>University of California</b> Berkeley CA 481-492
  99.  *      </li>
  100.  *      <li>
  101.  *          Ruszczynski, A. (2006): <i>Nonlinear Optimization</i> <b>Princeton University Press</b> Princeton
  102.  *              NJ
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer Library</a></li>
  110.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/optimization/README.md">Necessary, Sufficient, and Regularity Checks for Gradient Descent in a Constrained Optimization Setup</a></li>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/optimization/constrained/README.md">KKT Fritz-John Constrained Optimizer</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class NecessarySufficientConditions {
  117.     private double[] _adblVariate = null;
  118.     private boolean _bCheckForMinima = false;
  119.     private org.drip.optimization.constrained.FritzJohnMultipliers _fjm = null;
  120.     private org.drip.optimization.necessary.ConditionQualifierFONC _cqFONC = null;
  121.     private org.drip.optimization.necessary.ConditionQualifierSOSC _cqSOSC = null;
  122.     private org.drip.optimization.necessary.ConditionQualifierDualFeasibility _cqDualFeasibility = null;
  123.     private org.drip.optimization.necessary.ConditionQualifierPrimalFeasibility _cqPrimalFeasibility =
  124.         null;
  125.     private org.drip.optimization.necessary.ConditionQualifierComplementarySlackness
  126.         _cqComplementarySlackness = null;

  127.     /**
  128.      * Create a Standard Instance of NecessarySufficientConditions
  129.      *
  130.      * @param adblVariate The Candidate Variate Array
  131.      * @param fjm The Fritz John Multipliers
  132.      * @param bCheckForMinima TRUE - Check For Minima
  133.      * @param bPrimalFeasibilityValidity The Primal Feasibility Validity
  134.      * @param bDualFeasibilityValidity The Dual Feasibility Validity
  135.      * @param bComplementarySlacknessValidity The Complementary Slackness Validity
  136.      * @param bFONCValidity The FONC Validity
  137.      * @param bSOSCValidity The SOSC Validity
  138.      *
  139.      * @return The Standard NecessarySufficientConditions Instance
  140.      */

  141.     public static final NecessarySufficientConditions Standard (
  142.         final double[] adblVariate,
  143.         final org.drip.optimization.constrained.FritzJohnMultipliers fjm,
  144.         final boolean bCheckForMinima,
  145.         final boolean bPrimalFeasibilityValidity,
  146.         final boolean bDualFeasibilityValidity,
  147.         final boolean bComplementarySlacknessValidity,
  148.         final boolean bFONCValidity,
  149.         final boolean bSOSCValidity)
  150.     {
  151.         try {
  152.             return new NecessarySufficientConditions (adblVariate, fjm, bCheckForMinima, new
  153.                 org.drip.optimization.necessary.ConditionQualifierPrimalFeasibility
  154.                     (bPrimalFeasibilityValidity), new
  155.                         org.drip.optimization.necessary.ConditionQualifierDualFeasibility
  156.                             (bDualFeasibilityValidity), new
  157.                                 org.drip.optimization.necessary.ConditionQualifierComplementarySlackness
  158.                                     (bComplementarySlacknessValidity), new
  159.                                         org.drip.optimization.necessary.ConditionQualifierFONC
  160.                                             (bFONCValidity), new
  161.                                                 org.drip.optimization.necessary.ConditionQualifierSOSC
  162.                                                     (bSOSCValidity));
  163.         } catch (java.lang.Exception e) {
  164.             e.printStackTrace();
  165.         }

  166.         return null;
  167.     }

  168.     /**
  169.      * NecessarySufficientConditions Constructor
  170.      *
  171.      * @param adblVariate The Candidate Variate Array
  172.      * @param fjm The Fritz John Multipliers
  173.      * @param bCheckForMinima TRUE - Check For Minima
  174.      * @param cqPrimalFeasibility The Primal Feasibility Necessary Condition
  175.      * @param cqDualFeasibility The Dual Feasibility Necessary Condition
  176.      * @param cqComplementarySlackness The Complementary Slackness Necessary Condition
  177.      * @param cqFONC The First Order Necessary Condition
  178.      * @param cqSOSC The Second Order Sufficiency Condition
  179.      *
  180.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  181.      */

  182.     public NecessarySufficientConditions (
  183.         final double[] adblVariate,
  184.         final org.drip.optimization.constrained.FritzJohnMultipliers fjm,
  185.         final boolean bCheckForMinima,
  186.         final org.drip.optimization.necessary.ConditionQualifierPrimalFeasibility cqPrimalFeasibility,
  187.         final org.drip.optimization.necessary.ConditionQualifierDualFeasibility cqDualFeasibility,
  188.         final org.drip.optimization.necessary.ConditionQualifierComplementarySlackness
  189.             cqComplementarySlackness,
  190.         final org.drip.optimization.necessary.ConditionQualifierFONC cqFONC,
  191.         final org.drip.optimization.necessary.ConditionQualifierSOSC cqSOSC)
  192.         throws java.lang.Exception
  193.     {
  194.         if (null == (_adblVariate = adblVariate) || 0 == _adblVariate.length || null == (_fjm = fjm) || null
  195.             == (_cqPrimalFeasibility = cqPrimalFeasibility) || null == (_cqDualFeasibility =
  196.                 cqDualFeasibility) || null == (_cqComplementarySlackness = cqComplementarySlackness) || null
  197.                     == (_cqFONC = cqFONC) || null == (_cqSOSC = cqSOSC))
  198.             throw new java.lang.Exception ("NecessarySufficientConditions Constructor => Invalid Inputs");

  199.         _bCheckForMinima = bCheckForMinima;
  200.     }

  201.     /**
  202.      * Retrieve the Candidate Variate Array
  203.      *
  204.      * @return The Candidate Variate Array
  205.      */

  206.     public double[] variate()
  207.     {
  208.         return _adblVariate;
  209.     }

  210.     /**
  211.      * Retrieve the Fritz John Mutipliers
  212.      *
  213.      * @return The Fritz John Mutipliers
  214.      */

  215.     public org.drip.optimization.constrained.FritzJohnMultipliers fritzJohnMultipliers()
  216.     {
  217.         return _fjm;
  218.     }

  219.     /**
  220.      * Retrieve if the Check corresponds to Local Minima
  221.      *
  222.      * @return TRUE - The Check corresponds to Local Minima
  223.      */

  224.     public boolean checkFroMinima()
  225.     {
  226.         return _bCheckForMinima;
  227.     }

  228.     /**
  229.      * Retrieve the Primal Feasibility Necessary Condition
  230.      *
  231.      * @return The Primal Feasibility Necessary Condition
  232.      */

  233.     public org.drip.optimization.necessary.ConditionQualifierPrimalFeasibility primalFeasibility()
  234.     {
  235.         return _cqPrimalFeasibility;
  236.     }

  237.     /**
  238.      * Retrieve the Dual Feasibility Necessary Condition
  239.      *
  240.      * @return The Dual Feasibility Necessary Condition
  241.      */

  242.     public org.drip.optimization.necessary.ConditionQualifierDualFeasibility dualFeasibility()
  243.     {
  244.         return _cqDualFeasibility;
  245.     }

  246.     /**
  247.      * Retrieve the Complementary Slackness Necessary Condition
  248.      *
  249.      * @return The Complementary Slackness Necessary Condition
  250.      */

  251.     public org.drip.optimization.necessary.ConditionQualifierComplementarySlackness
  252.         complementarySlackness()
  253.     {
  254.         return _cqComplementarySlackness;
  255.     }

  256.     /**
  257.      * Retrieve the First Order Necessary Condition
  258.      *
  259.      * @return The First Order Necessary Condition
  260.      */

  261.     public org.drip.optimization.necessary.ConditionQualifierFONC fonc()
  262.     {
  263.         return _cqFONC;
  264.     }

  265.     /**
  266.      * Retrieve the Second Order Sufficiency Condition
  267.      *
  268.      * @return The Second Order Sufficiency Condition
  269.      */

  270.     public org.drip.optimization.necessary.ConditionQualifierSOSC sosc()
  271.     {
  272.         return _cqSOSC;
  273.     }

  274.     /**
  275.      * Indicate the Necessary/Sufficient Validity across all the Condition Qualifiers
  276.      *
  277.      * @return TRUE - The Necessary/Sufficient Criteria is satisfied across all the Condition Qualifiers
  278.      */

  279.     public boolean valid()
  280.     {
  281.         return _cqPrimalFeasibility.valid() && _cqDualFeasibility.valid() &&
  282.             _cqComplementarySlackness.valid() && _cqFONC.valid() && _cqSOSC.valid();
  283.     }

  284.     /**
  285.      * Retrieve the Array of Condition Orders
  286.      *
  287.      * @return The Array of Condition Orders
  288.      */

  289.     public java.lang.String[] conditionOrder()
  290.     {
  291.         return new java.lang.String[] {"ZERO ORDER: " + _cqPrimalFeasibility.display() + " >> " +
  292.             _cqDualFeasibility.display() + " >> " + _cqComplementarySlackness.display(), "FIRST ORDER: " +
  293.                 _cqFONC.display(), "SECOND ORDER: " + _cqSOSC.display()};
  294.     }
  295. }