Skip to content

Internal Documentation ​

Documentation for ComposableRecurrences's internal interface.

Contents ​

Index ​

Internal API ​

ComposableRecurrences.ConvolutionMethod Type
julia
abstract type ConvolutionMethod

The method a Convolution uses to compute its lag sum

The methods are ComposableRecurrences.Direct (the default) and ComposableRecurrences.FFTMethod.

Examples

julia
using ComposableRecurrences
ComposableRecurrences.Direct() isa ComposableRecurrences.ConvolutionMethod

# output

true

Fields

source
ComposableRecurrences.Executor Type
julia
abstract type Executor

A strategy for how ComposableRecurrences.each! runs a loop over independent indices. Every executor e calls the same bodies, so the result does not depend on it:

Examples

julia
using ComposableRecurrences
ComposableRecurrences.Serial() isa ComposableRecurrences.Executor

# output

true

Fields

source
ComposableRecurrences.ExponentForm Type
julia
abstract type ExponentForm

The supertype of the depletion forms with a heterogeneity exponent : Hazard and Floor.


Fields

source
ComposableRecurrences.LagMap Type
julia
abstract type LagMap

The supertype of the maps of a computed kernel's weights over its lags: Increments and Normalised.


Fields

source
ComposableRecurrences.Local Type
julia
struct Local

The role of a map's local derivative at one entry: the partial derivatives of a Derived map or a ComposableRecurrences.Transform map at its arguments, given its value there.

For a map   of scalars, pullback!(grads, f, Local(), y, x...) returns the partial derivatives

one per argument and shaped as it is: a Transform map f(v, θ) with a tuple or NamedTuple θ returns (∂f/∂v, ∂f/∂θ), the second shaped as θ. y is the map's value there, from the forward pass. grads holds no cotangents for this role. The operators look for the method at the types of the arguments they pass, so it should accept any Real arguments. Without one the partials come from a local forward-mode derivative. The package's rules for min and max give the first argument the cotangent on a tie, so a tie can differ from ForwardDiff's convention, which also varies between its versions.

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
# A logistic hazard of the sum of its arguments, whose derivative reads its
# value.
struct LogisticSum end
(::LogisticSum)(a, b) = inv(1 + exp(-(a + b)))
function CR.pullback!(grads, ::LogisticSum, ::CR.Local, y, a, b)
    d = y * (1 - y)
    return d, d
end
h = CR.Derived(LogisticSum(), [-2.0, -1.0], 0.5)
cdf = TimeVarying(1 - CR.Survival(h), CR.Primary())
round.(CR.kernel_weights(cdf, 1); digits = 3)

# output

2×1 Matrix{Float64}:
 0.182
 0.491

Fields

source
ComposableRecurrences.Run Type
julia
struct Run

The role of an operator's whole call, forward(op, Run(), args...; kwargs...), which returns (y, cache); calling the operator lowers to it.

For inputs (the call's arguments and the operator's fields) it computes the output over the call's times  ,

with the maths of the operator, a Recurrence or a Convolution; cache holds what the reverse pass needs, such as the ComposableRecurrences.State. It is the role an operator is asked about, as in uses_adjoint(op, Run()) and PieceInterface with role = Run().

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
r = Recurrence([0.5, 0.5])
y, cache = CR.forward(r, CR.Run(), fill(1.1, 4); history = ones(2))
round.(y; digits = 3)

# output

4-element Vector{Float64}:
 1.1
 1.155
 1.24
 1.317

Fields

source
ComposableRecurrences.TRACED_MIN_STRATA Constant
julia
TRACED_MIN_STRATA

The fewest strata at which a loop of a traced call runs as one kernel.

A traced call runs each step's loop over S strata as one kernel when S is at least this, so its program does not grow with the strata. A shorter loop is written out, one block a stratum. Its program grows with S, but on the CPU its forward pass runs faster than a kernel launch each step. The default, 32, is measured on the CPU. From there a kernel runs gradients faster and compiles them faster, while a written-out loop still runs the forward pass faster. A model that mostly runs forward can raise it. On a GPU, where a launch costs less, a lower value may run faster. Set it with with, as for EXECUTOR.

Examples

julia
using ComposableRecurrences
using Base.ScopedValues: with
const CR = ComposableRecurrences
with(CR.TRACED_MIN_STRATA => 8) do
    CR.TRACED_MIN_STRATA[]
end

# output

8
source
ComposableRecurrences._add_hazard! Function
julia
_add_hazard!(h̄, h, sc, v, k, i, τ, l) -> Any

Add v to the cotangent of a Survival's hazard at an entry, from its kept partials where sc holds them.

source
ComposableRecurrences._add_table! Function
julia
_add_table!(t̄, _::AbstractMatrix, v, k, i, τ) -> Any

Add v to the cotangent t̄ of the entry of table t on lag index i of cohort τ, for stratum k where it has a strata axis.

source
ComposableRecurrences._add_value! Function
julia
_add_value!(x̄, x::Real, sc, v, k, i, τ, l, b) -> Any

Add v to the cotangent of a coefficient's value at an entry, through its mirror x̄; a Survival adds it to its scratch.

source
ComposableRecurrences._add_value_partials! Function
julia
_add_value_partials!(
    x̄,
    x::ComposableRecurrences.Derived{F, A},
    sc,
    v,
    ∂,
    k,
    i,
    τ,
    l,
    b
) -> Any

Add v times each partial in ∂ of a Derived map at an entry to the cotangent of its argument, through the mirror x̄.

source
ComposableRecurrences._alloc Function
julia
_alloc(_::Type{T}, dims::Int64...) -> Any

Return a scratch buffer of element type T and size dims, its entries written before they are read.

source
ComposableRecurrences._any_delays Function
julia
_any_delays(_::Type{Tuple{}}) -> Bool

Return whether any kernel type in tuple type G holds delays.

source
ComposableRecurrences._applied Function
julia
_applied(lin, gain, at, v, ρ, L) -> Any

Return M(ρ) v, from a step from the exponential history of v.

source
ComposableRecurrences._array Function
julia
_array(x::AbstractArray) -> AbstractArray

Return the array under any wrappers.

source
ComposableRecurrences._back_block! Function
julia
_back_block!(x̄, x, sc, W̄, τ0, nb, o, last)

Take the block's weight cotangents W̄ back to the mirror x̄ of coefficient x.

source
ComposableRecurrences._back_scratch Function
julia
_back_scratch(sc) -> Any

Return scratch sc for the reverse pass, with its cotangents allocated and its values and hazards shared.

source
ComposableRecurrences._block! Function
julia
_block!(x, sc, τ0, nb, o, last)

Fill the scratch sc of every Survival and lag map in x for the nb cohorts from τ0, inner ones first.

source
ComposableRecurrences._block_args! Function
julia
_block_args!(_::Tuple{}, _::Tuple{}, τ0, nb, o, last)

Fill the scratch of each argument in args, with its scratch in sc, for the block.

source
ComposableRecurrences._block_back! Function
julia
_block_back!(x̄, x, sc, τ0, nb, o, last)

Take the cotangents in scratch sc of the block's values back to the mirror x̄ of coefficient x, clearing them for the next block.

source
ComposableRecurrences._block_back_args! Function
julia
_block_back_args!(
    _::Tuple{},
    _::Tuple{},
    _::Tuple{},
    τ0,
    nb,
    o,
    last
)

Take each argument's cotangents in its scratch in sc back to its mirror in ā, for the block.

source
ComposableRecurrences._block_size Function
julia
_block_size(x, n, _::Val{keep}) -> Any

Return the cohorts per block: all n when keep, the run's cache flag, is true or :traced and x keeps its fill, else _BLOCK.

source
ComposableRecurrences._bmax Function
julia
_bmax(τ0, nb, i, o, last) -> Any

Return how many of the nb cohorts from τ0, the first ones, have their weight on lag index i (lags from o) land by last.

source
ComposableRecurrences._chain_masses Function
julia
_chain_masses(ms::Tuple{Any}, lags) -> Any

Return the first lags masses of the convolution of the masses ms of a chain's links.

source
ComposableRecurrences._check_argument Function
julia
_check_argument(
    x::Union{ComposableRecurrences.LagMap, Real, ComposableRecurrences.Derived, PerStratum{<:AbstractVecOrMat{<:Number}}, ComposableRecurrences.Survival, TimeVarying{<:Any, <:Union{PerStratum{<:AbstractMatrix{<:Number}}, ComposableRecurrences._Piecewise{<:Union{PerStratum{<:AbstractMatrix{<:Number}}, AbstractVector{<:Number}}}, AbstractVector{<:Number}}}, AbstractVector{<:Number}}
)

Check x as an argument of a Derived: a kernel coefficient, or else a modifier parameter.

