Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
Bug Fixes/Re-organization:

Samples:

	- B Spline Segment Monic Basis Function - Constructor (1, 2)
	- B Spline Segment Monic Basis Function - Evaluate (3, 4, 5)
	- B Spline Segment Monic Basis Function - Derivative (6, 7, 8)
	- B Spline Segment Monic Basis Function - Integrate (9, 10, 11)
	- B Spline Segment Monic Basis Function - Normalizer (12, 13)
	- B Spline Segment Monic Basis Function - Normalized Cumulative (14, 15, 16)
	- B Spline Segment Multic Basis Function (17, 18)
	- B Spline Segment Multic Basis Function - Left (19, 20)
	- B Spline Segment Multic Basis Function - Right (21, 22)
	- B Spline Segment Multic Basis Function - Constructor (23, 24, 25)
	- B Spline Segment Multic Basis Function - Evaluate (26, 27, 28)
	- B Spline Segment Multic Basis Function - Integrate (29)
	- B Spline Segment Multic Basis Function - Normalizer (30)
	- B Spline Segment Multic Basis Function - Normalized Cumulative (31, 32, 33)
	- B Spline Segment Basis Function Set (34, 35, 36)
	- B Spline Segment Basis Function Set - Tension (37, 38)
	- B Spline Segment Basis Function Set - Response Array (39, 40, 41)
	- B Spline Segment Basis Function Set - Constructor (42, 43, 44)
	- Spline Grid Span (45, 46, 47)
	- Spline Grid Span - Left (48)
	- Spline Grid Span - Right (49)
	- Spline Grid Span - Is Merge State (50)
	- Spline Grid Span - Calculate Response Value (51)
	- Spline Grid Span - Calculate Response Value Derivative (52)
	- Spline Grid Span - Add Stretch (53)
	- Spline Grid Span - Get Containing Stretch (54)
	- Spline Grid Span - Get Stretch (55)
	- Spline Grid Span - Jack Response D Manifest Measure (56)
	- Spline Grid Span - In (57)
	- Spline Grid Span - Display String (58)
	- Spline Grid Overlapping Stretch Span (59, 60)


IdeaDRIP:
  • Loading branch information
Lakshmik committed Jan 7, 2024
1 parent ed2bfc1 commit ca131b8
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 225 deletions.
41 changes: 41 additions & 0 deletions ReleaseNotes/04_13_2023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Features:

Bug Fixes/Re-organization:

Samples:

- B Spline Segment Monic Basis Function - Constructor (1, 2)
- B Spline Segment Monic Basis Function - Evaluate (3, 4, 5)
- B Spline Segment Monic Basis Function - Derivative (6, 7, 8)
- B Spline Segment Monic Basis Function - Integrate (9, 10, 11)
- B Spline Segment Monic Basis Function - Normalizer (12, 13)
- B Spline Segment Monic Basis Function - Normalized Cumulative (14, 15, 16)
- B Spline Segment Multic Basis Function (17, 18)
- B Spline Segment Multic Basis Function - Left (19, 20)
- B Spline Segment Multic Basis Function - Right (21, 22)
- B Spline Segment Multic Basis Function - Constructor (23, 24, 25)
- B Spline Segment Multic Basis Function - Evaluate (26, 27, 28)
- B Spline Segment Multic Basis Function - Integrate (29)
- B Spline Segment Multic Basis Function - Normalizer (30)
- B Spline Segment Multic Basis Function - Normalized Cumulative (31, 32, 33)
- B Spline Segment Basis Function Set (34, 35, 36)
- B Spline Segment Basis Function Set - Tension (37, 38)
- B Spline Segment Basis Function Set - Response Array (39, 40, 41)
- B Spline Segment Basis Function Set - Constructor (42, 43, 44)
- Spline Grid Span (45, 46, 47)
- Spline Grid Span - Left (48)
- Spline Grid Span - Right (49)
- Spline Grid Span - Is Merge State (50)
- Spline Grid Span - Calculate Response Value (51)
- Spline Grid Span - Calculate Response Value Derivative (52)
- Spline Grid Span - Add Stretch (53)
- Spline Grid Span - Get Containing Stretch (54)
- Spline Grid Span - Get Stretch (55)
- Spline Grid Span - Jack Response D Manifest Measure (56)
- Spline Grid Span - In (57)
- Spline Grid Span - Display String (58)
- Spline Grid Overlapping Stretch Span (59, 60)


