Propensity functions

NumCME.StandardTimeInvariantPropensityType
StandardTimeInvariantPropensity

Propensity function for a reaction with rate not dependent on time.

Examples

A standard time-invariant propensity can be created by wrapping around a Julia function. The function must accept two inputs x, p where x is the CME state vector and p is the vector of parameters.

julia> f(x, p) = p[1]*x[1]
f (generic function with 1 method)
julia> α = StandardTimeInvariantPropensity(f)
StandardTimeInvariantPropensity(f)
julia> α([1,2], [0.1,0.2])
0.1

One can also input f into the propensity() function. Provided that f is a function of two arguments with the CME state argument followed by the parameter argument, propensity() will output a standard time-invariant propensity. Continuing the example above,

julia> β = propensity(f)
StandardTimeInvariantPropensity(f)
julia> β([1,2], [0.1,0.2]) == α([1,2], [0.1,0.2])
true 

One can also take advantage of Julia's do block to make the code more concise.

julia> γ = propensity() do x,p
        x[1]*p[1]
    end 
julia> γ([1,2], [0.1,0.2])
0.1
source
NumCME.SeparableTimeVaryingPropensityType
SeparableTimeVaryingPropensity

Reaction propensity with a time-varying rate that can be factorized into a function that depends only on the time variable (and parameters) and another function that does not depend on time. Subsequent types that build upon this type (such as FspMatrixSparse) takes advantage of time-space separability to avoid repeating expensive computations.

Examples

A separable time-varying propensity can be created by specifying two Julia functions. The first function represents the time-varying factor and accepts two input arguments t (for time) and p (for parameters), the second function represents the time-invariant factor and accepts two input arguments x (for CME state) and p (for parameters).

julia> c(t,p) = (1.0+cos(π*t/p[2]))
c (generic function with 1 method)
julia> f(x, p) = p[1]*x[1]
f (generic function with 1 method)
julia> α = SeparableTimeVaryingPropensity(c,f)
SeparableTimeVaryingPropensity(c,f)
julia> α(20.0,[1,2], [0.1,0.2])
0.2

One can also use a method of the propensity() function to create a SeparableTimeVaryingPropensity instance. Provided that f is a function of two arguments with the CME state argument followed by the parameter argument, propensity(f,c) (note that the time-varying factor comes after the time-invariant factor) will output a standard time-invariant propensity. Continuing the example above,

julia> β = propensity(f,c)
SeparableTimeVaryingPropensity(f, c)
julia> β(20.0, [1,2], [0.1,0.2]) == α(20.0, [1,2], [0.1,0.2])
true 

One can also take advantage of Julia's do block to make the code more concise.

julia> γ = propensity((1.0+cos(π*t/p[2]))) do x,p
        x[1]*p[1]
    end 
julia> SeparableTimeVaryingPropensity(var"#19#21"(), var"#18#20"())
julia> γ(20.0, [1,2], [0.1,0.2])
0.2
source
NumCME.JointTimeVaryingPropensityType
JointTimeVaryingPropensity

Reaction propensity with a time-varying rate. For speed, we recommend using SeparableTimeVaryingPropensity if the propensity function has a separable structure.

Examples

A time-varying propensity can be created by wrapping a function with three input arguments, t (for time) x (for CME state) and p (for parameters).

julia> f(t, x, p) = (1.0+cos(π*t/p[2]))*p[1]*x[1]
f (generic function with 1 method)
julia> α = JointTimeVaryingPropensity(c,f)
JointTimeVaryingPropensity(c,f)
julia> α(20.0,[1,2], [0.1,0.2])
0.2

One can also use a method of the propensity() function to create a JointTimeVaryingPropensity instance. Provided that f is a function of three arguments with time as the first argument, the CME state as the second argument followed by the parameter argument.

julia> β = propensity(f)
julia> β(20.0, [1,2], [0.1,0.2]) == α(20.0, [1,2], [0.1,0.2])
true 
source