LatentStateResponseModel.java

  1. package org.drip.spline.segment;

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

  80. /**
  81.  * <i>LatentStateResponseModel</i> implements the single segment basis calibration and inference
  82.  * functionality. It exports the following functionality:
  83.  *
  84.  * <br><br>
  85.  *  <ul>
  86.  *      <li>
  87.  *          Build the LatentStateResponseModel instance from the Basis Function/Shape Controller Set
  88.  *      </li>
  89.  *      <li>
  90.  *          Build the LatentStateResponseModel instance from the Basis Evaluator Set
  91.  *      </li>
  92.  *      <li>
  93.  *          Retrieve the Number of Parameters, Basis Evaluator, Array of the Response Basis Coefficients, and
  94.  *              Segment Design Inelastic Control
  95.  *      </li>
  96.  *      <li>
  97.  *          Calibrate the Segment State from the Calibration Parameter Set
  98.  *      </li>
  99.  *      <li>
  100.  *          Sensitivity Calibrator: Calibrate the Segment Manifest Jacobian from the Calibration Parameter
  101.  *              Set
  102.  *      </li>
  103.  *      <li>
  104.  *          Calibrate the coefficients from the prior Predictor/Response Segment, the Constraint, and fitness
  105.  *              Weights
  106.  *      </li>
  107.  *      <li>
  108.  *          Calibrate the coefficients from the prior Segment and the Response Value at the Right Predictor
  109.  *              Ordinate
  110.  *      </li>
  111.  *      <li>
  112.  *          Calibrate the Coefficients from the Edge Response Values and the Left Edge Response Slope
  113.  *      </li>
  114.  *      <li>
  115.  *          Calibrate the coefficients from the Left Edge Response Value Constraint, the Left Edge Response
  116.  *              Value Slope, and the Right Edge Response Value Constraint
  117.  *      </li>
  118.  *      <li>
  119.  *          Retrieve the Segment Curvature, Length, and the Best Fit DPE
  120.  *      </li>
  121.  *      <li>
  122.  *          Calculate the Response Value and its Derivative at the given Predictor Ordinate
  123.  *      </li>
  124.  *      <li>
  125.  *          Calculate the Ordered Derivative of the Coefficient to the Manifest
  126.  *      </li>
  127.  *      <li>
  128.  *          Calculate the Jacobian of the Segment's Response Basis Function Coefficients to the Edge Inputs
  129.  *      </li>
  130.  *      <li>
  131.  *          Calculate the Jacobian of the Response to the Edge Inputs at the given Predictor Ordinate
  132.  *      </li>
  133.  *      <li>
  134.  *          Calculate the Jacobian of the Response to the Basis Coefficients at the given Predictor Ordinate
  135.  *      </li>
  136.  *      <li>
  137.  *          Calibrate the segment and calculate the Jacobian of the Segment's Response Basis Function
  138.  *              Coefficients to the Edge Parameters
  139.  *      </li>
  140.  *      <li>
  141.  *          Calibrate the Coefficients from the Edge Response Values and the Left Edge Response Value Slope
  142.  *              and calculate the Jacobian of the Segment's Response Basis Function Coefficients to the Edge
  143.  *              Parameters
  144.  *      </li>
  145.  *      <li>
  146.  *          Calibrate the coefficients from the prior Segment and the Response Value at the Right Predictor
  147.  *              Ordinate and calculate the Jacobian of the Segment's Response Basis Function Coefficients to
  148.  *              the Edge Parameters
  149.  *      </li>
  150.  *      <li>
  151.  *          Indicate whether the given segment is monotone. If monotone, may optionally indicate the nature
  152.  *              of the extrema contained inside (maxima/minima/infection)
  153.  *      </li>
  154.  *      <li>
  155.  *          Clip the part of the Segment to the Right of the specified Predictor Ordinate. Retain all other
  156.  *              constraints the same
  157.  *      </li>
  158.  *      <li>
  159.  *          Clip the part of the Segment to the Left of the specified Predictor Ordinate. Retain all other
  160.  *              constraints the same
  161.  *      </li>
  162.  *      <li>
  163.  *          Display the string representation for diagnostic purposes
  164.  *      </li>
  165.  *  </ul>
  166.  *
  167.  * <br><br>
  168.  *  <ul>
  169.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  170.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/SplineBuilderLibrary.md">Spline Builder Library</a></li>
  171.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/README.md">Basis Splines and Linear Compounders across a Broad Family of Spline Basis Functions</a></li>
  172.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/segment/README.md">Flexure Penalizing Best Fit Segment</a></li>
  173.  *  </ul>
  174.  * <br><br>
  175.  *
  176.  * @author Lakshmi Krishnamurthy
  177.  */

  178. public class LatentStateResponseModel extends org.drip.spline.segment.LatentStateInelastic {

  179.     /**
  180.      * LEFT NODE VALUE PARAMETER INDEX
  181.      */

  182.     public static final int LEFT_NODE_VALUE_PARAMETER_INDEX = 0;

  183.     /**
  184.      * RIGHT NODE VALUE PARAMETER INDEX
  185.      */

  186.     public static final int RIGHT_NODE_VALUE_PARAMETER_INDEX = 1;

  187.     private double[] _adblResponseBasisCoeff = null;
  188.     private org.drip.spline.segment.BasisEvaluator _be = null;
  189.     private double[][] _aadblDResponseBasisCoeffDConstraint = null;
  190.     private org.drip.spline.params.SegmentInelasticDesignControl _sidc = null;
  191.     private org.drip.numerical.differentiation.WengertJacobian _wjDBasisCoeffDEdgeValue = null;

  192.     private
  193.         org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.spline.segment.LatentStateManifestSensitivity>
  194.             _mapLSMS = new
  195.                 org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.spline.segment.LatentStateManifestSensitivity>();

  196.     /**
  197.      * Build the LatentStateResponseModel instance from the Basis Function/Shape Controller Set
  198.      *
  199.      * @param dblLeftPredictorOrdinate Left Predictor Ordinate
  200.      * @param dblRightPredictorOrdinate Right Predictor Ordinate
  201.      * @param fs Response Basis Function Set
  202.      * @param rssc Shape Controller
  203.      * @param sidc Segment Inelastic Design Parameters
  204.      *
  205.      * @return Instance of LatentStateResponseModel
  206.      */

  207.     public static final org.drip.spline.segment.LatentStateResponseModel Create (
  208.         final double dblLeftPredictorOrdinate,
  209.         final double dblRightPredictorOrdinate,
  210.         final org.drip.spline.basis.FunctionSet fs,
  211.         final org.drip.spline.params.ResponseScalingShapeControl rssc,
  212.         final org.drip.spline.params.SegmentInelasticDesignControl sidc)
  213.     {
  214.         try {
  215.             org.drip.spline.segment.SegmentBasisEvaluator sbe = new
  216.                 org.drip.spline.segment.SegmentBasisEvaluator (fs, rssc);

  217.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblLeftPredictorOrdinate) ||
  218.                 !org.drip.numerical.common.NumberUtil.IsValid (dblRightPredictorOrdinate) ||
  219.                 dblLeftPredictorOrdinate == dblRightPredictorOrdinate)
  220.             {
  221.                 return null;
  222.             }

  223.             org.drip.spline.segment.LatentStateResponseModel lsrm = new
  224.                 org.drip.spline.segment.LatentStateResponseModel (dblLeftPredictorOrdinate,
  225.                     dblRightPredictorOrdinate, sbe, sidc);

  226.             return sbe.setContainingInelastics (lsrm) ? lsrm : null;
  227.         } catch (java.lang.Exception e) {
  228.             e.printStackTrace();
  229.         }

  230.         return null;
  231.     }

  232.     /**
  233.      * Build the LatentStateResponseModel instance from the Basis Evaluator Set
  234.      *
  235.      * @param dblLeftPredictorOrdinate Left Predictor Ordinate
  236.      * @param dblRightPredictorOrdinate Right Predictor Ordinate
  237.      * @param be Basis Evaluator
  238.      * @param sidc Segment Inelastic Design Parameters
  239.      *
  240.      * @return Instance of LatentStateResponseModel
  241.      */

  242.     public static final org.drip.spline.segment.LatentStateResponseModel Create (
  243.         final double dblLeftPredictorOrdinate,
  244.         final double dblRightPredictorOrdinate,
  245.         final org.drip.spline.segment.BasisEvaluator be,
  246.         final org.drip.spline.params.SegmentInelasticDesignControl sidc)
  247.     {
  248.         try {
  249.             org.drip.spline.segment.LatentStateResponseModel lsrm = new
  250.                 org.drip.spline.segment.LatentStateResponseModel (dblLeftPredictorOrdinate,
  251.                     dblRightPredictorOrdinate, be, sidc);

  252.             return be.setContainingInelastics (lsrm) ? lsrm : null;
  253.         } catch (java.lang.Exception e) {
  254.             e.printStackTrace();
  255.         }

  256.         return null;
  257.     }

  258.     private LatentStateResponseModel (
  259.         final double dblLeftPredictorOrdinate,
  260.         final double dblRightPredictorOrdinate,
  261.         final org.drip.spline.segment.BasisEvaluator be,
  262.         final org.drip.spline.params.SegmentInelasticDesignControl sidc)
  263.         throws java.lang.Exception
  264.     {
  265.         super (dblLeftPredictorOrdinate, dblRightPredictorOrdinate);

  266.         if (null == (_be = be) || null == (_sidc = sidc))
  267.             throw new java.lang.Exception ("LatentStateResponseModel ctr: Invalid Basis Functions!");

  268.         int iNumBasis = _be.numBasis();

  269.         _adblResponseBasisCoeff = new double[iNumBasis];

  270.         if (0 >= iNumBasis || _sidc.Ck() > iNumBasis - 2)
  271.             throw new java.lang.Exception ("LatentStateResponseModel ctr: Invalid inputs!");
  272.     }

  273.     private double[] DResponseDBasisCoeff (
  274.         final double dblPredictorOrdinate,
  275.         final int iOrder)
  276.     {
  277.         if (0 == iOrder) return null;

  278.         int iNumBasis = _be.numBasis();

  279.         double[] adblDResponseDBasisCoeff = new double[iNumBasis];

  280.         for (int i = 0; i < iNumBasis; ++i) {
  281.             try {
  282.                 adblDResponseDBasisCoeff[i] = 1 == iOrder ? _be.shapedBasisFunctionResponse
  283.                     (dblPredictorOrdinate, i) : 0.;
  284.             } catch (java.lang.Exception e) {
  285.                 e.printStackTrace();

  286.                 return null;
  287.             }
  288.         }

  289.         return adblDResponseDBasisCoeff;
  290.     }

  291.     private double[] transmissionCk (
  292.         final double dblPredictorOrdinate,
  293.         final org.drip.spline.segment.LatentStateResponseModel csPreceeding,
  294.         final int iCk)
  295.     {
  296.         double[] adblDeriv = new double[iCk];

  297.         for (int i = 0; i < iCk; ++i) {
  298.             try {
  299.                 adblDeriv[i] = csPreceeding.calcResponseValueDerivative (dblPredictorOrdinate, i + 1);
  300.             } catch (java.lang.Exception e) {
  301.                 e.printStackTrace();

  302.                 return null;
  303.             }
  304.         }

  305.         return adblDeriv;
  306.     }

  307.     private org.drip.spline.segment.LatentStateManifestSensitivity manifestSensitivity (
  308.         final java.lang.String strManifestMeasure)
  309.     {
  310.         return null == strManifestMeasure || strManifestMeasure.isEmpty() || !_mapLSMS.containsKey
  311.             (strManifestMeasure) ? null : _mapLSMS.get (strManifestMeasure);
  312.     }

  313.     private double[] CkDBasisCoeffDPreceedingManifestMeasure (
  314.         final java.lang.String strManifestMeasure)
  315.     {
  316.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  317.             (strManifestMeasure);

  318.         if (null == lsms) return null;

  319.         int iCk = lsms.getPMSC().Ck();

  320.         if (0 == iCk) return null;

  321.         double[] adblDBasisCoeffDPreceedingManifestTail = new double[iCk];

  322.         for (int i = 0; i < iCk; ++i)
  323.             adblDBasisCoeffDPreceedingManifestTail[i] = 0.;

  324.         return adblDBasisCoeffDPreceedingManifestTail;
  325.     }

  326.     /**
  327.      * Set the Preceeding Manifest Sensitivity Control Parameters for the specified Manifest Measure
  328.      *
  329.      * @param strManifestMeasure The Manifest Measure
  330.      * @param pmsc The Preceeding Manifest Sensitivity Control Instance
  331.      *
  332.      * @return TRUE - Named Preceeding Manifest Sensitivity Control Instance Successfully Set
  333.      */

  334.     public boolean setPreceedingManifestSensitivityControl (
  335.         final java.lang.String strManifestMeasure,
  336.         final org.drip.spline.params.PreceedingManifestSensitivityControl pmsc)
  337.     {
  338.         if (null == strManifestMeasure || strManifestMeasure.isEmpty()) return false;

  339.         try {
  340.             _mapLSMS.put (strManifestMeasure, new org.drip.spline.segment.LatentStateManifestSensitivity
  341.                 (pmsc));

  342.             return true;
  343.         } catch (java.lang.Exception e) {
  344.             e.printStackTrace();
  345.         }

  346.         return false;
  347.     }

  348.     /**
  349.      * Retrieve the Number of Parameters
  350.      *
  351.      * @return The Number of Parameters
  352.      */

  353.     public int numParameters()
  354.     {
  355.         return _sidc.Ck() + 2;
  356.     }

  357.     /**
  358.      * Retrieve the Basis Evaluator
  359.      *
  360.      * @return The Basis Evaluator
  361.      */

  362.     public org.drip.spline.segment.BasisEvaluator basisEvaluator()
  363.     {
  364.         return _be;
  365.     }

  366.     /**
  367.      * Retrieve the Array of Response Basis Coefficients
  368.      *
  369.      * @return The Array of Response Basis Coefficients
  370.      */

  371.     public double[] responseBasisCoefficient()
  372.     {
  373.         return _adblResponseBasisCoeff;
  374.     }

  375.     /**
  376.      * Retrieve the Segment Inelastic Design Control
  377.      *
  378.      * @return The Segment Inelastic Design Control
  379.      */

  380.     public org.drip.spline.params.SegmentInelasticDesignControl designControl()
  381.     {
  382.         return _sidc;
  383.     }

  384.     /**
  385.      * Main Calibrator: Calibrate the Segment State from the Calibration Parameter Set
  386.      *
  387.      * @param ssciState The Segment State Calibration Inputs Set
  388.      *
  389.      * @return TRUE - Calibration Successful
  390.      */

  391.     public boolean calibrateState (
  392.         final org.drip.spline.params.SegmentStateCalibrationInputs ssciState)
  393.     {
  394.         if (null == ssciState) return false;

  395.         double[] adblPredictorOrdinate = ssciState.predictorOrdinates();

  396.         double[] adblResponseValue = ssciState.responseValues();

  397.         double[] adblLeftEdgeDeriv = ssciState.leftEdgeDeriv();

  398.         double[] adblRightEdgeDeriv = ssciState.rightEdgeDeriv();

  399.         org.drip.spline.params.SegmentBestFitResponse sbfr = ssciState.bestFitResponse();

  400.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFC = ssciState.flexureConstraint();

  401.         int iNumConstraint = 0;
  402.         int iNumResponseBasisCoeff = _adblResponseBasisCoeff.length;
  403.         int iNumLeftDeriv = null == adblLeftEdgeDeriv ? 0 : adblLeftEdgeDeriv.length;
  404.         int iNumRightDeriv = null == adblRightEdgeDeriv ? 0 : adblRightEdgeDeriv.length;
  405.         double[] adblPredictorResponseConstraintValue = new double[iNumResponseBasisCoeff];
  406.         int iNumPredictorOrdinate = null == adblPredictorOrdinate ? 0 : adblPredictorOrdinate.length;
  407.         double[][] aadblResponseBasisCoeffConstraint = new
  408.             double[iNumResponseBasisCoeff][iNumResponseBasisCoeff];

  409.         if (null != aSBFC) {
  410.             int iNumPotentialConstraint = aSBFC.length;

  411.             for (int i = 0; i < iNumPotentialConstraint; ++i) {
  412.                 if (null != aSBFC[i]) ++iNumConstraint;
  413.             }
  414.         }

  415.         if (iNumResponseBasisCoeff < iNumPredictorOrdinate + iNumLeftDeriv + iNumRightDeriv + iNumConstraint)
  416.             return false;

  417.         try {
  418.             org.drip.spline.segment.BestFitFlexurePenalizer bffp = new
  419.                 org.drip.spline.segment.BestFitFlexurePenalizer (this, _sidc.curvaturePenaltyControl(),
  420.                     _sidc.lengthPenaltyControl(), sbfr, _be);

  421.             for (int j = 0; j < iNumResponseBasisCoeff; ++j) {
  422.                 if (j < iNumPredictorOrdinate)
  423.                     adblPredictorResponseConstraintValue[j] = adblResponseValue[j];
  424.                 else if (j < iNumPredictorOrdinate + iNumConstraint)
  425.                     adblPredictorResponseConstraintValue[j] = aSBFC[j -
  426.                         iNumPredictorOrdinate].contraintValue();
  427.                 else if (j < iNumPredictorOrdinate + iNumConstraint + iNumLeftDeriv)
  428.                     adblPredictorResponseConstraintValue[j] = adblLeftEdgeDeriv[j - iNumPredictorOrdinate -
  429.                         iNumConstraint];
  430.                 else if (j < iNumPredictorOrdinate + iNumConstraint + iNumLeftDeriv + iNumRightDeriv)
  431.                     adblPredictorResponseConstraintValue[j] = adblRightEdgeDeriv[j - iNumPredictorOrdinate -
  432.                         iNumConstraint - iNumLeftDeriv];
  433.                 else
  434.                     adblPredictorResponseConstraintValue[j] = bffp.basisPairPenaltyConstraint (j);
  435.             }

  436.             for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  437.                 for (int l = 0; l < iNumResponseBasisCoeff; ++l) {
  438.                     double[] adblCalibBasisConstraintWeight = null;

  439.                     if (0 != iNumConstraint && (l >= iNumPredictorOrdinate && l < iNumPredictorOrdinate +
  440.                         iNumConstraint))
  441.                         adblCalibBasisConstraintWeight = aSBFC[l -
  442.                             iNumPredictorOrdinate].responseBasisCoeffWeights();

  443.                     if (l < iNumPredictorOrdinate)
  444.                         aadblResponseBasisCoeffConstraint[l][i] = _be.shapedBasisFunctionResponse
  445.                             (adblPredictorOrdinate[l], i);
  446.                     else if (l < iNumPredictorOrdinate + iNumConstraint)
  447.                         aadblResponseBasisCoeffConstraint[l][i] = adblCalibBasisConstraintWeight[i];
  448.                     else if (l < iNumPredictorOrdinate + iNumConstraint + iNumLeftDeriv)
  449.                         aadblResponseBasisCoeffConstraint[l][i] = _be.shapedBasisFunctionDerivative (left(),
  450.                             l - iNumPredictorOrdinate - iNumConstraint + 1, i);
  451.                     else if (l < iNumPredictorOrdinate + iNumConstraint + iNumLeftDeriv + iNumRightDeriv)
  452.                         aadblResponseBasisCoeffConstraint[l][i] = _be.shapedBasisFunctionDerivative
  453.                             (right(), l - iNumPredictorOrdinate - iNumConstraint - iNumLeftDeriv + 1, i);
  454.                     else
  455.                         aadblResponseBasisCoeffConstraint[l][i] = bffp.basisPairConstraintCoefficient (i, l);
  456.                 }
  457.             }
  458.         } catch (java.lang.Exception e) {
  459.             e.printStackTrace();

  460.             return false;
  461.         }

  462.         org.drip.numerical.linearalgebra.LinearizationOutput lo =
  463.             org.drip.numerical.linearalgebra.LinearSystemSolver.SolveUsingMatrixInversion
  464.                 (aadblResponseBasisCoeffConstraint, adblPredictorResponseConstraintValue);

  465.         if (null == lo) return false;

  466.         double[] adblCalibResponseBasisCoeff = lo.getTransformedRHS();

  467.         if (null == adblCalibResponseBasisCoeff || adblCalibResponseBasisCoeff.length !=
  468.             iNumResponseBasisCoeff || null == (_aadblDResponseBasisCoeffDConstraint =
  469.                 lo.getTransformedMatrix()) || _aadblDResponseBasisCoeffDConstraint.length !=
  470.                     iNumResponseBasisCoeff || _aadblDResponseBasisCoeffDConstraint[0].length !=
  471.                         iNumResponseBasisCoeff)
  472.             return false;

  473.         for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  474.             if (!org.drip.numerical.common.NumberUtil.IsValid (_adblResponseBasisCoeff[i] =
  475.                 adblCalibResponseBasisCoeff[i]))
  476.                 return false;
  477.         }

  478.         return true;
  479.     }

  480.     /**
  481.      * Sensitivity Calibrator: Calibrate the Segment Manifest Measure Jacobian from the Calibration Inputs
  482.      *
  483.      * @param ssciManifestSensitivity The Segment Manifest Calibration Sensitivity Inputs
  484.      * @param aSBFCState Array of Segment State Basis Flexure Constraints
  485.      *
  486.      * @return The Manifest Sensitivity Coefficients
  487.      */

  488.     public double[] calibrateManifestJacobian (
  489.         final org.drip.spline.params.SegmentStateCalibrationInputs ssciManifestSensitivity,
  490.         final org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState)
  491.     {
  492.         if (null == ssciManifestSensitivity) return null;

  493.         double[] adblPredictorOrdinate = ssciManifestSensitivity.predictorOrdinates();

  494.         double[] adblResponseValueManifestSensitivity = ssciManifestSensitivity.responseValues();

  495.         double[] adblLeftEdgeDerivManifestSensitivity = ssciManifestSensitivity.leftEdgeDeriv();

  496.         double[] adblRightEdgeDerivManifestSensitivity = ssciManifestSensitivity.rightEdgeDeriv();

  497.         org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity =
  498.             ssciManifestSensitivity.bestFitResponse();

  499.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCManifestSensitivity =
  500.             ssciManifestSensitivity.flexureConstraint();

  501.         int iNumConstraint = 0;
  502.         int iNumResponseBasisCoeff = _adblResponseBasisCoeff.length;
  503.         int iNumPredictorOrdinate = null == adblPredictorOrdinate ? 0 : adblPredictorOrdinate.length;
  504.         double[] adblPredictorResponseManifestSensitivityConstraint = new double[iNumResponseBasisCoeff];
  505.         int iNumLeftDerivManifestSensitivity = null == adblLeftEdgeDerivManifestSensitivity ? 0 :
  506.             adblLeftEdgeDerivManifestSensitivity.length;
  507.         int iNumRightDerivManifestSensitivity = null == adblRightEdgeDerivManifestSensitivity ? 0 :
  508.             adblRightEdgeDerivManifestSensitivity.length;
  509.         double[][] aadblResponseCoeffConstraintManifestSensitivity = new
  510.             double[iNumResponseBasisCoeff][iNumResponseBasisCoeff];

  511.         if (null != aSBFCState) {
  512.             int iNumPotentialConstraint = aSBFCState.length;

  513.             for (int i = 0; i < iNumPotentialConstraint; ++i) {
  514.                 if (null != aSBFCState[i]) ++iNumConstraint;
  515.             }
  516.         }

  517.         if (iNumResponseBasisCoeff < iNumPredictorOrdinate + iNumLeftDerivManifestSensitivity +
  518.             iNumRightDerivManifestSensitivity + iNumConstraint)
  519.             return null;

  520.         try {
  521.             org.drip.spline.segment.BestFitFlexurePenalizer bffpManifestSensitivity = new
  522.                 org.drip.spline.segment.BestFitFlexurePenalizer (this, null == _sidc ? null :
  523.                     _sidc.curvaturePenaltyControl(), null == _sidc ? null : _sidc.lengthPenaltyControl(),
  524.                         sbfrManifestSensitivity, _be);

  525.             for (int j = 0; j < iNumResponseBasisCoeff; ++j) {
  526.                 if (j < iNumPredictorOrdinate)
  527.                     adblPredictorResponseManifestSensitivityConstraint[j] =
  528.                         adblResponseValueManifestSensitivity[j];
  529.                 else if (j < iNumPredictorOrdinate + iNumConstraint) {
  530.                     adblPredictorResponseManifestSensitivityConstraint[j] = 0.;
  531.                     org.drip.spline.params.SegmentBasisFlexureConstraint sbfcManifestSensitivity =
  532.                         aSBFCManifestSensitivity[j - iNumPredictorOrdinate];

  533.                     if (null != sbfcManifestSensitivity) {
  534.                         adblPredictorResponseManifestSensitivityConstraint[j] =
  535.                             sbfcManifestSensitivity.contraintValue();

  536.                         double[] adblCalibConstraintWeightManifestSensitivity =
  537.                             sbfcManifestSensitivity.responseBasisCoeffWeights();

  538.                         for (int i = 0; i < iNumResponseBasisCoeff; ++i)
  539.                             adblPredictorResponseManifestSensitivityConstraint[j] -=
  540.                                 _adblResponseBasisCoeff[i] * adblCalibConstraintWeightManifestSensitivity[i];
  541.                     }
  542.                 } else if (j < iNumPredictorOrdinate + iNumConstraint + iNumLeftDerivManifestSensitivity)
  543.                     adblPredictorResponseManifestSensitivityConstraint[j] =
  544.                         adblLeftEdgeDerivManifestSensitivity[j - iNumPredictorOrdinate - iNumConstraint];
  545.                 else if (j < iNumPredictorOrdinate + iNumConstraint + iNumLeftDerivManifestSensitivity +
  546.                     iNumRightDerivManifestSensitivity)
  547.                     adblPredictorResponseManifestSensitivityConstraint[j] =
  548.                         adblRightEdgeDerivManifestSensitivity[j - iNumPredictorOrdinate - iNumConstraint -
  549.                             iNumLeftDerivManifestSensitivity];
  550.                 else
  551.                     adblPredictorResponseManifestSensitivityConstraint[j] =
  552.                         bffpManifestSensitivity.basisPairPenaltyConstraint (j);
  553.             }

  554.             for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  555.                 for (int l = 0; l < iNumResponseBasisCoeff; ++l) {
  556.                     double[] adblCalibBasisConstraintWeight = null;

  557.                     if (0 != iNumConstraint && (l >= iNumPredictorOrdinate && l < iNumPredictorOrdinate +
  558.                         iNumConstraint))
  559.                         adblCalibBasisConstraintWeight = aSBFCState[l -
  560.                             iNumPredictorOrdinate].responseBasisCoeffWeights();

  561.                     if (l < iNumPredictorOrdinate)
  562.                         aadblResponseCoeffConstraintManifestSensitivity[l][i] =
  563.                             _be.shapedBasisFunctionResponse (adblPredictorOrdinate[l], i);
  564.                     else if (l < iNumPredictorOrdinate + iNumConstraint)
  565.                         aadblResponseCoeffConstraintManifestSensitivity[l][i] =
  566.                             adblCalibBasisConstraintWeight[i];
  567.                     else if (l < iNumPredictorOrdinate + iNumConstraint + iNumLeftDerivManifestSensitivity)
  568.                         aadblResponseCoeffConstraintManifestSensitivity[l][i] =
  569.                             _be.shapedBasisFunctionDerivative (left(), l - iNumPredictorOrdinate -
  570.                                 iNumConstraint + 1, i);
  571.                     else if (l < iNumPredictorOrdinate + iNumConstraint + iNumLeftDerivManifestSensitivity +
  572.                         iNumRightDerivManifestSensitivity)
  573.                         aadblResponseCoeffConstraintManifestSensitivity[l][i] =
  574.                             _be.shapedBasisFunctionDerivative (right(), l - iNumPredictorOrdinate -
  575.                                 iNumConstraint - iNumLeftDerivManifestSensitivity + 1, i);
  576.                     else
  577.                         aadblResponseCoeffConstraintManifestSensitivity[l][i] =
  578.                             bffpManifestSensitivity.basisPairConstraintCoefficient (i, l);
  579.                 }
  580.             }
  581.         } catch (java.lang.Exception e) {
  582.             e.printStackTrace();

  583.             return null;
  584.         }

  585.         org.drip.numerical.linearalgebra.LinearizationOutput lo =
  586.             org.drip.numerical.linearalgebra.LinearSystemSolver.SolveUsingMatrixInversion
  587.                 (aadblResponseCoeffConstraintManifestSensitivity,
  588.                     adblPredictorResponseManifestSensitivityConstraint);

  589.         return null == lo ? null : lo.getTransformedRHS();
  590.     }

  591.     /**
  592.      * Sensitivity Calibrator: Calibrate the Segment Local Manifest Jacobian from the Calibration Parameter
  593.      *  Set
  594.      *
  595.      * @param strManifestMeasure Latent State Manifest Measure
  596.      * @param ssciManifestSensitivity The Segment Manifest Calibration Parameter Sensitivity
  597.      * @param aSBFCState Array of Segment State Basis Flexure Constraints
  598.      *
  599.      * @return TRUE - Local Manifest Sensitivity Calibration Successful
  600.      */

  601.     public boolean calibrateLocalManifestJacobian (
  602.         final java.lang.String strManifestMeasure,
  603.         final org.drip.spline.params.SegmentStateCalibrationInputs ssciManifestSensitivity,
  604.         final org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState)
  605.     {
  606.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  607.             (strManifestMeasure);

  608.         if (null == lsms) return false;

  609.         double[] adblDBasisCoeffDLocalManifest = calibrateManifestJacobian (ssciManifestSensitivity,
  610.             aSBFCState);

  611.         return null == adblDBasisCoeffDLocalManifest || adblDBasisCoeffDLocalManifest.length !=
  612.             _adblResponseBasisCoeff.length ? false : lsms.setDBasisCoeffDLocalManifest
  613.                 (adblDBasisCoeffDLocalManifest);
  614.     }

  615.     /**
  616.      * Sensitivity Calibrator: Calibrate the Segment Preceeding Manifest Jacobian from the Calibration
  617.      *  Parameter Set
  618.      *
  619.      * @param strManifestMeasure Latent State Manifest
  620.      * @param ssciPreceedingManifestSensitivity The Segment Preceeding Manifest Calibration Parameter
  621.      *  Sensitivity
  622.      *
  623.      * @return TRUE - Preceeding Manifest Sensitivity Calibration Successful
  624.      */

  625.     public boolean calibratePreceedingManifestJacobian (
  626.         final java.lang.String strManifestMeasure,
  627.         final org.drip.spline.params.SegmentStateCalibrationInputs ssciPreceedingManifestSensitivity)
  628.     {
  629.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  630.             (strManifestMeasure);

  631.         if (null == lsms) return false;

  632.         double[] adblDBasisCoeffDPreceedingManifest = calibrateManifestJacobian
  633.             (ssciPreceedingManifestSensitivity, null);

  634.         return null == adblDBasisCoeffDPreceedingManifest || adblDBasisCoeffDPreceedingManifest.length !=
  635.             _adblResponseBasisCoeff.length ? false : lsms.setDBasisCoeffDPreceedingManifest
  636.                 (adblDBasisCoeffDPreceedingManifest);
  637.     }

  638.     /**
  639.      * Calibrate the coefficients from the prior Predictor/Response Segment, the Constraint, and fitness
  640.      *  Weights
  641.      *
  642.      * @param csPreceeding Preceeding Predictor/Response Segment
  643.      * @param srvcState The Segment State Response Value Constraint
  644.      * @param sbfrState Segment's Best Fit Weighted State Response Values
  645.      *
  646.      * @return TRUE - If the calibration succeeds
  647.      */

  648.     public boolean calibrate (
  649.         final org.drip.spline.segment.LatentStateResponseModel csPreceeding,
  650.         final org.drip.spline.params.SegmentResponseValueConstraint srvcState,
  651.         final org.drip.spline.params.SegmentBestFitResponse sbfrState)
  652.     {
  653.         int iCk = _sidc.Ck();

  654.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState = null == srvcState ? null : new
  655.             org.drip.spline.params.SegmentBasisFlexureConstraint[] {srvcState.responseIndexedBasisConstraint
  656.                 (_be, this)};

  657.         double[] adblManifestJacobianDerivAtLeftOrdinate = null;

  658.         if (0 != iCk) {
  659.             adblManifestJacobianDerivAtLeftOrdinate = new double[iCk];

  660.             for (int i = 0; i < iCk; ++i)
  661.                 adblManifestJacobianDerivAtLeftOrdinate[i] = 0.;
  662.         }

  663.         if (null == csPreceeding) {
  664.             try {
  665.                 double[] adblStateDerivAtLeftOrdinate = null;

  666.                 if (0 != iCk) {
  667.                     adblStateDerivAtLeftOrdinate = new double[iCk];

  668.                     for (int i = 0; i < iCk; ++i)
  669.                         adblStateDerivAtLeftOrdinate[i] = _be.responseValueDerivative
  670.                             (_adblResponseBasisCoeff, left(), i);
  671.                 }

  672.                 return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs (new double[]
  673.                     {left()}, new double[] {_be.responseValue (_adblResponseBasisCoeff, left())},
  674.                         adblStateDerivAtLeftOrdinate, null, aSBFCState, sbfrState));
  675.             } catch (java.lang.Exception e) {
  676.                 e.printStackTrace();
  677.             }

  678.             return false;
  679.         }

  680.         try {
  681.             return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs (new double[]
  682.                 {left()}, new double[] {csPreceeding.responseValue (left())}, 0 == iCk ? null :
  683.                     transmissionCk (left(), csPreceeding, iCk), null, aSBFCState, sbfrState));
  684.         } catch (java.lang.Exception e) {
  685.             e.printStackTrace();
  686.         }

  687.         return false;
  688.     }

  689.     /**
  690.      * Calibrate the coefficients from the prior Segment and the Response Value at the Right Predictor
  691.      *  Ordinate
  692.      *
  693.      * @param csPreceeding Preceeding Predictor/Response Segment
  694.      * @param dblRightStateValue Response Value at the Right Predictor Ordinate
  695.      * @param sbfrState Segment's Best Fit Weighted Response Values
  696.      *
  697.      * @return TRUE - If the calibration succeeds
  698.      */

  699.     public boolean calibrate (
  700.         final LatentStateResponseModel csPreceeding,
  701.         final double dblRightStateValue,
  702.         final org.drip.spline.params.SegmentBestFitResponse sbfrState)
  703.     {
  704.         if (null == csPreceeding) return false;

  705.         int iCk = _sidc.Ck();

  706.         try {
  707.             return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs (new double[]
  708.                 {left(), right()}, new double[] {csPreceeding.responseValue (left()), dblRightStateValue}, 0
  709.                     != iCk ? csPreceeding.transmissionCk (left(), this, iCk) : null, null, null, sbfrState));
  710.         } catch (java.lang.Exception e) {
  711.             e.printStackTrace();
  712.         }

  713.         return false;
  714.     }

  715.     /**
  716.      * Calibrate the Coefficients from the Edge Response Values and the Left Edge Response Slope
  717.      *
  718.      * @param dblLeftValue Left Edge Response Value
  719.      * @param dblLeftSlope Left Edge Response Slope
  720.      * @param dblRightValue Right Edge Response Value
  721.      * @param sbfrState Segment's Best Fit Weighted Response Values
  722.      *
  723.      * @return TRUE - The Calibration Succeeded
  724.      */

  725.     public boolean calibrate (
  726.         final double dblLeftValue,
  727.         final double dblLeftSlope,
  728.         final double dblRightValue,
  729.         final org.drip.spline.params.SegmentBestFitResponse sbfrState)
  730.     {
  731.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblLeftValue) ||
  732.             !org.drip.numerical.common.NumberUtil.IsValid (dblLeftSlope) ||
  733.                 !org.drip.numerical.common.NumberUtil.IsValid (dblRightValue))
  734.             return false;

  735.         try {
  736.             return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs (new double[]
  737.                 {left(), right()}, new double[] {dblLeftValue, dblRightValue},
  738.                     org.drip.numerical.common.CollectionUtil.DerivArrayFromSlope (numParameters() - 2,
  739.                         dblLeftSlope), null, null, sbfrState));
  740.         } catch (java.lang.Exception e) {
  741.             e.printStackTrace();
  742.         }

  743.         return false;
  744.     }

  745.     /**
  746.      * Calibrate the coefficients from the Left Edge Response Value Constraint, the Left Edge Response Value
  747.      *  Slope, and the Right Edge Response Value Constraint
  748.      *
  749.      * @param wrvcStateLeft Left Edge Response Value Constraint
  750.      * @param dblLeftSlope Left Edge Response Value Slope
  751.      * @param wrvcStateRight Right Edge Response Value Constraint
  752.      * @param sbfrState Segment's Best Fit Weighted Response
  753.      *
  754.      * @return TRUE - If the calibration succeeds
  755.      */

  756.     public boolean calibrate (
  757.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateLeft,
  758.         final double dblLeftSlope,
  759.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateRight,
  760.         final org.drip.spline.params.SegmentBestFitResponse sbfrState)
  761.     {
  762.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState = null;

  763.         try {
  764.             if (null != wrvcStateLeft || null != wrvcStateRight)
  765.                 aSBFCState = new org.drip.spline.params.SegmentBasisFlexureConstraint[] {null ==
  766.                     wrvcStateLeft ? null : wrvcStateLeft.responseIndexedBasisConstraint (_be, this), null ==
  767.                         wrvcStateRight ? null : wrvcStateRight.responseIndexedBasisConstraint (_be, this)};

  768.             return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs (null, null,
  769.                 org.drip.numerical.common.CollectionUtil.DerivArrayFromSlope (numParameters() - 2, dblLeftSlope),
  770.                     null, aSBFCState, sbfrState));
  771.         } catch (java.lang.Exception e) {
  772.             e.printStackTrace();
  773.         }

  774.         return false;
  775.     }

  776.     /**
  777.      * Compute the Local and the Preceeding Manifest Measure Sensitivity Coefficients from the Preceeding
  778.      *  Segment, the Local Response Value, the Local Response Value Manifest Measure Sensitivity, and the
  779.      *  Local Best Fit Response Sensitivity
  780.      *
  781.      * @param csPreceeding Preceeding Predictor/Response Segment
  782.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  783.      * @param srvcState The Segment State Response Value Constraint
  784.      * @param srvcManifestSensitivity The Segment State Response Value Constraint Manifest Sensitivity
  785.      * @param sbfrManifestSensitivity Segment's Best Fit Weighted State Response Value Manifest Sensitivity
  786.      *
  787.      * @return TRUE - If the calibration succeeds
  788.      */

  789.     public boolean manifestMeasureSensitivity (
  790.         final org.drip.spline.segment.LatentStateResponseModel csPreceeding,
  791.         final java.lang.String strManifestMeasure,
  792.         final org.drip.spline.params.SegmentResponseValueConstraint srvcState,
  793.         final org.drip.spline.params.SegmentResponseValueConstraint srvcManifestSensitivity,
  794.         final org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity)
  795.     {
  796.         if (null == srvcState && null != srvcManifestSensitivity) return false;

  797.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState = null == srvcState ? null : new
  798.             org.drip.spline.params.SegmentBasisFlexureConstraint[] {srvcState.responseIndexedBasisConstraint
  799.                 (_be, this)};

  800.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCManifestSensitivity = null ==
  801.             srvcManifestSensitivity ? null : new org.drip.spline.params.SegmentBasisFlexureConstraint[]
  802.                 {srvcManifestSensitivity.responseIndexedBasisConstraint (_be, this)};

  803.         double[] adblManifestJacobianDerivAtLeftOrdinate = null;

  804.         int iCk = _sidc.Ck();

  805.         if (0 != iCk) {
  806.             adblManifestJacobianDerivAtLeftOrdinate = new double[iCk];

  807.             for (int i = 0; i < iCk; ++i)
  808.                 adblManifestJacobianDerivAtLeftOrdinate[i] = 0.;
  809.         }

  810.         if (null == csPreceeding) return false;

  811.         try {
  812.             if (null == aSBFCManifestSensitivity) return true;

  813.             if (!calibrateLocalManifestJacobian (strManifestMeasure, new
  814.                 org.drip.spline.params.SegmentStateCalibrationInputs (new double[] {left()}, new double[]
  815.                     {0.}, adblManifestJacobianDerivAtLeftOrdinate, null, aSBFCManifestSensitivity,
  816.                         sbfrManifestSensitivity), aSBFCState))
  817.                 return false;

  818.             org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  819.                 (strManifestMeasure);

  820.             if (null == lsms) return true;

  821.             return lsms.getPMSC().impactFade() ? calibratePreceedingManifestJacobian (strManifestMeasure, new
  822.                 org.drip.spline.params.SegmentStateCalibrationInputs (new double[] {left(), right()}, new
  823.                     double[] {csPreceeding.calcDResponseDManifest (strManifestMeasure, left(), 1), 0.}, null,
  824.                         CkDBasisCoeffDPreceedingManifestMeasure (strManifestMeasure), null, null)) :
  825.                             lsms.setDResponseDPreceedingManifest (csPreceeding.calcDResponseDManifest
  826.                                 (strManifestMeasure, left(), 1));
  827.         } catch (java.lang.Exception e) {
  828.             e.printStackTrace();
  829.         }

  830.         return false;
  831.     }

  832.     /**
  833.      * Compute the Local and the Preceeding Manifest Measure Sensitivity Coefficients from the Preceeding
  834.      *  Segments, the Local Response Value Sensitivity at the Right Predictor Ordinate, and the Local Best
  835.      *  Fit Response Sensitivity
  836.      *
  837.      * @param csPreceeding Preceeding Predictor/Response Segment
  838.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  839.      * @param dblRightStateManifestSensitivity Response Value Manifest Sensitivity at the Right Predictor
  840.      *  Ordinate
  841.      * @param sbfrManifestSensitivity Segment's Best Fit Weighted Response Value Manifest Sensitivity
  842.      *
  843.      * @return TRUE - If the calibration succeeds
  844.      */

  845.     public boolean manifestMeasureSensitivity (
  846.         final LatentStateResponseModel csPreceeding,
  847.         final java.lang.String strManifestMeasure,
  848.         final double dblRightStateManifestSensitivity,
  849.         final org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity)
  850.     {
  851.         if (null == csPreceeding) return false;

  852.         int iCk = _sidc.Ck();

  853.         try {
  854.             double[] adblManifestJacobianDerivAtLeftOrdinate = null;

  855.             if (0 != iCk) {
  856.                 adblManifestJacobianDerivAtLeftOrdinate = new double[iCk];

  857.                 for (int i = 0; i < iCk; ++i)
  858.                     adblManifestJacobianDerivAtLeftOrdinate[i] = 0.;
  859.             }

  860.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblRightStateManifestSensitivity)) return true;

  861.             if (!calibrateLocalManifestJacobian (strManifestMeasure, new
  862.                 org.drip.spline.params.SegmentStateCalibrationInputs (new double[] {left(), right()}, new
  863.                     double[] {0., dblRightStateManifestSensitivity}, 0 != iCk ?
  864.                         adblManifestJacobianDerivAtLeftOrdinate : null, null, null, sbfrManifestSensitivity),
  865.                             null))
  866.                 return false;

  867.             org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  868.                 (strManifestMeasure);

  869.             if (null == lsms) return true;

  870.             return lsms.getPMSC().impactFade() ? calibratePreceedingManifestJacobian (strManifestMeasure, new
  871.                 org.drip.spline.params.SegmentStateCalibrationInputs (new double[] {left(), right()}, new
  872.                     double[] {csPreceeding.calcDResponseDManifest (strManifestMeasure, left(), 1), 0.}, null,
  873.                         CkDBasisCoeffDPreceedingManifestMeasure (strManifestMeasure), null, null)) :
  874.                             lsms.setDResponseDPreceedingManifest (csPreceeding.calcDResponseDManifest
  875.                                 (strManifestMeasure, left(), 1));
  876.         } catch (java.lang.Exception e) {
  877.             e.printStackTrace();
  878.         }

  879.         return false;
  880.     }

  881.     /**
  882.      * Compute the Local and the Preceeding Manifest Measure Sensitivity Coefficients from the Local
  883.      *  Response Value Sensitivity at the Left/Right Predictor Ordinate, the Local Left Response Value
  884.      *  Sensitivity Slope, and the Local Best Fit Response Sensitivity.
  885.      *
  886.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  887.      * @param dblLeftManifestSensitivity Left Edge Response Value Manifest Sensitivity
  888.      * @param dblLeftSlopeManifestSensitivity Left Edge Response Slope Manifest Sensitivity
  889.      * @param dblRightManifestSensitivity Right Edge Response Value Manifest Sensitivity
  890.      * @param sbfrManifestSensitivity Segment's Best Fit Weighted Response Values Manifest Sensitivity
  891.      *
  892.      * @return TRUE - The Calibration Succeeded
  893.      */

  894.     public boolean manifestMeasureSensitivity (
  895.         final java.lang.String strManifestMeasure,
  896.         final double dblLeftManifestSensitivity,
  897.         final double dblLeftSlopeManifestSensitivity,
  898.         final double dblRightManifestSensitivity,
  899.         final org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity)
  900.     {
  901.         try {
  902.             return org.drip.numerical.common.NumberUtil.IsValid (dblLeftManifestSensitivity) &&
  903.                 org.drip.numerical.common.NumberUtil.IsValid (dblLeftSlopeManifestSensitivity) &&
  904.                     org.drip.numerical.common.NumberUtil.IsValid (dblRightManifestSensitivity) ?
  905.                         calibrateLocalManifestJacobian (strManifestMeasure, new
  906.                             org.drip.spline.params.SegmentStateCalibrationInputs (new double[] {left(),
  907.                                 right()}, new double[] {dblLeftManifestSensitivity,
  908.                                     dblRightManifestSensitivity},
  909.                                         org.drip.numerical.common.CollectionUtil.DerivArrayFromSlope
  910.                                             (numParameters() - 2, dblLeftSlopeManifestSensitivity), null,
  911.                                                 null, sbfrManifestSensitivity), null) : true;
  912.         } catch (java.lang.Exception e) {
  913.             e.printStackTrace();
  914.         }

  915.         return false;
  916.     }

  917.     /**
  918.      * Compute the Local and the Preceeding Manifest Measure Sensitivity Coefficients from the Local
  919.      *  Response Value/Sensitivity Constraints at the Left/Right Predictor Ordinate, the Local Left
  920.      *  Response Value Sensitivity Slope, and the Local Best Fit Response Sensitivity
  921.      *
  922.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  923.      * @param wrvcStateLeft Left Edge Response Value Constraint
  924.      * @param wrvcStateRight Right Edge Response Value Constraint
  925.      * @param dblLeftSlopeManifestSensitivity Left Edge Response Value Slope Manifest Sensitivity
  926.      * @param wrvcStateLeftManifestSensitivity Left Edge Response Value Constraint Manifest Sensitivity
  927.      * @param wrvcStateRightManifestSensitivity Right Edge Response Value Constraint Manifest Sensitivity
  928.      * @param sbfrManifestSensitivity Segment's Best Fit Weighted Response Manifest Sensitivity
  929.      *
  930.      * @return TRUE - If the calibration succeeds
  931.      */

  932.     public boolean manifestMeasureSensitivity (
  933.         final java.lang.String strManifestMeasure,
  934.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateLeft,
  935.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateRight,
  936.         final double dblLeftSlopeManifestSensitivity,
  937.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateLeftManifestSensitivity,
  938.         final org.drip.spline.params.SegmentResponseValueConstraint wrvcStateRightManifestSensitivity,
  939.         final org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity)
  940.     {
  941.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCState = null;
  942.         org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFCManifestSensitivity = null;

  943.         try {
  944.             if (null != wrvcStateLeft || null != wrvcStateRight)
  945.                 aSBFCState = new org.drip.spline.params.SegmentBasisFlexureConstraint[] {null ==
  946.                     wrvcStateLeft ? null : wrvcStateLeft.responseIndexedBasisConstraint (_be, this), null ==
  947.                         wrvcStateRight ? null : wrvcStateRight.responseIndexedBasisConstraint (_be, this)};

  948.             if (null != wrvcStateLeftManifestSensitivity || null != wrvcStateRightManifestSensitivity)
  949.                 aSBFCManifestSensitivity = new org.drip.spline.params.SegmentBasisFlexureConstraint[] {null
  950.                     == wrvcStateLeftManifestSensitivity ? null :
  951.                         wrvcStateLeftManifestSensitivity.responseIndexedBasisConstraint (_be, this), null ==
  952.                             wrvcStateRightManifestSensitivity ? null :
  953.                                 wrvcStateRightManifestSensitivity.responseIndexedBasisConstraint (_be,
  954.                                     this)};

  955.             return null == aSBFCManifestSensitivity ? true : calibrateLocalManifestJacobian
  956.                 (strManifestMeasure, new org.drip.spline.params.SegmentStateCalibrationInputs (null, null,
  957.                     org.drip.numerical.common.CollectionUtil.DerivArrayFromSlope (numParameters() - 2,
  958.                         dblLeftSlopeManifestSensitivity), null, aSBFCManifestSensitivity,
  959.                             sbfrManifestSensitivity), aSBFCState);
  960.         } catch (java.lang.Exception e) {
  961.             e.printStackTrace();
  962.         }

  963.         return false;
  964.     }

  965.     /**
  966.      * Retrieve the Segment Curvature DPE
  967.      *
  968.      * @return The Segment Curvature DPE
  969.      *
  970.      * @throws java.lang.Exception Thrown if the Segment Curvature DPE cannot be computed
  971.      */

  972.     public double curvatureDPE()
  973.         throws java.lang.Exception
  974.     {
  975.         double dblDPE = 0.;

  976.         int iNumBasis = _be.numBasis();

  977.         org.drip.spline.params.SegmentFlexurePenaltyControl sfpc = _sidc.curvaturePenaltyControl();

  978.         if (null == sfpc) sfpc = new org.drip.spline.params.SegmentFlexurePenaltyControl (2, 1.);

  979.         org.drip.spline.segment.BestFitFlexurePenalizer bffp = new
  980.             org.drip.spline.segment.BestFitFlexurePenalizer (this, sfpc, null, null, _be);

  981.         for (int i = 0; i < iNumBasis; ++i) {
  982.             for (int j = 0; j < iNumBasis; ++j)
  983.                 dblDPE += _adblResponseBasisCoeff[i] * _adblResponseBasisCoeff[j] *
  984.                     bffp.basisPairCurvaturePenalty (i, j);
  985.         }

  986.         return sfpc.amplitude() * dblDPE;
  987.     }

  988.     /**
  989.      * Retrieve the Segment Length DPE
  990.      *
  991.      * @return The Segment Length DPE
  992.      *
  993.      * @throws java.lang.Exception Thrown if the Segment Length DPE cannot be computed
  994.      */

  995.     public double lengthDPE()
  996.         throws java.lang.Exception
  997.     {
  998.         double dblDPE = 0.;

  999.         int iNumBasis = _be.numBasis();

  1000.         org.drip.spline.params.SegmentFlexurePenaltyControl sfpcLength = _sidc.lengthPenaltyControl();

  1001.         if (null == sfpcLength) sfpcLength = new org.drip.spline.params.SegmentFlexurePenaltyControl (1, 1.);

  1002.         org.drip.spline.segment.BestFitFlexurePenalizer bffp = new
  1003.             org.drip.spline.segment.BestFitFlexurePenalizer (this, null, sfpcLength, null, _be);

  1004.         for (int i = 0; i < iNumBasis; ++i) {
  1005.             for (int j = 0; j < iNumBasis; ++j)
  1006.                 dblDPE += _adblResponseBasisCoeff[i] * _adblResponseBasisCoeff[j] *
  1007.                     bffp.basisPairLengthPenalty (i, j);
  1008.         }

  1009.         return sfpcLength.amplitude() * dblDPE;
  1010.     }

  1011.     /**
  1012.      * Retrieve the Segment Best Fit DPE
  1013.      *
  1014.      * @param sbfr The Segment's Best Fit Response Inputs
  1015.      *
  1016.      * @return The Segment Best Fit DPE
  1017.      *
  1018.      * @throws java.lang.Exception Thrown if the Segment Best Fit DPE cannot be computed
  1019.      */

  1020.     public double bestFitDPE (
  1021.         final org.drip.spline.params.SegmentBestFitResponse sbfr)
  1022.         throws java.lang.Exception
  1023.     {
  1024.         if (null == sbfr) return 0.;

  1025.         double dblDPE = 0.;

  1026.         int iNumBasis = _be.numBasis();

  1027.         org.drip.spline.segment.BestFitFlexurePenalizer bffp = new
  1028.             org.drip.spline.segment.BestFitFlexurePenalizer (this, null, null, sbfr, _be);

  1029.         for (int i = 0; i < iNumBasis; ++i) {
  1030.             for (int j = 0; j < iNumBasis; ++j)
  1031.                 dblDPE += _adblResponseBasisCoeff[i] * _adblResponseBasisCoeff[j] * bffp.basisBestFitPenalty
  1032.                     (i, j);
  1033.         }

  1034.         return dblDPE;
  1035.     }

  1036.     /**
  1037.      * Calculate the Response Value at the given Predictor Ordinate
  1038.      *
  1039.      * @param dblPredictorOrdinate Predictor Ordinate
  1040.      *
  1041.      * @return The Response Value
  1042.      *
  1043.      * @throws java.lang.Exception Thrown if the calculation did not succeed
  1044.      */

  1045.     public double responseValue (
  1046.         final double dblPredictorOrdinate)
  1047.         throws java.lang.Exception
  1048.     {
  1049.         return _be.responseValue (_adblResponseBasisCoeff, dblPredictorOrdinate);
  1050.     }

  1051.     /**
  1052.      * Calculate the Ordered Response Value Derivative at the Predictor Ordinate
  1053.      *
  1054.      * @param dblPredictorOrdinate Predictor Ordinate at which the ordered Response Derivative is to be
  1055.      *  calculated
  1056.      * @param iOrder Derivative Order
  1057.      *
  1058.      * @throws java.lang.Exception Thrown if the Ordered Response Value Derivative cannot be calculated
  1059.      *
  1060.      * @return Retrieve the Ordered Response Value Derivative
  1061.      */

  1062.     public double calcResponseValueDerivative (
  1063.         final double dblPredictorOrdinate,
  1064.         final int iOrder)
  1065.         throws java.lang.Exception
  1066.     {
  1067.         return 0 == iOrder ? responseValue (dblPredictorOrdinate) : _be.responseValueDerivative
  1068.             (_adblResponseBasisCoeff, dblPredictorOrdinate, iOrder);
  1069.     }

  1070.     /**
  1071.      * Calculate the Ordered Derivative of the Response to the Manifest
  1072.      *
  1073.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  1074.      * @param dblPredictorOrdinate Predictor Ordinate at which the ordered Derivative of the Response to the
  1075.      *  Manifest is to be calculated
  1076.      * @param iOrder Derivative Order
  1077.      *
  1078.      * @throws java.lang.Exception Thrown if the Ordered Derivative of the Response to the Manifest cannot be
  1079.      *  calculated
  1080.      *
  1081.      * @return Retrieve the Ordered Derivative of the Response to the Manifest
  1082.      */

  1083.     public double calcDResponseDManifest (
  1084.         final java.lang.String strManifestMeasure,
  1085.         final double dblPredictorOrdinate,
  1086.         final int iOrder)
  1087.         throws java.lang.Exception
  1088.     {
  1089.         if (0 == iOrder)
  1090.             throw new java.lang.Exception
  1091.                 ("LatentStateResponseModel::calcDResponseDManifest => Invalid Inputs");

  1092.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  1093.             (strManifestMeasure);

  1094.         if (null == lsms)
  1095.             throw new java.lang.Exception
  1096.                 ("LatentStateResponseModel::calcDResponseDManifest => Invalid Inputs");

  1097.         return _be.responseValue (lsms.getDBasisCoeffDLocalManifest(), dblPredictorOrdinate);
  1098.     }

  1099.     /**
  1100.      * Calculate the Ordered Derivative of the Response to the Preceeding Manifest
  1101.      *
  1102.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  1103.      * @param dblPredictorOrdinate Predictor Ordinate at which the ordered Derivative of the Response to the
  1104.      *  Manifest is to be calculated
  1105.      * @param iOrder Derivative Order
  1106.      *
  1107.      * @throws java.lang.Exception Thrown if the Ordered Derivative of the Response to the Manifest cannot be
  1108.      *  calculated
  1109.      *
  1110.      * @return Retrieve the Ordered Derivative of the Response to the Preceeding Manifest
  1111.      */

  1112.     public double calcDResponseDPreceedingManifest (
  1113.         final java.lang.String strManifestMeasure,
  1114.         final double dblPredictorOrdinate,
  1115.         final int iOrder)
  1116.         throws java.lang.Exception
  1117.     {
  1118.         if (0 == iOrder)
  1119.             throw new java.lang.Exception
  1120.                 ("LatentStateResponseModel::calcDResponseDPreceedingManifest => Invalid Inputs");

  1121.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  1122.             (strManifestMeasure);

  1123.         if (null == lsms)
  1124.             throw new java.lang.Exception
  1125.                 ("LatentStateResponseModel::calcDResponseDPreceedingManifest => Cannot locate state Manifest sensitivity");

  1126.         org.drip.spline.params.PreceedingManifestSensitivityControl pqsc = lsms.getPMSC();

  1127.         double dblDResponseDPreceedingManifest = lsms.getDResponseDPreceedingManifest();

  1128.         if (!pqsc.impactFade())
  1129.             return org.drip.numerical.common.NumberUtil.IsValid (dblDResponseDPreceedingManifest) ?
  1130.                 dblDResponseDPreceedingManifest : 0.;

  1131.         org.drip.spline.segment.BasisEvaluator be = pqsc.basisEvaluator();

  1132.         double[] adblDBasisCoeffDPreceedingManifest = lsms.getDBasisCoeffDPreceedingManifest();

  1133.         return null == adblDBasisCoeffDPreceedingManifest ? 0. : (null == be ? _be : be).responseValue
  1134.             (adblDBasisCoeffDPreceedingManifest, dblPredictorOrdinate);
  1135.     }

  1136.     /**
  1137.      * Retrieve the Manifest Measure Preceeding Manifest Impact Flag
  1138.      *
  1139.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  1140.      *
  1141.      * @return The Manifest Measure Preceeding Manifest Impact Flag
  1142.      *
  1143.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  1144.      */

  1145.     public boolean impactFade (
  1146.         final java.lang.String strManifestMeasure)
  1147.         throws java.lang.Exception
  1148.     {
  1149.         org.drip.spline.segment.LatentStateManifestSensitivity lsms = manifestSensitivity
  1150.             (strManifestMeasure);

  1151.         if (null == lsms)
  1152.             throw new java.lang.Exception
  1153.                 ("LatentStateResponseModel::impactFade => Cannot locate state Manifest sensitivity");

  1154.         return lsms.getPMSC().impactFade();
  1155.     }

  1156.     /**
  1157.      * Calculate the Jacobian of the Segment's Response Basis Function Coefficients to the Edge Inputs
  1158.      *
  1159.      * @return The Jacobian of the Segment's Response Basis Function Coefficients to the Edge Inputs
  1160.      */

  1161.     public org.drip.numerical.differentiation.WengertJacobian jackDCoeffDEdgeInputs()
  1162.     {
  1163.         if (null != _wjDBasisCoeffDEdgeValue) return _wjDBasisCoeffDEdgeValue;

  1164.         int iNumResponseBasisCoeff = _be.numBasis();

  1165.         try {
  1166.             _wjDBasisCoeffDEdgeValue = new org.drip.numerical.differentiation.WengertJacobian (iNumResponseBasisCoeff,
  1167.                 iNumResponseBasisCoeff);
  1168.         } catch (java.lang.Exception e) {
  1169.             e.printStackTrace();

  1170.             return _wjDBasisCoeffDEdgeValue = null;
  1171.         }

  1172.         for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  1173.             if (!_wjDBasisCoeffDEdgeValue.setWengert (i, _adblResponseBasisCoeff[i]))
  1174.                 return _wjDBasisCoeffDEdgeValue = null;
  1175.         }

  1176.         if (null == _aadblDResponseBasisCoeffDConstraint) return null;

  1177.         int iSize = _aadblDResponseBasisCoeffDConstraint.length;

  1178.         for (int i = 0; i < iSize; ++i) {
  1179.             for (int j = 0; j < iSize; ++j) {
  1180.                 if (!_wjDBasisCoeffDEdgeValue.accumulatePartialFirstDerivative (i, j,
  1181.                     _aadblDResponseBasisCoeffDConstraint[i][j]))
  1182.                     return null;
  1183.             }
  1184.         }

  1185.         return _wjDBasisCoeffDEdgeValue;
  1186.     }

  1187.     /**
  1188.      * Calculate the Jacobian of the Response to the Edge Inputs at the given Predictor Ordinate
  1189.      *
  1190.      * @param dblPredictorOrdinate The Predictor Ordinate
  1191.      * @param iOrder Order of the Derivative Desired
  1192.      *
  1193.      * @return The Jacobian of the Response to the Edge Inputs at the given Predictor Ordinate
  1194.      */

  1195.     public org.drip.numerical.differentiation.WengertJacobian jackDResponseDEdgeInput (
  1196.         final double dblPredictorOrdinate,
  1197.         final int iOrder)
  1198.     {
  1199.         try {
  1200.             int iNumResponseBasisCoeff = _be.numBasis();

  1201.             org.drip.numerical.differentiation.WengertJacobian wjDResponseDEdgeParams = null;
  1202.             double[][] aadblDBasisCoeffDEdgeParams = new
  1203.                 double[iNumResponseBasisCoeff][iNumResponseBasisCoeff];

  1204.             double[] adblDResponseDBasisCoeff = DResponseDBasisCoeff (dblPredictorOrdinate, iOrder);

  1205.             if (null == adblDResponseDBasisCoeff || iNumResponseBasisCoeff !=
  1206.                 adblDResponseDBasisCoeff.length)
  1207.                 return null;

  1208.             org.drip.numerical.differentiation.WengertJacobian wjDBasisCoeffDEdgeParams = (null ==
  1209.                 _wjDBasisCoeffDEdgeValue) ? jackDCoeffDEdgeInputs() : _wjDBasisCoeffDEdgeValue;

  1210.             for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  1211.                 for (int j = 0; j < iNumResponseBasisCoeff; ++j)
  1212.                     aadblDBasisCoeffDEdgeParams[j][i] = wjDBasisCoeffDEdgeParams.firstDerivative (j, i);
  1213.             }

  1214.             if (!(wjDResponseDEdgeParams = new org.drip.numerical.differentiation.WengertJacobian (1,
  1215.                 iNumResponseBasisCoeff)).setWengert (0, responseValue (dblPredictorOrdinate)))
  1216.                 return null;

  1217.             for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  1218.                 for (int j = 0; j < iNumResponseBasisCoeff; ++j) {
  1219.                     if (!wjDResponseDEdgeParams.accumulatePartialFirstDerivative (0, i,
  1220.                         adblDResponseDBasisCoeff[j] * aadblDBasisCoeffDEdgeParams[j][i]))
  1221.                         return null;
  1222.                 }
  1223.             }

  1224.             return wjDResponseDEdgeParams;
  1225.         } catch (java.lang.Exception e) {
  1226.             e.printStackTrace();
  1227.         }

  1228.         return null;
  1229.     }

  1230.     /**
  1231.      * Calculate the Jacobian of the Response to the Basis Coefficients at the given Predictor Ordinate
  1232.      *
  1233.      * @param dblPredictorOrdinate The Predictor Ordinate
  1234.      * @param iOrder Order of the Derivative Desired
  1235.      *
  1236.      * @return The Jacobian of the Response to the Basis Coefficients at the given Predictor Ordinate
  1237.      */

  1238.     public org.drip.numerical.differentiation.WengertJacobian jackDResponseDBasisCoeff (
  1239.         final double dblPredictorOrdinate,
  1240.         final int iOrder)
  1241.     {
  1242.         try {
  1243.             int iNumResponseBasisCoeff = _be.numBasis();

  1244.             double[] adblBasisDResponseDBasisCoeff = DResponseDBasisCoeff (dblPredictorOrdinate, iOrder);

  1245.             if (null == adblBasisDResponseDBasisCoeff || iNumResponseBasisCoeff !=
  1246.                 adblBasisDResponseDBasisCoeff.length)
  1247.                 return null;

  1248.             org.drip.numerical.differentiation.WengertJacobian wjDResponseDBasisCoeff = new
  1249.                 org.drip.numerical.differentiation.WengertJacobian (1, iNumResponseBasisCoeff);

  1250.             for (int i = 0; i < iNumResponseBasisCoeff; ++i) {
  1251.                 if (!wjDResponseDBasisCoeff.accumulatePartialFirstDerivative (0, i,
  1252.                     adblBasisDResponseDBasisCoeff[i]))
  1253.                     return null;
  1254.             }

  1255.             return wjDResponseDBasisCoeff;
  1256.         } catch (java.lang.Exception e) {
  1257.             e.printStackTrace();
  1258.         }

  1259.         return null;
  1260.     }

  1261.     /**
  1262.      * Calibrate the segment and calculate the Jacobian of the Segment's Response Basis Function Coefficients
  1263.      *  to the Edge Parameters
  1264.      *
  1265.      * @param adblPredictorOrdinate Array of Predictor Ordinates
  1266.      * @param adblResponseValue Array of Response Values
  1267.      * @param adblLeftEdgeDeriv Array of Left Edge Derivatives
  1268.      * @param adblRightEdgeDeriv Array of Right Edge Derivatives
  1269.      * @param aSBFC Array of Segment Flexure Constraints, expressed as Basis Coefficients
  1270.      * @param sbfr Segment Best Fit Response Instance
  1271.      *
  1272.      * @return The Jacobian of the Segment's Response Basis Function Coefficients to the Edge Parameters
  1273.      */

  1274.     public org.drip.numerical.differentiation.WengertJacobian jackDCoeffDEdgeParams (
  1275.         final double[] adblPredictorOrdinate,
  1276.         final double[] adblResponseValue,
  1277.         final double[] adblLeftEdgeDeriv,
  1278.         final double[] adblRightEdgeDeriv,
  1279.         final org.drip.spline.params.SegmentBasisFlexureConstraint[] aSBFC,
  1280.         final org.drip.spline.params.SegmentBestFitResponse sbfr)
  1281.     {
  1282.         try {
  1283.             return calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs
  1284.                 (adblPredictorOrdinate, adblResponseValue, adblLeftEdgeDeriv, adblRightEdgeDeriv, aSBFC,
  1285.                     sbfr)) ? jackDCoeffDEdgeInputs() : null;
  1286.         } catch (java.lang.Exception e) {
  1287.             e.printStackTrace();
  1288.         }

  1289.         return null;
  1290.     }

  1291.     /**
  1292.      * Calibrate the Coefficients from the Edge Response Values and the Left Edge Response Value Slope and
  1293.      *  calculate the Jacobian of the Segment's Response Basis Function Coefficients to the Edge Parameters
  1294.      *
  1295.      * @param dblLeftValue Left Edge Response Value
  1296.      * @param dblLeftSlope Left Edge Response Slope
  1297.      * @param dblRightValue Right Edge Response Value
  1298.      * @param sbfrState Segment's Best Fit Weighted Response Values
  1299.      *
  1300.      * @return The Jacobian of the Segment's Response Basis Function Coefficients to the Edge Parameters
  1301.      */

  1302.     public org.drip.numerical.differentiation.WengertJacobian jackDCoeffDEdgeParams (
  1303.         final double dblLeftValue,
  1304.         final double dblLeftSlope,
  1305.         final double dblRightValue,
  1306.         final org.drip.spline.params.SegmentBestFitResponse sbfrState)
  1307.     {
  1308.         return calibrate (dblLeftValue, dblLeftSlope, dblRightValue, sbfrState) ? jackDCoeffDEdgeInputs() :
  1309.             null;
  1310.     }

  1311.     /**
  1312.      * Calibrate the coefficients from the prior Segment and the Response Value at the Right Predictor
  1313.      *  Ordinate and calculate the Jacobian of the Segment's Response Basis Function Coefficients to the Edge
  1314.      *  Parameters
  1315.      *
  1316.      * @param csPreceeding Previous Predictor/Response Segment
  1317.      * @param strManifestMeasure Manifest Measure whose Sensitivity is sought
  1318.      * @param dblRightStateValue Response Value at the Right Predictor Ordinate
  1319.      * @param sbfrState Segment's Best Fit Weighted Response Values
  1320.      * @param dblRightStateManifestSensitivity Response Value Manifest Sensitivity at the Right Predictor
  1321.      *  Ordinate
  1322.      * @param sbfrManifestSensitivity Segment's Best Fit Weighted Response Value Manifest Sensitivity
  1323.      *
  1324.      * @return The Jacobian
  1325.      */

  1326.     public org.drip.numerical.differentiation.WengertJacobian jackDCoeffDEdgeParams (
  1327.         final LatentStateResponseModel csPreceeding,
  1328.         final java.lang.String strManifestMeasure,
  1329.         final double dblRightStateValue,
  1330.         final org.drip.spline.params.SegmentBestFitResponse sbfrState,
  1331.         final double dblRightStateManifestSensitivity,
  1332.         final org.drip.spline.params.SegmentBestFitResponse sbfrManifestSensitivity)
  1333.     {
  1334.         return !calibrate (csPreceeding, dblRightStateValue, sbfrState) || !manifestMeasureSensitivity
  1335.             (csPreceeding, strManifestMeasure, dblRightStateManifestSensitivity, sbfrManifestSensitivity) ?
  1336.                 null : jackDCoeffDEdgeInputs();
  1337.     }

  1338.     /**
  1339.      * Indicate whether the given segment is monotone. If monotone, may optionally indicate the nature of
  1340.      *  the extrema contained inside (maxima/minima/infection).
  1341.      *  
  1342.      * @return The monotone Type
  1343.      */

  1344.     public org.drip.spline.segment.Monotonocity monotoneType()
  1345.     {
  1346.         if (1 >= _sidc.Ck()) {
  1347.             try {
  1348.                 return new org.drip.spline.segment.Monotonocity
  1349.                     (org.drip.spline.segment.Monotonocity.MONOTONIC);
  1350.             } catch (java.lang.Exception e) {
  1351.                 e.printStackTrace();

  1352.                 return null;
  1353.             }
  1354.         }

  1355.         org.drip.function.definition.R1ToR1 ofDeriv = new
  1356.             org.drip.function.definition.R1ToR1 (null) {
  1357.             @Override public double evaluate (
  1358.                 final double dblX)
  1359.                 throws java.lang.Exception
  1360.             {
  1361.                 return _be.responseValueDerivative (_adblResponseBasisCoeff, dblX, 1);
  1362.             }

  1363.             @Override public org.drip.numerical.differentiation.Differential differential (
  1364.                 final double dblX,
  1365.                 final double dblOFBase,
  1366.                 final int iOrder)
  1367.             {
  1368.                 try {
  1369.                     double dblVariateInfinitesimal = _dc.getVariateInfinitesimal (dblX);

  1370.                     return new org.drip.numerical.differentiation.Differential (dblVariateInfinitesimal,
  1371.                         _be.responseValueDerivative (_adblResponseBasisCoeff, dblX, iOrder) *
  1372.                             dblVariateInfinitesimal);
  1373.                 } catch (java.lang.Exception e) {
  1374.                     e.printStackTrace();
  1375.                 }

  1376.                 return null;
  1377.             }

  1378.             @Override public double integrate (
  1379.                 final double dblBegin,
  1380.                 final double dblEnd)
  1381.                 throws java.lang.Exception
  1382.             {
  1383.                 return org.drip.numerical.integration.R1ToR1Integrator.Boole (this, dblBegin, dblEnd);
  1384.             }
  1385.         };

  1386.         try {
  1387.             org.drip.function.r1tor1solver.FixedPointFinderOutput fpop = new
  1388.                 org.drip.function.r1tor1solver.FixedPointFinderBrent (0., ofDeriv, false).findRoot
  1389.                     (org.drip.function.r1tor1solver.InitializationHeuristics.FromHardSearchEdges (0., 1.));

  1390.             if (null == fpop || !fpop.containsRoot())
  1391.                 return new org.drip.spline.segment.Monotonocity
  1392.                     (org.drip.spline.segment.Monotonocity.MONOTONIC);

  1393.             double dblExtremum = fpop.getRoot();

  1394.             if (!org.drip.numerical.common.NumberUtil.IsValid (dblExtremum) || dblExtremum <= 0. || dblExtremum
  1395.                 >= 1.)
  1396.                 return new org.drip.spline.segment.Monotonocity
  1397.                     (org.drip.spline.segment.Monotonocity.MONOTONIC);

  1398.             double dbl2ndDeriv = _be.responseValueDerivative (_adblResponseBasisCoeff, dblExtremum, 2);

  1399.             if (0. > dbl2ndDeriv)
  1400.                 return new org.drip.spline.segment.Monotonocity
  1401.                     (org.drip.spline.segment.Monotonocity.MAXIMA);

  1402.             if (0. < dbl2ndDeriv)
  1403.                 return new org.drip.spline.segment.Monotonocity
  1404.                     (org.drip.spline.segment.Monotonocity.MINIMA);

  1405.             if (0. == dbl2ndDeriv)
  1406.                 return new org.drip.spline.segment.Monotonocity
  1407.                     (org.drip.spline.segment.Monotonocity.INFLECTION);

  1408.             return new org.drip.spline.segment.Monotonocity
  1409.                 (org.drip.spline.segment.Monotonocity.NON_MONOTONIC);
  1410.         } catch (java.lang.Exception e) {
  1411.             e.printStackTrace();
  1412.         }

  1413.         try {
  1414.             return new org.drip.spline.segment.Monotonocity (org.drip.spline.segment.Monotonocity.MONOTONIC);
  1415.         } catch (java.lang.Exception e) {
  1416.             e.printStackTrace();
  1417.         }

  1418.         return null;
  1419.     }

  1420.     /**
  1421.      * Clip the part of the Segment to the Right of the specified Predictor Ordinate. Retain all other
  1422.      *  constraints the same.
  1423.      *
  1424.      * @param dblPredictorOrdinate The Predictor Ordinate
  1425.      *
  1426.      * @return The Clipped Segment
  1427.      */

  1428.     public LatentStateResponseModel clipLeftOfPredictorOrdinate (
  1429.         final double dblPredictorOrdinate)
  1430.     {
  1431.         try {
  1432.             LatentStateResponseModel csLeftSnipped = LatentStateResponseModel.Create (dblPredictorOrdinate,
  1433.                 right(), _be.replicate(), _sidc);

  1434.             int iCk = _sidc.Ck();

  1435.             double[] adblCalibLeftEdgeDeriv = 0 != iCk ? csLeftSnipped.transmissionCk (dblPredictorOrdinate,
  1436.                 this, iCk) : null;

  1437.             return csLeftSnipped.calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs
  1438.                 (new double[] {dblPredictorOrdinate, right()}, new double[] {responseValue
  1439.                     (dblPredictorOrdinate), responseValue (right())}, adblCalibLeftEdgeDeriv, null, null,
  1440.                         null)) ? csLeftSnipped : null;
  1441.         } catch (java.lang.Exception e) {
  1442.             e.printStackTrace();
  1443.         }

  1444.         return null;
  1445.     }

  1446.     /**
  1447.      * Clip the part of the Segment to the Right of the specified Predictor Ordinate. Retain all other
  1448.      *  constraints the same.
  1449.      *
  1450.      * @param dblPredictorOrdinate The Predictor Ordinate
  1451.      *
  1452.      * @return The Clipped Segment
  1453.      */

  1454.     public LatentStateResponseModel clipRightOfPredictorOrdinate (
  1455.         final double dblPredictorOrdinate)
  1456.     {
  1457.         try {
  1458.             LatentStateResponseModel csRightSnipped = LatentStateResponseModel.Create (left(),
  1459.                 dblPredictorOrdinate, _be.replicate(), _sidc);

  1460.             int iCk = _sidc.Ck();

  1461.             return csRightSnipped.calibrateState (new org.drip.spline.params.SegmentStateCalibrationInputs
  1462.                 (new double[] {left(), dblPredictorOrdinate}, new double[] {responseValue (left()),
  1463.                     responseValue (dblPredictorOrdinate)}, 0 != iCk ? csRightSnipped.transmissionCk (left(),
  1464.                         this, iCk) : null, null, null, null)) ? csRightSnipped : null;
  1465.         } catch (java.lang.Exception e) {
  1466.             e.printStackTrace();
  1467.         }

  1468.         return null;
  1469.     }

  1470.     /**
  1471.      * Display the string representation for diagnostic purposes
  1472.      *
  1473.      * @return The string representation
  1474.      */

  1475.     public java.lang.String displayString()
  1476.     {
  1477.         java.lang.StringBuffer sb = new java.lang.StringBuffer();

  1478.         sb.append ("\t\t\t[" + left() + " => " + right() + "\n");

  1479.         for (int i = 0; i < _adblResponseBasisCoeff.length; ++i) {
  1480.             if (0 != i) sb.append ("  |  ");

  1481.             sb.append (_adblResponseBasisCoeff[i] + "\n");
  1482.         }

  1483.         return sb.toString();
  1484.     }
  1485. }