source
ComposableRecurrences._check_coef_times Function
julia
_check_coef_times(x, n, last)

Check that each time-varying coefficient in x covers the cohorts up to n and the times up to last that the weights read.

source
ComposableRecurrences._check_coefficient Function
julia
_check_coefficient(
    x::Union{PerStratum{<:AbstractVecOrMat{<:Number}}, TimeVarying{<:Any, <:Union{PerStratum{<:AbstractMatrix{<:Number}}, ComposableRecurrences._Piecewise{<:Union{PerStratum{<:AbstractMatrix{<:Number}}, AbstractVector{<:Number}}}, AbstractVector{<:Number}}}, AbstractVector{<:Number}}
)

Throw an error unless x is a coefficient a computed kernel reads, with real entries and one-based axes for an array.

source
ComposableRecurrences._check_kernel_args Function
julia
_check_kernel_args(x)

Check that every argument of computed kernel x is a coefficient it reads.

source
ComposableRecurrences._check_lag_map Function
julia
_check_lag_map(x)

Throw an error unless x is a computed kernel, or a kernel's weights with real entries, which are what a lag map takes.

source
ComposableRecurrences._check_lag_times Function
julia
_check_lag_times(x, n, o)

Check that the coefficients a total in x reads cover every lag of each cohort: for lags from o, the times up to n + L - 1 + o.

source
ComposableRecurrences._check_lags Function
julia
_check_lags(lags, origin)

Throw an error unless lags is an integer above origin, the first lag of the operator's kernel.

source
ComposableRecurrences._check_no_delays Function
julia
_check_no_delays(kernel)

Throw an error when kernel holds delays, since they need lags to become masses.

source
ComposableRecurrences._check_no_step Function
julia
_check_no_step(width)

Throw an error unless width is one, since it has meaning only where lags turns delays into masses.

source
ComposableRecurrences._check_reversed_record Function
julia
_check_reversed_record(_::Val{false})

Throw an ArgumentError when a reversed call's record asks for Resume().

source
ComposableRecurrences._check_reversed_tail Function
julia
_check_reversed_tail(kernel, tail)

Throw an ArgumentError when a Primary() kernel is given a tail.

source
ComposableRecurrences._check_route_kernel Function
julia
_check_route_kernel(g)

Check a route's kernel g, which may hold delays until the operator is built with lags, and reject routes given as a kernel.

source
ComposableRecurrences._check_step Function
julia
_check_step(width)

Throw an error unless width, the width of a lag in a delay's own unit, is a positive number.

source
ComposableRecurrences._check_transpose Function
julia
_check_transpose(
    kernel,
    x,
    tail,
    start,
    stop
) -> NTuple{5, Any}

Check a transposed call's arguments and return the buffer eltype, the strata, the series length, the last output time and the last series time read.

source
ComposableRecurrences._check_transposed_times Function
julia
_check_transposed_times(kernel, stop, last) -> Any

Check that the kernel has a column for every time a transposed call reads.

source
ComposableRecurrences._coef_array Function
julia
_coef_array(x) -> AbstractArray

Return the first array coefficient x reads, or nothing; on a device, the weights and the walks' scratch are allocated like it.

source
ComposableRecurrences._coef_lags Function
julia
_coef_lags(x) -> Any

Return the number of lags coefficient x sets, 0 for none.

source
ComposableRecurrences._coef_strata Function
julia
_coef_strata(x) -> Any

Return the number of strata coefficient x sets, 0 for none.

source
ComposableRecurrences._coefficient_error Function
julia
_coefficient_error(x)

Throw the error that x is not a coefficient a computed kernel reads.

source
ComposableRecurrences._cohort_item Function
julia
_cohort_item(j, nk) -> Tuple{Any, Any}

Return stratum k and cohort τ of item j, with nk strata per cohort.

source
ComposableRecurrences._colrange Function
julia
_colrange(g::ComposableRecurrences._Ragged, τ) -> Any

Return the range of g.values that holds column τ.

source
ComposableRecurrences._column_eltype Function
julia
_column_eltype(ks) -> Any

Return the eltype of the columns ks, promoted over them when their type is not concrete.

source
ComposableRecurrences._column_mirror Function
julia
_column_mirror(
    m,
    g::ComposableRecurrences._Ragged,
    τ
) -> Any

Return column τ of the mirror m of a column-form kernel's storage, or nothing without one.

source
ComposableRecurrences._colview Function
julia
_colview(g::ComposableRecurrences._Ragged, τ) -> Any

Return column τ of a column-form kernel.

source
ComposableRecurrences._continuous_masses Function
julia
_continuous_masses(d, lags; kwargs...) -> Any

Return the masses of continuous delay d, which an extension that makes the censoring choice provides; until it loads, throw an error.

source
ComposableRecurrences._convolve_masses Function
julia
_convolve_masses(a, b, lags) -> Any

Return the full linear convolution of a and b on lags 0 to lags - 1, taking only the products of entries that both exist.

source
ComposableRecurrences._convolve_masses! Function
julia
_convolve_masses!(
    c::AbstractVector{<:Union{Float16, Float32, Float64}},
    a,
    b
) -> AbstractVector{<:Union{Float16, Float32, Float64}}

Add the linear convolution of a and b on the lags of c into c and return it.

source
ComposableRecurrences._convolve_masses_back! Function
julia
_convolve_masses_back!(ā, b̄, c̄, a, b)

Add the cotangents of a and b from the cotangent c̄ of their convolution into ā and b̄, either of which may be nothing, leaving c̄ unchanged.

source
ComposableRecurrences._copy_time! Function
julia
_copy_time!(D::AbstractVector, t, V, j)

Copy the value of segment j of V into time t of the dense coefficient D.

source
ComposableRecurrences._correlate_masses! Function
julia
_correlate_masses!(x̄, c̄, y) -> Any

Add the correlation of the cotangent c̄ with y into x̄, the cotangent of the convolution's other factor, and return x̄.

source
ComposableRecurrences._cotangent_column Function
julia
_cotangent_column(P::AbstractVector, j) -> AbstractVector

Return column j of the cotangent buffer P, or P when it has one column.

source
ComposableRecurrences._cut Function
julia
_cut(a, lags) -> Any

Return the masses of a on lags 0 to lags - 1, with zeros past its end.

source
ComposableRecurrences._delay_kernel Function
julia
_delay_kernel(kernel, lags, origin, width) -> Any

Return kernel with its delays turned into masses from lag origin, throwing an error for a bad lags or width or a kernel with no delays.

source
ComposableRecurrences._dense_coef Function
julia
_dense_coef(x, last) -> ComposableRecurrences.Survival

Return coefficient x with any change points made dense over the times 1:last.

source
ComposableRecurrences._dense_kernel Function
julia
_dense_kernel(
    K::AbstractMatrix
) -> TimeVarying{ComposableRecurrences.Primary, A} where A<:(AbstractMatrix)

Return the dense kernel of weights array K.

source
ComposableRecurrences._dense_mirror Function
julia
_dense_mirror(_::Nothing)

Return the mirror of a dense kernel from the cotangent K̄ of its weights array.

source
ComposableRecurrences._dense_mirror_of Function
julia
_dense_mirror_of(
    x̄,
    x,
    last
) -> Union{Nothing, NamedTuple{(:hazard,), <:Tuple{Any}}}

Return the mirror of coefficient x made dense over the times 1:last, from its mirror x̄.

source
ComposableRecurrences._dense_walk_back! Function
julia
_dense_walk_back!(x̄, x, K̄, o, last, sc)

Take the cotangent K̄ of the weights back to the mirror x̄ of coefficients x with change points made dense.

source
ComposableRecurrences._dense_weights_back! Function
julia
_dense_weights_back!(x̄, x, K̄, o, last, sc)

Take the cotangent K̄ of the weights back to the mirror x̄ of coefficients x with change points made dense, with the forward scratch sc.

source
ComposableRecurrences._densified Function
julia
_densified(
    k::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    last
) -> TimeVarying{ComposableRecurrences.Primary}

Return computed kernel k with its coefficients given by change points made dense over the times 1:last, or k when it has none.

source
ComposableRecurrences._densified_mirror Function
julia
_densified_mirror(
    x̄,
    k::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    last
) -> Any

Return the mirror of the dense coefficients from the mirror x̄ of the kernel's coefficients: a zero array for each made dense, and the coefficient's own mirror elsewhere.

source
ComposableRecurrences._device_fill Function
julia
_device_fill(
    x,
    like,
    _::Type{Tp},
    ns,
    L,
    n,
    o,
    last
) -> Tuple{Any, Nothing}

Return the weights of coefficients x, filled on the device of array like, and no scratch.

source
ComposableRecurrences._device_ints Function
julia
_device_ints(like, v) -> Any

Return the integers v copied into an array on the device of like.