IdeaDRIP:
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@
/**
* <i>BasisHatPairGenerator</i> implements the generation functionality behind the hat basis function pair.
* It provides the following functionality:
*
* <ul>
* <li>Generate the array of the Hyperbolic Phy and Psy Hat Function Pair</li>
* <li>Generate the array of the Hyperbolic Phy and Psy Hat Function Pair From their Raw Counterparts</li>
* <li>Generate the array of the Cubic Rational Phy and Psy Hat Function Pair From their Raw Counterparts</li>
* <li>Generate the array of the Hat Function Pair From their Raw Counterparts</li>
* <li>Generate the array of the Hyperbolic Phy and Psy Hat Function Pair</li>
* <li>Generate the array of the Hyperbolic Phy and Psy Hat Function Pair From their Raw Counterparts</li>
* <li>Generate the array of the Cubic Rational Phy and Psy Hat Function Pair From their Raw Counterparts</li>
* <li>Generate the array of the Hat Function Pair From their Raw Counterparts</li>
* </ul>
*
* <br>
Expand Down
96 changes: 60 additions & 36 deletions src/main/java/org/drip/spline/bspline/SegmentBasisFunctionSet.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@

package org.drip.spline.bspline;

import org.drip.function.definition.R1ToR1;
import org.drip.function.r1tor1.Polynomial;
import org.drip.function.r1tor1.UnivariateReflection;
import org.drip.numerical.common.NumberUtil;
import org.drip.spline.basis.FunctionSet;

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

/*!
* Copyright (C) 2025 Lakshmi Krishnamurthy
* Copyright (C) 2024 Lakshmi Krishnamurthy
* Copyright (C) 2023 Lakshmi Krishnamurthy
* Copyright (C) 2022 Lakshmi Krishnamurthy
* Copyright (C) 2021 Lakshmi Krishnamurthy
* Copyright (C) 2020 Lakshmi Krishnamurthy
Expand Down Expand Up @@ -84,69 +93,84 @@

/**
* <i>SegmentBasisFunctionSet</i> class implements per-segment function set for B Splines and tension
* splines. Derived implementations expose explicit targeted basis functions.
*
* <br><br>
* splines. Derived implementations expose explicit targeted basis functions.
*
* <ul>
* <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
* <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/SplineBuilderLibrary.md">Spline Builder Library</a></li>
* <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>
* <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/bspline/README.md">de Boor Rational/Exponential/Tension B-Splines</a></li>
* <li><i>SegmentBasisFunctionSet</i> Constructor</li>
* <li>Retrieve the Tension Parameter</li>
* </ul>
* <br><br>
*
* <br>
* <style>table, td, th {
* padding: 1px; border: 2px solid #008000; border-radius: 8px; background-color: #dfff00;
* text-align: center; color: #0000ff;
* }
* </style>
*
* <table style="border:1px solid black;margin-left:auto;margin-right:auto;">
* <tr><td><b>Module </b></td> <td><a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></td></tr>
* <tr><td><b>Library</b></td> <td><a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></td></tr>
* <tr><td><b>Project</b></td> <td><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></td></tr>
* <tr><td><b>Package</b></td> <td><a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/spline/bspline/README.md">de Boor Rational/Exponential/Tension B-Splines</a></td></tr>
* </table>
* <br>
*
* @author Lakshmi Krishnamurthy
*/

