CavityTools.AccumulatorType

An a = Accumulator(v::AbstractVector; op=+, init=zero) works as a replacement for v with extra tracking computation, such as sum. See also CumSum and Cavity

julia> a = Accumulator([1:10;])
10-element Accumulator{Int64, +, zero}:
1
2
3
4
5
6
7
8
9
10

julia> sum(a)
55

julia> a[1]=0
0

julia> sum(a)
54

CavityTools.CumSumType

An CumSum(a::Accumulator) gets updated each time that a does. The time for an update and retrieval is both O(log(length(a))). It is normally constructed with cumsum(a), which takes time O(1)

julia> a = Accumulator([1:10;])
10-element Accumulator{Int64, +, zero}:
1
2
3
4
5
6
7
8
9
10

julia> c = cumsum(a)
CumSum(Accumulator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

julia> c[end]
55

julia> a[1] = 100
100

julia> c[end]
154
CavityTools.ExponentialQueueType

ExponentialQueue() keeps an updatable queue of up to N events with ids 1...N and contant rates Q[1] ... Q[N]. This is intended for sampling in continuous time.

julia> Q = ExponentialQueue() ExponentialQueue(Accumulator{Float64, +, zero}([Float64[]]), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], Int64[])

julia> Q[1] = 1.2 #updates rate of event 1 1.2

julia> Q[55] = 2.3 #updates rate of event 55 2.3

julia> i,t = pop!(Q) # gets time and id of next event and remove it from the queue (55, 0.37869716808319576)

See also: ExponentialQueueDict

CavityTools.ExponentialQueueDictType

ExponentialQueueDict{K} keeps an updatable queue of elements of type K with contant rates Q[k]. This is intended for sampling in continuous time.

julia> Q = ExponentialQueueDict{Int}() ExponentialQueueDict(Pair{Int64, Float64}[])

julia> Q[1] = 1.2 # updates rate of event 1 1.2

julia> Q[55] = 2.3 # updates rate of event 55 2.3

julia> i,t = pop!(Q) # gets time and id of next event and remove it from the queue (55, 0.37869716808319576)

See also: ExponentialQueue for a slightly more efficient queue for the case K == Int

Base.pop!Method

k,t = pop!(Q): Sample next event and time from the queue and remove it from the queue.