source
ComposableRecurrences._device_lag_map_error Function
julia
_device_lag_map_error()

Throw the error that a kernel with a lag map fills only on the host.

source
ComposableRecurrences._device_route_kernels Function
julia
_device_route_kernels(_::Tuple{}) -> Bool

Return whether every route kernel in gs is a fixed kernel.

source
ComposableRecurrences._device_routes Function
julia
_device_routes(_::Tuple{}) -> Bool

Return whether every route coupling in Cs is a matrix on the device.

source
ComposableRecurrences._device_walk_scratch Function
julia
_device_walk_scratch(x, _::Type, L, m, like) -> Any

Return the walk scratch for m blocks of walks of L lags on the device of array like, or nothing where x holds no Survival.

source
ComposableRecurrences._device_weights_back! Function
julia
_device_weights_back!(x̄, x, K̄, o, last)

Take the cotangent K̄ of the weights back to the mirror x̄ on the device, walking each cohort again in blocks.

source
ComposableRecurrences._device_window_sums Function
julia
_device_window_sums(
    op::ComposableRecurrences._WindowSums,
    lo,
    hi,
    x
) -> Any

Return the window sums of x on its device, one kernel index per sum.

source
ComposableRecurrences._device_window_sums_back! Function
julia
_device_window_sums_back!(
    x̄,
    op::ComposableRecurrences._WindowSums,
    lo,
    hi,
    ȳ
) -> Any

Add each window's cotangent to x̄ on its device, one kernel index per time.

source
ComposableRecurrences._discounted Function
julia
_discounted(
    lin,
    gain,
    at,
    v::Number,
    ρ,
    L
) -> Tuple{Any, Any}

Return M(ρ) v and -M'(ρ) v from two steps at time at: one from the history v exp(ρ (l - L)) and one from that history times its lags.

source
ComposableRecurrences._discounted_column Function
julia
_discounted_column(lin, gain, at, ρ, L, S, j) -> Any

Return column j of M(ρ), from a step from stratum j's unit profile.

source
ComposableRecurrences._discounted_matrix Function
julia
_discounted_matrix(
    lin,
    gain,
    at,
    ρ,
    L::Integer,
    S::Integer
) -> Any

Return the matrix M(ρ), a column per stratum's unit profile.

source
ComposableRecurrences._dominant Function
julia
_dominant(M) -> Tuple{Any, Any, Any}
_dominant(M, tol) -> Tuple{Any, Any, Any}

Return the largest eigenvalue of a non-negative matrix whose strata all reach each other, with its right and left vectors, each summing to one.

source
ComposableRecurrences._each_segment Function
julia
_each_segment(f, p::ComposableRecurrences._Piecewise, n)

Call f(t, j) for each time t in 1:n and its segment j of change points p.

source
ComposableRecurrences._eigen_jacobian Function
julia
_eigen_jacobian(
    lin,
    gain,
    at,
    ρ,
    L,
    S
) -> Tuple{Any, Any, Any}
_eigen_jacobian(
    lin,
    gain,
    at,
    ρ,
    L,
    S,
    v
) -> Tuple{Any, Any, Any}

Return ρ, the profile at ρ unless given, and the inverse Jacobian of F there.

source
ComposableRecurrences._eigen_step Function
julia
_eigen_step(x, lin, gain, at, L, S) -> Tuple{Any, Any}

Return the next Newton iterate of the rate on log λ(ρ) from x, for strata that mix.

source
ComposableRecurrences._fill_block! Function
julia
_fill_block!(W, x, sc, τ0, nb, o, last) -> Any

Fill the block's weights into W (cohorts × lags × strata) and return W.

source
ComposableRecurrences._fill_cohort! Function
julia
_fill_cohort!(j, K, x, o, last, nk)

Fill the weights in K of item j, one stratum of one cohort, by walking its lags.

source
ComposableRecurrences._fill_kernel Function
julia
_fill_kernel(
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    o,
    n,
    last
) -> Tuple{Any, Any}
_fill_kernel(
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    o,
    n,
    last,
    keep::Val
) -> Tuple{Any, Any}

Return the weights of kernel for n cohorts, lags from o and times up to last, with the scratch its reverse pass reads.

source
ComposableRecurrences._first_array Function
julia
_first_array(_::Tuple{})

Return the first entry of tuple a that is not nothing, or nothing when there is none.

source
ComposableRecurrences._first_mirror Function
julia
_first_mirror(_::Nothing)

Return the first of the argument mirrors ā, or nothing when there are none.

source
ComposableRecurrences._fixed Function
julia
_fixed(x::Number) -> Any

Return the value of x with no derivative.

source
ComposableRecurrences._flip Function
julia
_flip(
    x::Union{Nothing, AbstractString, Function, Number, Symbol, Val, AbstractArray, Type, LinearAlgebra.UniformScaling},
    w
) -> Union{Nothing, AbstractString, Function, Number, Symbol, Val, AbstractArray, Type, LinearAlgebra.UniformScaling}

Return x with every TimeVarying array it holds read at its columns w, last first.

source
ComposableRecurrences._flip_array Function
julia
_flip_array(A::AbstractArray, w) -> Any

Return the columns w of an array over time, last first, all of them when w is left out.

source
ComposableRecurrences._flip_input Function
julia
_flip_input(x::AbstractVecOrMat, w) -> Any

Return a call's gain or add on the reversed axis: an array is over time, and anything else is a parameter, read as the operator's are.

source
ComposableRecurrences._flip_tail Function
julia
_flip_tail(
    tail::Union{Nothing, Number}
) -> Union{Nothing, Number}

Return the outputs after stop, nearest last, as the history of the run.

source
ComposableRecurrences._fold! Function
julia
_fold!(x̄, x, x̄d) -> Any

Sum the dense cotangents x̄d of coefficient x onto the mirrors x̄ of its values given by change points.

source
ComposableRecurrences._fold_dense! Function
julia
_fold_dense!(
    x̄,
    k::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    x̄d
)

Sum each dense cotangent in x̄d onto the value of its time's segment in the mirror x̄.

source
ComposableRecurrences._fold_one Function
julia
_fold_one(C, g, R, J) -> Tuple{Any, Any}

Return a lone route's kernel g and coupling C, or (R, J) when g is itself pairwise.

source
ComposableRecurrences._fold_routes Function
julia
_fold_routes(
    Cs,
    gs,
    R,
    J
) -> Tuple{AbstractVector, LinearAlgebra.UniformScaling}

Return the kernel and coupling that routes with couplings Cs and kernels gs fold to, or (R, J) when they do not fold.

source
ComposableRecurrences._fold_values! Function
julia
_fold_values!(V̄, D̄::AbstractVector, p)

Add each time's dense cotangent in D̄ to the cotangent V̄ of its segment's value in change points p.

source
ComposableRecurrences._gather_outputs! Function
julia
_gather_outputs!(_::Nothing, H̄, D)

Add the cotangents of the buffer rows after the history to the outputs' cotangent ȳ.

source
ComposableRecurrences._growth Function
julia
_growth(
    _::Type,
    lin,
    gain,
    at
) -> NamedTuple{(:rate, :profile), <:Tuple{Any, Any}}

Return the rate and profile of growth for the linear recurrence lin.

source
ComposableRecurrences._growth_core Function
julia
_growth_core(
    r::Recurrence{<:Any, <:Any, Tuple{}}
) -> Recurrence{<:Any, <:Any, Tuple{}}

Return the recurrence with the kernel and coupling of r and no modifiers.

source
ComposableRecurrences._growth_float Function
julia
_growth_float(lin, xs...) -> Any

Return the float type of the parameters of the kernel, coupling and xs.

source
ComposableRecurrences._growth_gain Function
julia
_growth_gain(
    _::Val{false},
    _::Val{false},
    lin,
    rate,
    at
) -> Any

Return the scale of the gain at which lin grows at rate, as growth_gain does.

source
ComposableRecurrences._growth_root Function
julia
_growth_root(
    _::Val{false},
    stratified,
    lin,
    gain,
    at
) -> Any

Return the root rate with no derivative, and for strata that mix also its profile and the inverse Jacobian there.

source
ComposableRecurrences._growth_solve Function
julia
_growth_solve(
    lin,
    gain,
    at
) -> NamedTuple{(:rate, :profile), <:Tuple{Any, Any}}

Return the rate and profile: the root found with no derivative, then one Newton step from it.

source
ComposableRecurrences._growth_start Function
julia
_growth_start(lin, gain, at, v, L) -> Any

Return where Newton starts: the first step from zero, which for one series with a kernel vector is log(γ Σ g) / l̄ and needs no exponential.

source
ComposableRecurrences._growth_step Function
julia
_growth_step(
    _::Val{false},
    _::Val{false},
    lin,
    gain,
    at,
    ρ
) -> NamedTuple{(:rate, :profile), <:Tuple{Any, Bool}}

