Internal Functions

Main Struct

SchumakerSpline.SchumakerType
Schumaker(x::Array{T,1},y::Array{T,1} ; gradients::Union{Missing,Array{T,1}} = missing, extrapolation::Schumaker_ExtrapolationSchemes = Curve,
              left_gradient::Union{Missing,T} = missing, right_gradient::Union{Missing,T} = missing)
Schumaker(x::Array{Int,1},y::Array{T,1} ; gradients::Union{Missing,Array{T,1}} = missing, extrapolation::Schumaker_ExtrapolationSchemes = Curve,
              left_gradient::Union{Missing,T} = missing, right_gradient::Union{Missing,T} = missing)
Schumaker(x::Array{Date,1},y::Array{T,1} ; gradients::Union{Missing,Array{T,1}} = missing, extrapolation::Schumaker_ExtrapolationSchemes = Curve,
              left_gradient::Union{Missing,T} = missing, right_gradient::Union{Missing,T} = missing)

Creates a Schumaker spline.

Inputs

  • x - A vector of x coordinates.
  • y - A vector of y coordinates.
  • extrapolation - This should be Curve, Linear or Constant specifying how to interpolate outside of the sample domain.
  • gradients - A vector of gradients at each point. If not supplied these are imputed from x and y.
  • left_gradient - The gradient at the lowest value of x in the domain. This will override the gradient imputed or submitted in the gradients optional argument (if it is submitted there)
  • right_gradient - The gradient at the highest value of x in the domain. This will override the gradient imputed or submitted in the gradients optional argument (if it is submitted there)

Returns

  • A Schumaker object which contains the spline. This object can then be evaluated with evaluate or evaluate_integral.
source
SchumakerSpline.evaluateFunction

Evaluates the spline at a point. The point can be specified as a Real number (Int, Float, etc) or a Date. Derivatives can also be taken.

Inputs

  • spline - A Schumaker type spline
  • PointToExamine - The point at which to evaluate the integral
  • derivative - The derivative being sought. This should be 0 to just evaluate the spline, 1 for the first derivative or 2 for a second derivative.

Higher derivatives are all zero (because it is a quadratic spline). Negative values do not give integrals. Use evaluate_integral instead.

Returns

  • A value of the spline or appropriate derivative in the same format as specified in the spline.
source
evaluate(spline::Schumaker2d, p1::Real, p2::Real)

Inputs

  • spline - A Schumaker2d
  • p1 - The coordinate in the first dimension.
  • p2 - The coordinate in the second dimension.

Returns

  • A scalar
source
SchumakerSpline.evaluate_integralFunction

Estimates the integral of the spline between lhs and rhs. These end points can be input as Reals or Dates.

Inputs

  • spline - A Schumaker type spline
  • lhs - The left hand limit of the integral
  • rhs - The right hand limit of the integral

Returns

  • A Float64 value of the integral.
source

Extrapolation Schemes

SchumakerSpline.Schumaker_ExtrapolationSchemesType

This creates an enum which details how extrapolation from the interpolation domain should be done. The possible enum values are:

  • Curve - Curve extrapolation extends out the quadratic form at the edges. This can lead to a nonmonotonic result (as the curve can eventually change direction)
  • Linear - Linear extrapolation extends out the gradient from at the edges. This will always lead to a monotonic result.
  • Constant - Linear extrapolation extends out the value from at the edges. This leads to flat values being extended out.
source

Working with Splines

SchumakerSpline.find_rootsFunction
find_roots(spline::Schumaker{T}; root_value::Real = 0.0, interval::Tuple{<:Real,<:Real} = (spline.IntStarts_[1], spline.IntStarts_[length(spline.IntStarts_)])) where T<:Real

Finds roots - This is handy because in many applications schumaker splines are monotonic and globally concave/convex and so it is easy to find roots. Here root_value can be set to get all points at which the function is equal to the root value. For instance if you want to find all points at which the spline has a value of 1.0.

Inputs

  • spline - The spline you want to find the roots for.
  • root_value - What level counts as a root.
  • interval - What interval to explore for roots.

Returns

  • A NamedTuple describing all roots found together with the derivatives and second derivatives at that point.
source
SchumakerSpline.find_optimaFunction
find_optima(spline::Schumaker)

Finds optima - This is handy because in many applications schumaker splines are monotonic and globally concave/convex and so it is easy to find optima.

Inputs

  • spline - The spline you want to find optima for.
  • interval - The interval over which you want to look for optima.

Returns

  • A NamedTuple containing the optima and the types of the optima (:Maximum or :Minimum)
source
SchumakerSpline.get_crossover_in_intervalFunction
get_crossover_in_interval(s1::Schumaker{T}, s2::Schumaker{R}, interval::Tuple{U,U}) where T<:Real where R<:Real where U<:Real

Finds the point at which two schumaker splines cross over each other within a single interval.

Inputs

  • s1 - The first spline
  • s2 - The second spline
  • interval - The interval you want to examine for crossovers.

Returns

  • A Vector describing crossover points.
