Header menu logo bristlecone

ScriptNotebook

Integration Methods

Bristlecone supports model systems defined in discrete or continuous time. For continuous-time model systems - defined as ordinary differential equation(s) - Bristlecone applies numerical integration to calculate changes in the modelled properties through time.

Included integration methods

The following integration functions are included within the Bristlecone.Integration namespace:

Runge-Kutta 4

Bristlecone.Integration.RungeKutta.rk4

A fourth-order Runge Kutta method to provide approximate solutions to ODE systems.

Adding a custom integration method

You can add a custom integration routine by wrapping your integration function to match the EstimationEngine.Integration.IntegrationRoutine type signature as follows:

open Bristlecone

let myCustomIntegrator: EstimationEngine.Integration.IntegrationRoutine =
    fun tInitial tEnd tStep initialConditions (rhs:EstimationEngine.ParameterisedRHS) ->
        invalidOp "Doesn't actually do anything!"

let engine () =
    Bristlecone.mkContinuous () |> Bristlecone.withContinuousTime myCustomIntegrator

A custom integration routine is parameterised with fixed time-stepping between tInitial and tEnd, with tStep step size. The 'rhs' function to be integrated is a function compiled by Bristlecone that takes two arguments: first, a scalar of the current time t; and second a vector of the current state values.

Internally, if variable time-steps are required Bristlecone runs multiple fixed integration routines between each pair of time-points.

Multiple items
module Bristlecone from Bristlecone
<namespacedoc><summary>The core library of Bristlecone, containing model-fitting functions.</summary></namespacedoc>
Main functionality of Bristlecone, including functions to scaffold `ModelSystem`s and for model-fitting (tests and real fits).


--------------------
namespace Bristlecone
namespace Bristlecone.Integration
module RungeKutta from Bristlecone.Integration
val rk4: tInitial: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> tEnd: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> tStep: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> t0: CodedMap<Tensors.TypedTensor<Tensors.Scalar,ModelSystem.state>> -> rhs: EstimationEngine.ParameterisedRHS -> CodedMap<Tensors.TypedTensor<Tensors.Vector,ModelSystem.state>>
val myCustomIntegrator: tInitial: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> tEnd: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> tStep: Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> initialConditions: CodedMap<Tensors.TypedTensor<Tensors.Scalar,ModelSystem.state>> -> rhs: EstimationEngine.ParameterisedRHS -> CodedMap<Tensors.TypedTensor<Tensors.Vector,ModelSystem.state>>
module EstimationEngine from Bristlecone
<summary> The estimation engine represents the method used to calculate equations and optimise a likelihood function. The whole estimation engine is tensor-based internally, but may take float-based equations as a legacy option. </summary>
module Integration from Bristlecone.EstimationEngine
type IntegrationRoutine = Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> CodedMap<Tensors.TypedTensor<Tensors.Scalar,ModelSystem.state>> -> EstimationEngine.ParameterisedRHS -> CodedMap<Tensors.TypedTensor<Tensors.Vector,ModelSystem.state>>
<summary> Represents a low-level numerical method used to integrate functions. Takes the intial time, final time, and time step, and returns a function that is compiled to only require the current time and current state. Must return the baseline state plus evolutions. </summary>
val tInitial: Tensors.TypedTensor<Tensors.Scalar,Time.time index>
val tEnd: Tensors.TypedTensor<Tensors.Scalar,Time.time index>
val tStep: Tensors.TypedTensor<Tensors.Scalar,Time.time index>
val initialConditions: CodedMap<Tensors.TypedTensor<Tensors.Scalar,ModelSystem.state>>
val rhs: EstimationEngine.ParameterisedRHS
type ParameterisedRHS = Tensors.TypedTensor<Tensors.Scalar,Time.time index> -> Tensors.TypedTensor<Tensors.Vector,ModelSystem.state> -> CodedMap<Tensors.TypedTensor<Tensors.Scalar,ModelSystem.state/Time.time index>>
<summary> A parameterised RHS — parameters already bound. This is what the integration routine actually steps. </summary>
val invalidOp: message: string -> 'T
val engine: unit -> EstimationEngine.EstimationEngine<System.DateTime,System.TimeSpan,Time.year,'u>
val mkContinuous: unit -> EstimationEngine.EstimationEngine<System.DateTime,System.TimeSpan,Time.year,'u>
<summary>A basic estimation engine for ordinary differential equations, using a Nelder-Mead optimiser.</summary>
val withContinuousTime: t: EstimationEngine.Integration.IntegrationRoutine -> engine: EstimationEngine.EstimationEngine<'a,'b,'u,'v> -> EstimationEngine.EstimationEngine<'a,'b,'u,'v>
<summary> Use a custom integration method </summary>

Type something to start searching.