public class SegmentBasisFunctionSet extends org.drip.spline.basis.FunctionSet {
protected double _dblTension = java.lang.Double.NaN;
public class SegmentBasisFunctionSet
extends FunctionSet
{
protected double _tension = Double.NaN;

private static final org.drip.function.definition.R1ToR1[] responseBasis (
final int iNumBasisToUse,
final org.drip.function.definition.R1ToR1[] aAUHat)
private static final R1ToR1[] ResponseBasisArray (
final int basisCountToUse,
final R1ToR1[] basisHatFunctionArray)
{
if (null == aAUHat || iNumBasisToUse > aAUHat.length) return null;
if (null == basisHatFunctionArray || basisCountToUse > basisHatFunctionArray.length) {
return null;
}

try {
org.drip.function.definition.R1ToR1[] aAU = new
org.drip.function.definition.R1ToR1[iNumBasisToUse + 2];
R1ToR1[] basisHatFunctionArrayToUse = new R1ToR1[basisCountToUse + 2];

aAU[0] = new org.drip.function.r1tor1.Polynomial (0);
basisHatFunctionArrayToUse[0] = new Polynomial (0);

aAU[1] = new org.drip.function.r1tor1.UnivariateReflection (new
org.drip.function.r1tor1.Polynomial (1));
basisHatFunctionArrayToUse[1] = new UnivariateReflection (new Polynomial (1));

for (int i = 0; i < iNumBasisToUse; ++i)
aAU[2 + i] = aAUHat[i];
for (int basisIndex = 0; basisIndex < basisCountToUse; ++basisIndex) {
basisHatFunctionArrayToUse[2 + basisIndex] = basisHatFunctionArray[basisIndex];
}

return aAU;
} catch (java.lang.Exception e) {
return basisHatFunctionArrayToUse;
} catch (Exception e) {
e.printStackTrace();
}

return null;
}

/**
* SegmentBasisFunctionSet constructor
* <i>SegmentBasisFunctionSet</i> constructor
*
* @param iNumBasisToUse Number of Basis in the Hat Basis Set to Use
* @param dblTension Tension Parameter
* @param aAUHat The Hat Representation Function Set
* @param basisCountToUse Number of Basis in the Hat Basis Set to Use
* @param tension Tension Parameter
* @param basisHatFunctionArray The Hat Representation Function Set
*
* @throws java.lang.Exception Thrown if the inputs are invalid
* @throws Exception Thrown if the inputs are invalid
*/

public SegmentBasisFunctionSet (
final int iNumBasisToUse,
final double dblTension,
final org.drip.function.definition.R1ToR1[] aAUHat)
throws java.lang.Exception
final int basisCountToUse,
final double tension,
final R1ToR1[] basisHatFunctionArray)
throws Exception
{
super (responseBasis (iNumBasisToUse, aAUHat));
super (ResponseBasisArray (basisCountToUse, basisHatFunctionArray));

if (!org.drip.numerical.common.NumberUtil.IsValid (_dblTension = dblTension))
throw new java.lang.Exception ("SegmentBasisFunctionSet ctr: Invalid Inputs!");
if (!NumberUtil.IsValid (_tension = tension)) {
throw new Exception ("SegmentBasisFunctionSet ctr: Invalid Inputs!");
}
}

/**
Expand All @@ -157,6 +181,6 @@ public SegmentBasisFunctionSet (

public double tension()
{
return _dblTension;
return _tension;
}
}
129 changes: 70 additions & 59 deletions src/main/java/org/drip/spline/bspline/SegmentMonicBasisFunction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package org.drip.spline.bspline;

import org.drip.numerical.common.NumberUtil;

/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*/
Expand Down Expand Up @@ -137,98 +139,107 @@ public SegmentMonicBasisFunction (
}

@Override public double evaluate (
final double dblPredictorOrdinate)
throws java.lang.Exception
final double predictorOrdinate)
throws Exception
{
if (!org.drip.numerical.common.NumberUtil.IsValid (dblPredictorOrdinate))
throw new java.lang.Exception ("SegmentMonicBasisFunction::evaluate => Invalid Inputs");
if (!NumberUtil.IsValid (predictorOrdinate)) {
throw new Exception ("SegmentMonicBasisFunction::evaluate => Invalid Inputs");
}

if (dblPredictorOrdinate < leading() || dblPredictorOrdinate > trailing()) return 0.;
if (predictorOrdinate < leading() || predictorOrdinate > trailing()) {
return 0.;
}

return dblPredictorOrdinate < following() ? _leftTensionBasisHat.evaluate (dblPredictorOrdinate) :
_rightTensionBasisHat.evaluate (dblPredictorOrdinate);
return predictorOrdinate < following() ? _leftTensionBasisHat.evaluate (predictorOrdinate) :
_rightTensionBasisHat.evaluate (predictorOrdinate);
}

@Override public double derivative (
final double dblPredictorOrdinate,
final int iOrder)
throws java.lang.Exception
final double predictorOrdinate,
final int order)
throws Exception
{
if (!org.drip.numerical.common.NumberUtil.IsValid (dblPredictorOrdinate))
throw new java.lang.Exception ("SegmentMonicBasisFunction::derivative => Invalid Inputs");
if (!NumberUtil.IsValid (predictorOrdinate)) {
throw new Exception ("SegmentMonicBasisFunction::derivative => Invalid Inputs");
}

if (dblPredictorOrdinate < leading() || dblPredictorOrdinate > trailing()) return 0.;
if (predictorOrdinate < leading() || predictorOrdinate > trailing()) {
return 0.;
}

return dblPredictorOrdinate < following() ? _leftTensionBasisHat.derivative (dblPredictorOrdinate, iOrder) :
_rightTensionBasisHat.derivative (dblPredictorOrdinate, iOrder);
return predictorOrdinate < following() ? _leftTensionBasisHat.derivative (predictorOrdinate, order) :
_rightTensionBasisHat.derivative (predictorOrdinate, order);
}

