LinearSpline Module

Module to create linear splines from x,y coordinates. x,y coordinates are interpolated by straight lines between two knots.

Equivalent to interval-wise simple linear regression between any neighbouring pair of data.

Types

Type Description

LinearSplineCoef

Record type that contains the x-knots, intersects (C0) and slopes (C1) of each interval.

Functions and values

Function or value Description

differentiate lsc x

Full Usage: differentiate lsc x

Parameters:
    lsc : LinearSplineCoef - Linear spline coefficients given as input x values, intersects, and slopes.
    x : float - X value at which the corresponding slope should be predicted

Returns: float Slope of the function at the given x value.

Predicts the slope at point x. Since linear splines are lines between each pair of adjacend knots, the slope of the function within the interval of adjacent knots is constant.

X values that don't lie within the range of the input x values, are predicted using the nearest interpolation line!

lsc : LinearSplineCoef

Linear spline coefficients given as input x values, intersects, and slopes.

x : float

X value at which the corresponding slope should be predicted

Returns: float

Slope of the function at the given x value.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get slopes and intersects for interpolating straight lines
 let coefficients = 
     Interpolation.LinearSpline.initInterpolate xData yData 

 // get slope at 3.4
 Interpolation.LinearSpline.differentiate coefficients 3.4

interpolate xData yData

Full Usage: interpolate xData yData

Parameters:
    xData : float array - Collection of x values.
    yData : float array - Collection of y values.

Returns: LinearSplineCoef x-values, intersects, and slopes of interpolating lines

Returns the linear spline interpolation coefficients from unsorted x,y data.

Must not contain duplicate x values. Use Approximation.regularizeValues to preprocess data!

xData : float array

Collection of x values.

yData : float array

Collection of y values.

Returns: LinearSplineCoef

x-values, intersects, and slopes of interpolating lines

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get slopes and intersects for interpolating straight lines
 let coefficients = 
     Interpolation.LinearSpline.interpolate xData yData

interpolateInplace xData yData

Full Usage: interpolateInplace xData yData

Parameters:
    xData : float array - Collection of x values. May be modified when running this function!
    yData : float array - Collection of y values. May be modified when running this function!

Returns: LinearSplineCoef x-values, intersects, and slopes of interpolating lines

Returns the linear spline interpolation coefficients from unsorted x,y data. Works in place and modifies input sequences!

Works in place!Must not contain duplicate x values. Use Approximation.regularizeValues to preprocess data!

xData : float array

Collection of x values. May be modified when running this function!

yData : float array

Collection of y values. May be modified when running this function!

Returns: LinearSplineCoef

x-values, intersects, and slopes of interpolating lines

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get slopes and intersects for interpolating straight lines
 let coefficients = 
     Interpolation.LinearSpline.interpolateInplace xData yData

interpolateSorted xData yData

Full Usage: interpolateSorted xData yData

Parameters:
    xData : float array - Collection of ascending x values
    yData : float array - Collection of y values

Returns: LinearSplineCoef x-values, intersects, and slopes of interpolating lines

Returns the linear spline interpolation coefficients from x,y data that is sorted ascending according to x values.

The intersects (C0) correspond to the input y values.Must not contain duplicate x values. Use Approximation.regularizeValues to preprocess data!

xData : float array

Collection of ascending x values

yData : float array

Collection of y values

Returns: LinearSplineCoef

x-values, intersects, and slopes of interpolating lines

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;2.;3.;4.;5.;|]
 // some measured feature
 let yData = vector [|1.;5.;9.;13.;17.;18.;|]
 
 // get slopes and intersects for interpolating straight lines
 let coefficients = 
     Interpolation.LinearSpline.interpolateSorted xData yData

predict lsc x

Full Usage: predict lsc x

Parameters:
    lsc : LinearSplineCoef - Linear spline coefficients given as input x values, intersects, and slopes.
    x : float - X value at which the corresponding y value should be predicted

Returns: float Y value corresponding to the given x value.

Predicts the y value at point x. A straight line is fitted between the neighboring x values given.

X values that don't not lie within the range of the input x values, are predicted using the nearest interpolation line!

lsc : LinearSplineCoef

Linear spline coefficients given as input x values, intersects, and slopes.

x : float

X value at which the corresponding y value should be predicted

Returns: float

Y value corresponding to the given x value.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get slopes and intersects for interpolating straight lines
 let coefficients = 
     Interpolation.LinearSpline.initInterpolate xData yData 

 // get y value at 3.4
 Interpolation.LinearSpline.interpolate coefficients 3.4