source
SchumakerSpline.get_intersection_pointsFunction
get_intersection_points(s1::Schumaker{T}, s2::Schumaker{R}) where T<:Real where R<:Real

This funds the coordinates of the point at which spline s1 intercepts spline s2.

Inputs

  • s1 - The first spline
  • s2 - The second spline

Returns

  • Locations of any crossover points.
source
SchumakerSpline.reshape_valuesFunction
reshape_values(xvals::Vector{<:Real}, yvals::Vector{<:Real}; increasing::Bool = true,
                   concave::Bool = true, shape_map::Function = shape_map)

This reshapes a vector of yvalues. For instance if we are doing fixed point acceleration that should result in a monotonic concave function (ie the consumption smoothing problem from the documentation examples) then we may end up with occasional non monotonic/concave values due to a dodgy optimiser or some other numerical issue. So we can use reshape_values to adjust the values that cannot be true.

Inputs

  • xvals - A vector of x coordinates.
  • yvals - A vector of y coordinates
  • increasing - Should the y values be increasing. If false then they must be decreasing
  • concave - Should the y values be concave. If false then they must be convex
  • shape_map - A function used to adjust values to be increasing-concave (or whatever settings)

Returns

  • An updated vector of y values.
source
SchumakerSpline.splice_splinesFunction
splice_splines(left_spline::Schumaker, right_spline::Schumaker, splice_point::Real)

This puts two splines together. Making a new spline. Note that the stitched together spline is not guaranteed to be continuous or shape preserving anymore.

Inputs

  • left_spline - The spline to use on the left.
  • right_spline - The spline to use on the right.
  • splice_point - The x coordinate to stitch at.

Returns

  • A Schumaker struct
source

Two dimensional splines

SchumakerSpline.Schumaker2dType

This uses a combination of Schumaker Splines to cover a 2 dimensional space. We have a grid of splines. We first evaluate in one dimension (which leads us to a point between two adjacent splines). Then we evaluate each of the two splines and interpolate.

Members

  • IntStarts_ - A vector with the coordinates of each schumaker spline.
  • schumakers - A vector of schumaker splines.
source

Plotting of splines

RecipesBase.plotFunction
plot(s1::Schumaker, interval::Tuple{R,R} = (s1.IntStarts_[1], s1.IntStarts_[length(s1.IntStarts_)]); derivs::Bool = false, grid_len::Integer = 200, plot_options::NamedTuple = (label = "Spline",), deriv_plot_options::NamedTuple = (label = "Spline - 1st deriv",),
          deriv2_plot_options::NamedTuple = (label = "Spline - 2nd deriv",), plt = missing) where R<:Real
plot(s1::Schumaker, grid::AbstractArray{R,1}; derivs::Bool = false, plot_options::NamedTuple = (label = "Spline",), deriv_plot_options::NamedTuple = (label = "Spline - 1st deriv",),
          deriv2_plot_options::NamedTuple = (label = "Spline - 2nd deriv",), plt = missing) where R<:Real

Inputs

  • s1 - The Schumaker spline to chart
  • interval - The interval over which to chart it.
  • grid_len - The number of grid points to be used in plotting.
  • grid - The grid. If used this is instead of the interval and grid_len
  • derivs - Should the derivative splines also be plotted
  • plot_options - The options to use in plotting
  • deriv_plot_options - The options to use in the first derivative plot.
  • deriv2_plot_options- The options to use in the second derivative plot.
  • plt - A plot object. Feed this in if you want to add to a plot (rather than make a new one.)

Returns

  • A plot
source
plot(ss::Vector{Schumaker}, interval::Tuple{R,R} = (ss[1].IntStarts_[1], ss[1].IntStarts_[length(ss[1].IntStarts_)]); derivs::Bool = false, grid_len::Integer = 200, plot_options::Union{AbstractArray{Tuple,1},Missing} = missing,
     deriv_plot_options::Union{AbstractArray{Tuple,1},Missing} = missing, deriv2_plot_options::Union{AbstractArray{Tuple,1},Missing} = missing, plt = missing)  where R<:Real
plot(ss::Vector{Schumaker}, grid::Vector{R}; derivs::Bool = false, plot_options::Union{AbstractArray{Tuple,1},Missing} = missing, deriv_plot_options::Union{AbstractArray{Tuple,1},Missing} = missing,
     deriv2_plot_options::Union{AbstractArray{Tuple,1},Missing} = missing, plt = missing) where R<:Real

Inputs

  • ss - a vector of Schumaker splines to chart
  • interval - The interval over which to chart it.
  • grid_len - The number of grid points to be used in plotting.
  • grid - The grid. If used this is instead of the interval and grid_len
  • derivs - Should the derivative splines also be plotted
  • plot_options - The options to use in plotting
  • deriv_plot_options - The options to use in the first derivative plot.
  • deriv2_plot_options- The options to use in the second derivative plot.
  • plt - A plot object. Feed this in if you want to add to a plot (rather than make a new one.)

Returns

  • A plot
source