Return (; rate, profile) after one Newton step from the root ρ, which carries the derivative.

source
ComposableRecurrences._growth_strata Function
julia
_growth_strata(r::Recurrence, xs...) -> Any

Return the number of strata, from the first of xs, the kernel and the coupling that has a row per stratum.

source
ComposableRecurrences._growth_tol Function
julia
_growth_tol(ρ) -> Any

Return the tolerance of the root, the square root of the precision of the float type of ρ.

source
ComposableRecurrences._has_delays Function
julia
_has_delays(_::Type{T}) -> Bool

Return whether a kernel of type T holds delays.

source
ComposableRecurrences._has_pieces Function
julia
_has_pieces(x) -> Any

Return whether coefficient x holds a coefficient given by change points, fixed at compile time from its type.

source
ComposableRecurrences._has_strata Function
julia
_has_strata(x) -> Val{true}

Return whether x has a row per stratum, as a Val read from its type.

source
ComposableRecurrences._hazard_partials Function
julia
_hazard_partials(h, _::Type, dims, keep) -> Any

Return an array of size dims that keeps the partials of a costly hazard map h when every walk is kept, else nothing.

source
ComposableRecurrences._history_lags Function
julia
_history_lags(L) -> Any

Return the lag each column of an L-step history holds at the step after it.

source
ComposableRecurrences._imax Function
julia
_imax(τ, L, o, last) -> Any

Return the last lag index of cohort τ whose weight lands by last, for lags from o.

source
ComposableRecurrences._in_time_order Function
julia
_in_time_order(y::AbstractArray) -> Any

Return the outputs of a reversed run, or a tuple or named tuple of them, in time order.

source
ComposableRecurrences._increments_axpy! Function
julia
_increments_axpy!(Y, k, r, t, k0, τ, i0, imax, a) -> Any

Add u_i a to Y[r + i, k] over lag indices i0:imax, with u the increments of table t for cohort τ, and return Y.

source
ComposableRecurrences._increments_dot Function
julia
_increments_dot(t, k0, τ, i0, imax, Ȳ, k, r) -> Any

Return Σ_i u_i Ȳ[r + i, k] over lag indices i0:imax, with u the increments of table t for cohort τ.

source
ComposableRecurrences._inner_last Function
julia
_inner_last(
    _::ComposableRecurrences.Increments,
    τ0,
    nb,
    L,
    o,
    last
) -> Any

Return the last time lag map x reads the kernel inside at for the nb cohorts from τ0.

source
ComposableRecurrences._inner_span Function
julia
_inner_span(
    _::ComposableRecurrences.Increments,
    last
) -> Any

Return the last time lag map x reads the kernel inside at: a total reads every lag of the last cohort, one step on for a recurrence's offset.

source
ComposableRecurrences._inverse Function
julia
_inverse(J) -> Any

Return the inverse of J, or NaN entries when J is not finite, where a factorisation would throw.

source
ComposableRecurrences._is_masses Function
julia
_is_masses(_::Type{H}) -> Bool

Return whether a link of type H is a vector of masses: a vector of real numbers, or of a number type that stands for one and adds a method.

source
ComposableRecurrences._isdelay Function
julia
_isdelay(_::Type{T}) -> Bool

Return whether type T is a delay: not an array, and with a delay_masses method.

source
ComposableRecurrences._iterate_until Function
julia
_iterate_until(
    step,
    done,
    x::Tuple,
    n::Integer,
    args...
) -> Tuple{Any, Bool}

Apply x ← step(x, args...) until done(x, args...), at most n times, and return x and whether it was done.

source
ComposableRecurrences._joined Function
julia
_joined(f, _::Tuple{}, what) -> Int64

Return the count that f gives the arguments args of a Derived, throwing an error when two nonzero counts of what differ.

source
ComposableRecurrences._keeps_fill Function
julia
_keeps_fill(x) -> Any

Return whether the fill of coefficient x is kept for the reverse pass, a costly map without a lag map, fixed at compile time from its type.

source
ComposableRecurrences._keeps_fill_type Function
julia
_keeps_fill_type(_::Type) -> Union{Missing, Bool}

Return whether a coefficient of type T has a map other than +, -, * and /, from the type.

source
ComposableRecurrences._lag_axis Function
julia
_lag_axis(W::AbstractArray{<:Any, 3}) -> Any

Return the lag axis of a block of weights W.

source
ComposableRecurrences._lag_map! Function
julia
_lag_map!(
    w,
    _::ComposableRecurrences.Increments,
    u,
    n
) -> Any

Write the weights of lags 1:n from the values u of the kernel inside the lag map into w and return w.

source
ComposableRecurrences._lag_map_back! Function
julia
_lag_map_back!(
    ū,
    _::ComposableRecurrences.Increments,
    w̄,
    u,
    n
) -> Any

Write the cotangents ū of the values inside from the cotangents w̄ of the weights, where ū may be w̄, and return ū.

source
ComposableRecurrences._lag_mapped Function
julia
_lag_mapped(x) -> Any

Return whether coefficient x holds a lag map, fixed at compile time from its type.

source
ComposableRecurrences._lag_mapped_type Function
julia
_lag_mapped_type(_::Type) -> Bool

Return whether a coefficient of type T holds a lag map, from the type.

source
ComposableRecurrences._lag_sums Function
julia
_lag_sums(k::AbstractVector, ρ, j) -> Tuple{Any, Any}

Return the sum of stratum j's kernel discounted at ρ, and the same weighted by its lags.

source
ComposableRecurrences._lagged Function
julia
_lagged(lin, gain, at, v, ρ, L) -> Any

Return -M'(ρ) v, from a step from the exponential history of v times its lags.

source
ComposableRecurrences._largest_change Function
julia
_largest_change(w, v) -> Any

Return the largest change between the values of v and w, with no derivative.

source
ComposableRecurrences._link_masses Function
julia
_link_masses(
    k::AbstractVector,
    lags,
    width
) -> AbstractVector

Return the masses of chain link d: a vector as it is, whatever its length, or a delay's masses, checked to have lags entries.

source
ComposableRecurrences._links Function
julia
_links(_::Type{Tuple{}}) -> Bool

Return whether each link of tuple type T is a vector of masses or a delay.

source
ComposableRecurrences._load_outputs! Function
julia
_load_outputs!(
    H,
    y::AbstractVector,
    D
) -> GPUArraysCore.AnyGPUArray

Write the outputs y into the buffer rows after the history.

source
ComposableRecurrences._log_step Function
julia
_log_step(m, d) -> Any

Return the Newton step log(m) m / d without checking that m has a logarithm.

source
ComposableRecurrences._map_lags Function
julia
_map_lags(
    _::ComposableRecurrences.Increments,
    τ,
    L,
    o,
    last
) -> Any

Return how many lags of cohort τ lag map x reads: those whose weights land by last, or every lag for a total.

source
ComposableRecurrences._masses Function
julia
_masses(d, grid, origin) -> Any

Return the masses of d from lag origin, on the grid.lags lags of grid.width units each.

source
ComposableRecurrences._masses_kernel Function
julia
_masses_kernel(x, grid, origin) -> Any

Return kernel x with any delays it holds turned into masses from lag origin on grid.

source
ComposableRecurrences._maxlen Function
julia
_maxlen(g::ComposableRecurrences._Ragged) -> Any

Return the length of the longest column of a column-form kernel.

source
ComposableRecurrences._mirror_at Function
julia
_mirror_at(_::Nothing, τ)

Return entry τ of the mirror m, or nothing without one.

source
ComposableRecurrences._mixes Function
julia
_mixes(r::Recurrence) -> Union{Val{true}, Val{false}}

Return whether strata mix, as a Val read from the types.

source
ComposableRecurrences._nan_like Function
julia
_nan_like(x::Number) -> Any

Return a NaN of the float type of the value of x, or an array of them.

source
ComposableRecurrences._ncols Function
julia
_ncols(g::ComposableRecurrences._Ragged) -> Any

Return the number of columns of a column-form kernel.

source
ComposableRecurrences._nested_time_error Function
julia
_nested_time_error(x)

Throw the ArgumentError for a TimeVarying that wraps another.

source
ComposableRecurrences._newton_iterate Function
julia
_newton_iterate(ρ::Number, m, d) -> Tuple{Any, Any}

Return the Newton iterate (ρ + Δ, Δ) from ρ, for one series or per stratum.

source
ComposableRecurrences._newton_pair Function
julia
_newton_pair(Jinv, r) -> Any

Return the Newton step J⁻¹ F on F = (r, 0).

source
ComposableRecurrences._newton_step Function
julia
_newton_step(m::Real, d::Real) -> Any

Return the Newton step on log m(ρ) from m and d = -m'(ρ): NaN where m has no logarithm, which ends the solve as a settled step does.