@Override public double integrate (
final double dblBegin,
final double dblEnd)
throws java.lang.Exception
final double begin,
final double end)
throws Exception
{
if (!org.drip.numerical.common.NumberUtil.IsValid (dblBegin) || !org.drip.numerical.common.NumberUtil.IsValid
(dblEnd))
throw new java.lang.Exception ("SegmentMonicBasisFunction::integrate => Invalid Inputs");

if (dblBegin >= dblEnd) return 0.;

if (dblBegin <= leading()) {
if (dblEnd <= leading()) return 0.;

if (dblEnd <= following()) return _leftTensionBasisHat.integrate (leading(), dblEnd);

if (dblEnd <= trailing())
return _leftTensionBasisHat.integrate (leading(), following()) + _rightTensionBasisHat.integrate (following(),
dblEnd);
if (!NumberUtil.IsValid (begin) || !NumberUtil.IsValid (end)) {
throw new Exception ("SegmentMonicBasisFunction::integrate => Invalid Inputs");
}

return _leftTensionBasisHat.integrate (leading(), following()) + _rightTensionBasisHat.integrate (following(),
trailing());
if (begin >= end) {
return 0.;
}

if (dblBegin <= following()) {
if (dblEnd <= following()) return _leftTensionBasisHat.integrate (dblBegin, dblEnd);
double leading = leading();

if (dblEnd <= trailing())
return _leftTensionBasisHat.integrate (dblBegin, following()) + _rightTensionBasisHat.integrate (following(),
dblEnd);
double trailing = trailing();

return _leftTensionBasisHat.integrate (dblBegin, following()) + _rightTensionBasisHat.integrate (following(),
trailing());
}
double following = following();

if (dblBegin <= trailing()) {
if (dblEnd <= trailing()) return _rightTensionBasisHat.integrate (following(), dblEnd);
if (begin <= leading) {
return end <= leading ? 0. :
_leftTensionBasisHat.integrate (leading, end <= following ? end : following) +
_rightTensionBasisHat.integrate (following, end <= trailing ? end : trailing);
}

return _rightTensionBasisHat.integrate (following(), trailing());
if (begin <= following) {
return _leftTensionBasisHat.integrate (begin, end <= following ? end : following) +
_rightTensionBasisHat.integrate (following, end <= trailing ? end : trailing);
}

return 0.;
return begin <= trailing ? 0. :
_rightTensionBasisHat.integrate (following, end <= trailing ? end : trailing);
}

@Override public double normalizer()
throws java.lang.Exception
throws Exception
{
return _leftTensionBasisHat.integrate (leading(), following()) + _rightTensionBasisHat.integrate (following(), trailing());
double following = following();

return _leftTensionBasisHat.integrate (leading(), following) +
_rightTensionBasisHat.integrate (following, trailing());
}

@Override public double normalizedCumulative (
final double dblPredictorOrdinate)
throws java.lang.Exception
final double predictorOrdinate)
throws Exception
{
if (!org.drip.numerical.common.NumberUtil.IsValid (dblPredictorOrdinate))
throw new java.lang.Exception
("SegmentMonicBasisFunction::normalizedCumulative => Invalid Inputs");
if (!NumberUtil.IsValid (predictorOrdinate)) {
throw new Exception ("SegmentMonicBasisFunction::normalizedCumulative => Invalid Inputs");
}

double leading = leading();

if (dblPredictorOrdinate <= leading()) return 0.;
double following = following();

if (dblPredictorOrdinate >= trailing()) return 1.;
if (predictorOrdinate <= leading) {
return 0.;
}

if (predictorOrdinate >= trailing()) {
return 1.;
}

if (dblPredictorOrdinate <= following())
return _leftTensionBasisHat.integrate (leading(), dblPredictorOrdinate) / normalizer();
double normalizer = normalizer();

return (_leftTensionBasisHat.integrate (leading(), following()) + _rightTensionBasisHat.integrate (following(),
dblPredictorOrdinate)) / normalizer();
return predictorOrdinate <= following ?
_leftTensionBasisHat.integrate (leading, predictorOrdinate) / normalizer : (
_leftTensionBasisHat.integrate (leading, following) +
_rightTensionBasisHat.integrate (following, predictorOrdinate)
) / normalizer;
}
}
Loading

0 comments on commit ca131b8

Please sign in to comment.