source
ComposableRecurrences._no_censoring Function
julia
_no_censoring(d)

Throw the error that continuous delay d has no masses on whole lags until a censoring choice discretises it.

source
ComposableRecurrences._no_record Function
julia
_no_record(sc) -> Any

Return scratch sc with each Survival's part replaced by one that records nothing.

source
ComposableRecurrences._no_walk Function
julia
_no_walk(x) -> Any

Return the scratch of a walk that records nothing, built inside a kernel.

source
ComposableRecurrences._over_time Function
julia
_over_time(x) -> Bool

Return whether TimeVarying can wrap x.

source
ComposableRecurrences._over_time_error Function
julia
_over_time_error(x)

Throw the ArgumentError for a value TimeVarying cannot wrap.

source
ComposableRecurrences._padded Function
julia
_padded(x, tail, N) -> Any

Return the series and tail joined, with zeros after them up to time N.

source
ComposableRecurrences._pairwise_piecewise Function
julia
_pairwise_piecewise(x)

Throw the ArgumentError for Pairwise values given as change points.

source
ComposableRecurrences._partials_column Function
julia
_partials_column(_::Nothing, j)

Return column j of the kept partials D, or nothing when none are kept.

source
ComposableRecurrences._pieces_type Function
julia
_pieces_type(_::Type) -> Bool

Return whether a coefficient of type T holds a coefficient given by change points, from the type.

source
ComposableRecurrences._piecewise Function
julia
_piecewise(
    ps::AbstractVector{<:Pair}
) -> ComposableRecurrences._Piecewise{_A, Vector{Int64}} where _A

Return a _Piecewise of the values of start => value change points stacked along a new last axis, kernels of different lengths padded with zero weights.

source
ComposableRecurrences._power_settled Function
julia
_power_settled(x, tol) -> Any

Return whether the row sums of the power iterate x moved by at most tol.

source
ComposableRecurrences._power_step Function
julia
_power_step(x, tol) -> Tuple{Any, Any, Any}

Return the next power iterate, the square of the power in x rescaled.

source
ComposableRecurrences._pressure Function
julia
_pressure(r::Recurrence, route, y; history, start) -> Any

Check the arguments of pressure and compute it with _Pressure, taking the rule as route does.

source
ComposableRecurrences._pressure_forward Function
julia
_pressure_forward(
    r,
    y,
    h,
    τ0,
    keep::Val
) -> Tuple{Any, Union{Nothing, NamedTuple{(:H, :P, :kernel, :h, :τ0, :L, :D, :S, :T), <:Tuple{Any, Any, Any, AbstractVector, Vararg{Any, 5}}}, NamedTuple{(:H, :P, :kernel, :h, :τ0, :L, :D, :S, :T), <:Tuple{Any, Any, Any, AbstractMatrix, Vararg{Any, 5}}}}}

Return the pressure of the outputs y after the history h from time τ0, with what the reverse pass needs when keep is Val(true).

source
ComposableRecurrences._pressure_kernel Function
julia
_pressure_kernel(
    r::Recurrence,
    stop
) -> Union{Recurrence{K} where K<:(TimeVarying{ComposableRecurrences.Primary, A} where A<:(AbstractMatrix)), Recurrence{K} where K<:(TimeVarying{ComposableRecurrences.Primary, A} where A<:(PerStratum{A} where A<:(AbstractArray{<:Any, 3})))}

Return the recurrence whose kernel the pressure reads up to time stop.

source
ComposableRecurrences._pressure_rule Function
julia
_pressure_rule(kernel) -> Bool

Return whether pressure takes its rule for kernel.

source
ComposableRecurrences._pressure_run Function
julia
_pressure_run(
    _::Type{Tp},
    r,
    y,
    h,
    τ0,
    L,
    D,
    S,
    T,
    keep::Val
) -> Union{Tuple{Any, Nothing}, Tuple{Any, NamedTuple{(:H, :P, :kernel, :h, :τ0, :L, :D, :S, :T), <:NTuple{9, Any}}}}

Return the pressure at every step, with the buffer and each step's kernel convolutions P for the reverse pass when keep is Val(true).

source
ComposableRecurrences._pressure_step! Function
julia
_pressure_step!(
    t,
    out,
    P,
    coupling,
    g,
    p,
    q,
    H,
    τ0,
    L,
    D,
    S
)

Write step t's pressure on every stratum, read as the run's step reads it, and its kernel convolutions into P when the reverse pass keeps them.

source
ComposableRecurrences._primal_matrix Function
julia
_primal_matrix(lin, gain, at, ρ, L, S) -> Any

Return M(ρ) with no derivative.

source
ComposableRecurrences._rate_step Function
julia
_rate_step(x, lin, gain, at, v, L) -> Tuple{Any, Any}

Return the next Newton iterate of the rate from x, for strata that do not mix.

source
ComposableRecurrences._record! Function
julia
_record!(_::ComposableRecurrences._NoRecord, i, s, η)

Record survival s and hazard η at lag index i in walk scratch sc, unless it records nothing.

source
ComposableRecurrences._reversed_stop Function
julia
_reversed_stop(stop::Integer, gain, add) -> Int64

Return the last time of a reversed call: stop when given, else the length over time of gain or add.

source
ComposableRecurrences._root Function
julia
_root(ρ::Number, found) -> Any

Return the root with no derivative, or NaN when the solve did not settle.

source
ComposableRecurrences._route_coupling Function
julia
_route_coupling(C) -> GPUArrays.AbstractGPUSparseMatrixCSR

Return route coupling C in the form it is stored, which is C itself unless a method for its type says otherwise.

source
ComposableRecurrences._route_forward! Function
julia
_route_forward!(C, w, z, τ) -> Any

Write into w the pressure that route coupling C gives from the route's kernel pressure z.

source
ComposableRecurrences._route_mirrors Function
julia
_route_mirrors(_::Nothing, xs) -> Any

Return each route's mirror from x̄s, or nothing for each route in xs when no cotangent is carried.

source
ComposableRecurrences._route_op Function
julia
_route_op(r::Recurrence) -> Recurrence

Return the recurrence a NoAdjoint wraps, or the recurrence itself.

source
ComposableRecurrences._routes_back! Function
julia
_routes_back!(
    _::Tuple{},
    pbufs,
    ḡs,
    C̄s,
    Cs,
    gs,
    Ls,
    z,
    z̄,
    p̄,
    H,
    H̄,
    t,
    τ,
    L
)

For each route, recompute its convolution z, send p̄ back through its coupling into z̄, then through its kernel into its buffer in kbuf.

source
ComposableRecurrences._routes_pressure! Function
julia
_routes_pressure!(
    ex,
    p,
    z,
    w,
    _::Tuple{},
    _::Tuple{},
    _::Tuple{},
    H,
    t,
    τ,
    L
)

Add each route's coupled pressure at step t to p, with z and w as work vectors.

source
ComposableRecurrences._row Function
julia
_row(
    sc::ComposableRecurrences._SurvivalScratch{false},
    k
) -> Int64

Return the row of scratch sc that stratum k reads: 1 without a strata axis, else k.

source
ComposableRecurrences._row_dot Function
julia
_row_dot(K, i, x) -> Any

Return the dot product of row i of K with x.

source
ComposableRecurrences._row_route Function
julia
_row_route(route, op) -> ComposableRecurrences.NoAdjoint

Return op, wrapped in NoAdjoint when route is one.

source
ComposableRecurrences._rows_of Function
julia
_rows_of(x) -> Any

Return the number of strata x has rows for, or nothing when it has no row per stratum.

source
ComposableRecurrences._safe_slope Function
julia
_safe_slope(t) -> Any

Return the slope of the floored total at t: one above eps, and zero at or below it.

source
ComposableRecurrences._safe_total Function
julia
_safe_total(t) -> Any

Return total t, or eps when t is at most eps, as a max with no branch on its value.

source
ComposableRecurrences._scaled_power Function
julia
_scaled_power(B) -> Tuple{Any, Any, Any}

Return B over the sum of its entries, its row sums and their largest change from v, the row sums of a uniform matrix when left out.

source
ComposableRecurrences._scaled_sum Function
julia
_scaled_sum(Cs, gs) -> Any

Return Σ_r λ_r g_r for scaled identity couplings Cs and vector kernels gs, each kernel zero past its end.

source
ComposableRecurrences._scratch Function
julia
_scratch(x, ::Type, L) -> Any
_scratch(x, ::Type, L, B) -> Any

Return the scratch that the Survivals and lag maps in x fill for a block of B cohorts and L lags, or nothing when there are none.

source
ComposableRecurrences._segment Function
julia
_segment(p::ComposableRecurrences._Piecewise, t) -> Any

Return the segment of time t: the last whose start is at or before t, the first for a time before 1.

source
ComposableRecurrences._segment_of Function
julia
_segment_of(s, t) -> Any

Return the index of the last start in s at or before t, or 1 when none is.

source
ComposableRecurrences._set_weight! Function
julia
_set_weight!(K::AbstractMatrix, v, k, i, τ)

Set the weight on lag index i of cohort τ in weights array K, for stratum k where it has a strata axis, to v.

source
ComposableRecurrences._settled Function
julia
_settled(Δ::Number, ρ::Number) -> Any

Return whether the Newton step Δ from ρ is within the tolerance, in every entry for arrays.

source
ComposableRecurrences._skip Function
julia
_skip(i, l, st)

Do nothing, as the callback of a walk that only records.

source
ComposableRecurrences._solvable Function
julia
_solvable(x::Number) -> Any

Return whether x, or every entry of it, is positive and finite, the values for which a rate exists.

source
ComposableRecurrences._split_index Function
julia
_split_index(i, m) -> Tuple{Any, Any}

Return the row and column of linear index i in a matrix of m rows.

source
ComposableRecurrences._split_rows Function
julia
_split_rows(
    _::ComposableRecurrences._SplitRows{S},
    Y
) -> Tuple

Return the rows of Y as a tuple of S vectors.

source
ComposableRecurrences._stack Function
julia
_stack(_::Type{V}, get, ps, sz) -> Any

Return the values get(p), each of size sz, copied into the slices of one zeroed array on their device.

source
ComposableRecurrences._stack_masses Function
julia
_stack_masses(A, grid, origin) -> Any

Return the masses from lag origin of each delay in array A as one array, lags first and the axes of A after.

source
ComposableRecurrences._stack_rows Function
julia
_stack_rows(xs::Tuple) -> Any

Return the series of the tuple xs, checked to share one length, stacked as the rows of a strata × time matrix.

source
ComposableRecurrences._stack_values Function
julia
_stack_values(_::Type{<:Real}, get, ps) -> Any

Return the values get(p) of the pairs ps stacked along a new last axis, in the form the type V picks.

source
ComposableRecurrences._start_time Function
julia
_start_time(p::Pair{<:Integer}) -> Integer

Return the start time of the change point p, an ArgumentError when it is not an integer.

source
ComposableRecurrences._start_times Function
julia
_start_times(ps) -> Any

Return the start times of the change points ps.

source
ComposableRecurrences._strata_axis Function
julia
_strata_axis(W::AbstractArray{<:Any, 3}) -> Any

Return the strata axis of a block of weights W.

source
ComposableRecurrences._strata_ragged Function
julia
_strata_ragged(x)

Throw the ArgumentError for a per-stratum or pairwise kernel given as kernel columns.

source
ComposableRecurrences._stratified Function
julia
_stratified(x) -> Any

Return whether coefficient x has a strata axis, fixed at compile time from its type.

source
julia
_stratified(r::Recurrence, gain) -> Any

Return whether the gain or kernel has a row per stratum, as a Val read from the types.

source
ComposableRecurrences._stratified_rate Function
julia
_stratified_rate(rate) -> Val{true}

Return whether rate has one value per stratum, as a Val.

source
ComposableRecurrences._stratified_type Function
julia
_stratified_type(_::Type) -> Any

Return whether a coefficient of type T has a strata axis, whose count _coef_strata then gives, from the type alone so the kernel's shape infers.

source
ComposableRecurrences._survival_flat Function
julia
_survival_flat(
    hazard,
    from
) -> ComposableRecurrences.Survival

Return the Survival rebuilt from its fields, as constructorof gives it.

source
ComposableRecurrences._table_back! Function
julia
_table_back!(X̄, Y, t̄, x, X, Ȳ, m, start)

Run the reverse pass of a table's convolution, adding into input mirror X̄, table mirror t̄ and transposed product Y, each skipped when nothing.

source
ComposableRecurrences._table_back_through! Function
julia
_table_back_through!(X̄, Y, c̄, c, X, Ȳ, m, start)

Take the kernel's mirror c̄ to the table's mirror, then run the reverse pass of the table's convolution.

source
ComposableRecurrences._table_convolve! Function
julia
_table_convolve!(Y, x, X, m, start) -> Any

Add the convolution of input rows X, from row m, with lag map x of a weights table into Y, whose rows are the times from start, and return Y.

source
ComposableRecurrences._table_covers Function
julia
_table_covers(K, stop) -> Any

The table K with zero columns after its last input time up to stop, so its kernel covers the call's times.

Arguments

  • K: an L × n or S × L × n table.

  • stop: the last time of the call, or nothing for n.

source
ComposableRecurrences._table_entry Function
julia
_table_entry(t::AbstractMatrix, k, i, τ) -> Any

Return the weight on lag index i of cohort τ in table t, for stratum k where the table has a strata axis.

source
ComposableRecurrences._table_group Function
julia
_table_group(t::AbstractMatrix, ks, k0) -> Any

Return the strata of ks that group k0 serves: all of them for a table of one stratum's weights, else k0 alone.

source
ComposableRecurrences._table_groups Function
julia
_table_groups(t::AbstractMatrix, ks) -> Base.OneTo{Int64}

Return the groups to loop over: one for a table of one stratum's weights, which serves every stratum, or each stratum of ks for a table with a stratum axis.

source
ComposableRecurrences._table_inputs Function
julia
_table_inputs(K::AbstractMatrix) -> Any

Inputs of one for each input time of the table K, one series per stratum.

Arguments

  • K: an L × n or S × L × n table.
source
ComposableRecurrences._table_kernel Function
julia
_table_kernel(K::AbstractMatrix) -> AbstractMatrix

The kernel weights of the table K: K itself, or PerStratum(K) for one table per stratum.

Arguments

  • K: an L × n or S × L × n table.
source
ComposableRecurrences._table_mapped Function
julia
_table_mapped(x) -> Bool

Return whether x is the increments of a table of a kernel's weights, or those normalised, which read the table in place.

source
ComposableRecurrences._table_mirror Function
julia
_table_mirror(
    x̄,
    x::ComposableRecurrences.Increments{<:Union{TimeVarying{ComposableRecurrences.Primary, <:AbstractMatrix{<:Number}}, TimeVarying{ComposableRecurrences.Primary, <:AbstractArray{<:Number, 3}}}}
) -> Any

Return the table's mirror inside the mirror x̄ of the kernel's lag maps.

source
ComposableRecurrences._table_of Function
julia
_table_of(
    x::ComposableRecurrences.Increments{<:Union{TimeVarying{ComposableRecurrences.Primary, <:AbstractMatrix{<:Number}}, TimeVarying{ComposableRecurrences.Primary, <:AbstractArray{<:Number, 3}}}}
) -> Union{AbstractArray{<:Number, 3}, AbstractMatrix{<:Number}}

Return the table of weights inside lag map x.

source
ComposableRecurrences._table_scale Function
julia
_table_scale(
    x::ComposableRecurrences.Increments{<:Union{TimeVarying{ComposableRecurrences.Primary, <:AbstractMatrix{<:Number}}, TimeVarying{ComposableRecurrences.Primary, <:AbstractArray{<:Number, 3}}}},
    t,
    k,
    τ,
    L
) -> Tuple{Any, Any}

Return the scale of cohort τ's increments and the slope of its total's floor.

source
ComposableRecurrences._table_step Function
julia
_table_step(t, k, i, τ) -> Any

Return the increment of table t on lag index i > 1.

source
ComposableRecurrences._tail_mirrors Function
julia
_tail_mirrors(_::Nothing)

Return the argument mirrors ā after the first, or nothing when there are none.

source
ComposableRecurrences._time Function
julia
_time(
    _::TimeVarying{ComposableRecurrences.Primary},
    τ,
    l
) -> Any

Return the time a coefficient is read at for lag l of cohort τ: the cohort's own time, or the time the weight lands.

source
ComposableRecurrences._time_length Function
julia
_time_length(x) -> Any

Return the length over time of an array, or nothing for anything else.

source
ComposableRecurrences._time_slice Function
julia
_time_slice(A::AbstractVector, w) -> Any

Return the columns w of A along its last axis.

source
ComposableRecurrences._transposed_back! Function
julia
_transposed_back!(ex, Ā, k̄, kernel, Z̄, A, o, start)

Compute the series' cotangent Ā from the convolution's forward body, then the kernel's k̄ from its reverse body.

source
ComposableRecurrences._transposed_rows Function
julia
_transposed_rows(kernel, last, stop) -> Any

Return the rows the bodies fill and read for the outputs, past stop for most kernels.

source
ComposableRecurrences._transposed_split! Function
julia
_transposed_split!(ex, Ā, k̄, kernel, Z̄, A, o, start)

Compute the series' cotangent and then the kernel's in two separate passes.

source
ComposableRecurrences._uniform Function
julia
_uniform(tol, S) -> Any

Return a vector of S entries 1 / S in the type of tol.

source
ComposableRecurrences._unit Function
julia
_unit(_::Val{false}, lin, gain) -> Any

Return the profile of strata that do not mix: one for a series, one per stratum.

source
ComposableRecurrences._value Function
julia
_value(x::Real, sc, k, i, τ, l, b) -> Real

Return the value of coefficient x on lag index i (lag l) of cohort τ in stratum k, reading entry b of the block's scratch sc where it needs.

source
ComposableRecurrences._value_type Function
julia
_value_type(_::Type{<:Pair{<:Any, V}}) -> Any

Return the value type of a Pair type.

source
ComposableRecurrences._values_at Function
julia
_values_at(_::Tuple{}, _::Tuple{}, k, i, τ, l, b) -> Tuple{}

Return the values of arguments a at an entry, each with its scratch in sc.

source
ComposableRecurrences._values_eltype Function
julia
_values_eltype(_::Type{V}, get, ps) -> Any

Return the eltype of the stacked values: that of V when concrete, else promoted over the values.

source
ComposableRecurrences._values_type Function
julia
_values_type(_::Type{V}, get, ps) -> Any

Return the type that picks how the values get(p) stack: V when concrete, else the join of the values' own types, as for pairs typed Pair{Int, Any}.

source
ComposableRecurrences._walk Function
julia
_walk(x, sc, st, k, i, τ, l) -> Tuple

Return the state at lag index i (lag l) of cohort τ, stratum k, from the state st at the lag before, inner Survivals first.

source
ComposableRecurrences._walk_args Function
julia
_walk_args(
    _::Tuple{},
    _::Tuple{},
    _::Tuple{},
    k,
    i,
    τ,
    l
) -> Tuple{}

Return the states of arguments a at an entry, each from its state in st.

source
ComposableRecurrences._walk_back Function
julia
_walk_back(x̄, x, sc, a, k, i, τ, l) -> Any

Return the carried cotangents at the lag index before i, from those a at i, adding to the mirror x̄ on the way.

source
ComposableRecurrences._walk_back_args Function
julia
_walk_back_args(
    ā,
    _::Tuple{},
    _::Tuple{},
    _::Tuple{},
    k,
    i,
    τ,
    l
) -> Tuple{}

Return the carried cotangents of arguments x one lag index back, each from its own in a.

source
ComposableRecurrences._walk_back_one! Function
julia
_walk_back_one!(x̄, x, sc, K̄, k, τ, o, last)

Walk cohort τ of stratum k again, add its weights' cotangents, and walk it back.

source
ComposableRecurrences._walk_cohort! Function
julia
_walk_cohort!(f, x, sc, k, τ, o, imax, _::Type{T})

Walk cohort τ from lag index 1 to imax, lags from o, for stratum k, calling f(i, l, st) with the state at each lag.

source
ComposableRecurrences._walk_cohort_back! Function
julia
_walk_cohort_back!(x̄, x, sc, k, τ, o, imax, _::Type{T})

Walk back along cohort τ's lags from imax, once the cotangents of its weights are added.

source
ComposableRecurrences._walk_column Function
julia
_walk_column(sc, j) -> Any

Return the scratch of column j of sc.

source
ComposableRecurrences._walk_cotangent Function
julia
_walk_cotangent(x, _::Type) -> Any

Return the starting cotangents carried back: each Survival's, of its survival from the current lag on, and its hazard's, in the shape of the walk's state.

source
ComposableRecurrences._walk_fill! Function
julia
_walk_fill!(
    K,
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    o,
    last
) -> Tuple{Union{AbstractArray{<:Any, 3}, AbstractMatrix}, Any}
_walk_fill!(
    K,
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    o,
    last,
    keep::Val
) -> Tuple{Union{AbstractArray{<:Any, 3}, AbstractMatrix}, Any}

Fill the weights K of kernel by walking each cohort's lags, and return them with the walk's scratch.

source
ComposableRecurrences._walk_groups Function
julia
_walk_groups(x, ks) -> Any

Return the first stratum of each walk: one walk for all of ks when no Survival has strata, else one walk per stratum.

source
ComposableRecurrences._walk_hazard! Function
julia
_walk_hazard!(sc, h, st, k, i, τ, l) -> Any

Return a Survival's hazard at an entry, keeping its partials where sc holds them.

source
ComposableRecurrences._walk_index Function
julia
_walk_index(sc, g, τ, n) -> Any

Return the column of group g and cohort τ when every walk is kept, else 1.

source
ComposableRecurrences._walk_keeps Function
julia
_walk_keeps(x, _::Val{keep}) -> Any

Return whether every walk of x is kept: when keep is true and x keeps its fill.

source
ComposableRecurrences._walk_kept Function
julia
_walk_kept(sc) -> Bool

Return whether scratch sc keeps every cohort's walk.

source
ComposableRecurrences._walk_scratch Function
julia
_walk_scratch(x, _::Type, dims, keep) -> Any

Return the scratch that the walks of coefficient x record into, its arrays of size dims, or nothing where x holds no Survival or lag map.

source
ComposableRecurrences._walk_state Function
julia
_walk_state(x, _::Type) -> Any

Return the walk's starting state: each Survival's survival at the current lag and its hazard's state, a tuple per Derived, nothing elsewhere.

source
ComposableRecurrences._walk_strata Function
julia
_walk_strata(x, ks, k0) -> Any

Return the strata that the walk from stratum k0 serves: all of ks when no Survival has strata, else k0 alone.

source
ComposableRecurrences._walk_total! Function
julia
_walk_total!(
    x::ComposableRecurrences.Normalised,
    sc,
    k,
    τ,
    o,
    _::Type{T}
)

Walk the kernel inside x through all of cohort τ's lags into U, and write its normalised weights into W.

source
ComposableRecurrences._walk_total_back! Function
julia
_walk_total_back!(
    x̄,
    x::ComposableRecurrences.Normalised,
    sc,
    k,
    τ,
    o
)

Take the weight cotangents of x back through the map, then back along all of cohort τ's lags of the kernel inside.

source
ComposableRecurrences._walk_value Function
julia
_walk_value(x, st, k, i, τ, l) -> Any

Return the value of coefficient x at an entry, from the walk's state st.

source
ComposableRecurrences._walk_values Function
julia
_walk_values(_::Tuple{}, _::Tuple{}, k, i, τ, l) -> Tuple{}

Return the values of arguments a at an entry, from their walk states st.

source
ComposableRecurrences._walk_weights_back! Function
julia
_walk_weights_back!(
    x̄,
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    K̄,
    o,
    last,
    sc
)

Take the cotangent K̄ of the weights back to the coefficients' mirror x̄, walking each cohort again unless sc kept its walk.

source
ComposableRecurrences._walks_strata Function
julia
_walks_strata(x) -> Any

Return whether a Survival in coefficient x has a strata axis, fixed at compile time from its type.

source
ComposableRecurrences._walks_strata_type Function
julia
_walks_strata_type(_::Type) -> Any

Return whether a Survival in a coefficient of type T has a strata axis, from the type.

source
ComposableRecurrences._weights_array Function
julia
_weights_array(_::Val{false}, _::Type{Tp}, ns, L, n) -> Any

Return a zero array of weights on L lags of n cohorts, with ns strata first when the first argument is Val(true).

source
ComposableRecurrences._weights_back! Function
julia
_weights_back!(
    _::Nothing,
    kernel::TimeVarying{ComposableRecurrences.Primary, <:Union{ComposableRecurrences.LagMap, ComposableRecurrences.Derived, ComposableRecurrences.Survival}},
    K̄,
    o,
    last,
    sc
)

Take the cotangent K̄ of the weights of kernel back to the mirror x̄ of its coefficients.

source
ComposableRecurrences._weights_cotangent Function
julia
_weights_cotangent(_::Nothing, K)

Return the cotangent of the weights K to fill, or nothing when the kernel's mirror x̄ is absent.

source
ComposableRecurrences._weights_strata Function
julia
_weights_strata(K::AbstractMatrix) -> Base.OneTo{Int64}

Return the strata axis of weights array K, one stratum for a matrix.

source
ComposableRecurrences._window_before Function
julia
_window_before(_::Nothing, v, prev) -> Any

Return the time before window v: before its start when given, else the end prev of the window before it, so consecutive windows start after that end.

source
ComposableRecurrences._window_sum_at! Function
julia
_window_sum_at!(i, out, x, lo, hi, along, m)

Write into out[i] the sum of x over one window, with along true when time is the first dimension and m the rows of out.

source
ComposableRecurrences._window_sums Function
julia
_window_sums(
    op::ComposableRecurrences._WindowSums,
    ,
    x::AbstractVector
) -> Any

Return the sums of x over the windows lo, hi along op.dims.

source
ComposableRecurrences._window_sums_back! Function
julia
_window_sums_back!(
    x̄::AbstractVector,
    op::ComposableRecurrences._WindowSums,
    ,
    ȳ
) -> AbstractVector

Add each window's cotangent in ȳ to x̄ at every time the window covers.

source
ComposableRecurrences._window_sums_back_at! Function
julia
_window_sums_back_at!(j, x̄, ȳ, lo, hi, along, m)

Add to x̄[j] the cotangents of every window its time falls in, with along as in _window_sum_at! and m the rows of x̄.

source
ComposableRecurrences._windows Function
julia
_windows(
    op::ComposableRecurrences._WindowSums
) -> NamedTuple{(:lo, :hi), <:Tuple{Any, Any}}

Return (; lo, hi), window v covering times lo[v] + 1 to hi[v], empty when hi[v] <= lo[v].

source
ComposableRecurrences.depth Function
julia
depth(x) -> Int64

Return the number of past outputs x reads from a recurrence's buffer, before the current step.

A Recurrence keeps

past outputs per stratum, where is the kernel length, is depth and are the modifiers. The kernel reads the last of them; the deeper rows are kept for objects that read further back than the kernel. A ComposableRecurrences.State holds the last outputs, so a resumed call reads the same past. The default recurses by value through the fields of immutable structs, tuples and named tuples and takes the largest. Numbers, arrays, functions, mutable objects and operators (which keep their own buffers) read nothing,  , so an object held inside an array or a mutable struct is not counted. Add a method for a type that reads the buffer.

Arguments

  • x: any object, such as a modifier, coupling or kernel.

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
struct Window
    w::Int
end
CR.depth(x::Window) = x.w
x = (Window(5), (; a = Window(9), b = 1.0))
CR.depth(x), CR.depth(CR.Transform(clamp, 0.0, 1.0))

# output

(9, 0)
source
ComposableRecurrences.each! Function
julia
each!(
    body,
    _::ComposableRecurrences.Serial,
    n,
    work,
    args...
)
julia
each!(body, ex::Executor, n, work, args...)

Call body(k, args...) for every k in 1:n with executor ex:

where each index k is one stratum or one output time.

body must write only the slots it owns for index k, so the indices can run in any order or at the same time. A new executor type adds a method of each!. Returns nothing.

Arguments

  • body: the per-index function, called as body(k, args...).

  • ex: the executor that runs the loop.

  • n: the number of indices.

  • work: an estimate of the loop's total cost in inner operations, which an executor may use to run small loops in order; Serial ignores it.

  • args: the arguments passed to every call of body.

Examples

julia
using ComposableRecurrences
const CR = ComposableRecurrences
# Row sums of a matrix, one row per index.
rowsum!(k, y, A) = (y[k] = sum(view(A, k, :)); nothing)
A = [1.0 2.0; 3.0 4.0]
y = zeros(2)
CR.each!(rowsum!, CR.Serial(), 2, length(A), y, A)
y

# output

2-element Vector{Float64}:
 3.0
 7.0
source
ComposableRecurrences.forward Function

Run operator op over a whole call, returning (y, cache).

This is the ComposableRecurrences.Run role: calling the operator lowers to forward(op, Run(), args...; kwargs...). For inputs it computes

with the operator's own maths, and cache holds what the reverse pass needs. Couplings and whole-step modifiers write their outputs in place through ComposableRecurrences.forward! instead.

Arguments

  • op: the operator.

  • role: Run().

  • args: the call's arguments.

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
y, cache = CR.forward(Convolution([0.5, 0.5]), CR.Run(), [1.0, 2.0, 3.0])
y

# output

3-element Vector{Float64}:
 0.5
 1.5
 2.5
source
ComposableRecurrences.ispointwise Function
julia
ispointwise(m) -> Bool

Return whether modifier m acts on each stratum separately: whether its ComposableRecurrences.blocks is (1, 1).

A pointwise modifier's step factorises over the strata: at absolute time , stratum 's new value and state depend only on its own,

It follows from blocks, which is the trait to define.

Arguments

  • m: the modifier.

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
CR.ispointwise(CR.Transform(clamp, 0.0, 1.0)), CR.ispointwise(nothing)

# output

(true, false)
source
ComposableRecurrences.param_eltype Function
julia
param_eltype(x) -> Any

Return the element type the parameters of x contribute to an operator's buffer.

The buffer eltype is the float promotion of this over the kernel, coupling, modifiers, inputs and history,

where is param_eltype, so a dual number or a Float32 anywhere sets it. The default recurses by value through fields, tuples and named tuples, so abstractly typed fields count; a Real gives its type and an array of reals its eltype. Add a method for a type whose parameters this does not reach.

Arguments

  • x: any object, such as a modifier, coupling or kernel.

Examples

julia
using ComposableRecurrences
struct Scale
    a
    extra::NamedTuple
end
ComposableRecurrences.param_eltype(Scale(1.0f0, (; b = 2)))

# output

Float32
source
Base.reverse Method
julia
reverse(
    r::Recurrence
) -> ComposableRecurrences._Reversed{R} where R<:Recurrence

Return the recurrence r run backwards in time,

in the notation of Recurrence, with its modifiers. It is r on the time axis    , called as reverse(r)(gain = 1; tail, add, start = 1, stop, record).

Arguments

  • gain, add: as in a call of r, read at absolute time s.

Keyword Arguments

A TimeVarying array in r is read at its columns start:stop. One given by change points or by a vector per time, or a kernel computed from coefficients, is an ArgumentError. A type of your own is rebuilt from its fields with ConstructionBase.constructorof.

Examples

julia
using ComposableRecurrences
g = [0.6, 0.4]
R = [2.0, 1.0, 0.5, 1.0]
reverse(Recurrence(g))(R; add = R)

# output

4-element Vector{Float64}:
 4.896
 1.88
 0.8
 1.0
source
Base.transpose Method
julia
transpose(
    c::Convolution
) -> ComposableRecurrences._TransposedConvolution

Return the transpose of the convolution c, also written c': a sum that reads the series forward from each time rather than back from it,

for a ComposableRecurrences.Primary or fixed kernel, in the notation of Convolution: if c without a gain or add input computes  , the transpose computes  . A ComposableRecurrences.Secondary kernel (the default for a TimeVarying kernel) weights by  , the column of the time it reads. c' is the same operator, and the transpose of the transpose is c.

Called as transpose(c)(x; tail = nothing, start = 1, stop), it covers the absolute times start:stop:

  • x: the series, length n or S × n, read at absolute time t.

  • tail: the series after t = n, oldest first (any length m, or S × m); later values are zero. A series extended by its last value is tail = fill(x[end], L - 1).

  • start: the first time; 1 by default.

  • stop: the last time; n by default. It may pass n + m, where the series is zero, so an output that reads only those times is zero.

The output has the layout of x and length stop - start + 1. A Primary() kernel covers times up to stop, and any other TimeVarying kernel the last time it reads, min(stop + L - 1, n + m).

It takes the direct method whatever the method of c.

Examples

julia
using ComposableRecurrences
c = Convolution([0.5, 0.25, 0.25])
c'([1.0, 2.0, 4.0, 8.0])

# output

4-element Vector{Float64}:
 2.0
 4.0
 4.0
 4.0
source
ComposableRecurrences.uses_adjoint Function
julia
uses_adjoint(piece, role) -> Bool

Return whether piece carries its own rule in role: a ComposableRecurrences.pullback! method for that role.

For outputs   of the role, with inputs and parameters , the adjoint computes the cotangents

directly, where is the gradient of a scalar loss with respect to .

By default it is true for a modifier written as a pure ComposableRecurrences.step whose float fields are all parameters, and when pullback! has a method for the type of piece and role whose other arguments are untyped, so writing the method is enough. A whole-step modifier with a forward! for ComposableRecurrences.Init needs a pullback! for it too. The lookup is read from the types, so the route costs nothing per call. A method with a typed grads or typed arguments is not found; declare uses_adjoint(::T, role) = true for such a type, which ComposableRecurrences.PieceInterface checks. A method of uses_adjoint also overrides the default, for example when the adjoint covers only some values of a type. If it is true but no pullback! method fits the arguments, the reverse pass throws a MethodError. An operator uses its adjoint in ComposableRecurrences.Run when it has one. A Recurrence does when every float it holds is a Float16, Float32 or Float64 and each component is a pure ComposableRecurrences.step or has a pullback!.

Arguments

  • piece: the operator, coupling, modifier or depletion form.

  • role: the role.

Examples

julia
using ComposableRecurrences
CR = ComposableRecurrences
CR.uses_adjoint(Recurrence([0.5, 0.5]), CR.Run())

# output

true
source