From ef1494d1cc4c81b06ac445182c763290e44bc514 Mon Sep 17 00:00:00 2001 From: denainjs <43207175+denainjs@users.noreply.github.com> Date: Fri, 19 Jun 2020 08:00:57 +0200 Subject: [PATCH 01/44] Initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..f0398e39 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# AdvancedSMC.jl \ No newline at end of file From c752e7fc93dad2995fdda3ed2173fff78c95cb4c Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 19 Jun 2020 08:04:40 +0200 Subject: [PATCH 02/44] initialize files --- AdvancedSMC.jl | 0 particlecontainer.jl | 0 resampling.jl | 0 trace.jl | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 AdvancedSMC.jl create mode 100644 particlecontainer.jl create mode 100644 resampling.jl create mode 100644 trace.jl diff --git a/AdvancedSMC.jl b/AdvancedSMC.jl new file mode 100644 index 00000000..e69de29b diff --git a/particlecontainer.jl b/particlecontainer.jl new file mode 100644 index 00000000..e69de29b diff --git a/resampling.jl b/resampling.jl new file mode 100644 index 00000000..e69de29b diff --git a/trace.jl b/trace.jl new file mode 100644 index 00000000..e69de29b From 35652c05b7e6896a53feab52aeee2a6ebc7c66c1 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 19 Jun 2020 08:08:56 +0200 Subject: [PATCH 03/44] move first chunks, temporary --- particlecontainer.jl | 269 +++++++++++++++++++++++++++++++++++++++++++ resampling.jl | 149 ++++++++++++++++++++++++ trace.jl | 78 +++++++++++++ 3 files changed, 496 insertions(+) diff --git a/particlecontainer.jl b/particlecontainer.jl index e69de29b..06ba0c19 100644 --- a/particlecontainer.jl +++ b/particlecontainer.jl @@ -0,0 +1,269 @@ + +""" +Data structure for particle filters +- effectiveSampleSize(pc :: ParticleContainer) +- normalise!(pc::ParticleContainer) +- consume(pc::ParticleContainer): return incremental likelihood +""" +mutable struct ParticleContainer{T<:Particle} + "Particles." + vals::Vector{T} + "Unnormalized logarithmic weights." + logWs::Vector{Float64} +end + +function ParticleContainer(particles::Vector{<:Particle}) + return ParticleContainer(particles, zeros(length(particles))) +end + +Base.collect(pc::ParticleContainer) = pc.vals +Base.length(pc::ParticleContainer) = length(pc.vals) +Base.@propagate_inbounds Base.getindex(pc::ParticleContainer, i::Int) = pc.vals[i] + +# registers a new x-particle in the container +function Base.push!(pc::ParticleContainer, p::Particle) + push!(pc.vals, p) + push!(pc.logWs, 0.0) + pc +end + +# clones a theta-particle +function Base.copy(pc::ParticleContainer) + # fork particles + vals = eltype(pc.vals)[fork(p) for p in pc.vals] + + # copy weights + logWs = copy(pc.logWs) + + ParticleContainer(vals, logWs) +end + +""" + reset_logweights!(pc::ParticleContainer) +Reset all unnormalized logarithmic weights to zero. +""" +function reset_logweights!(pc::ParticleContainer) + fill!(pc.logWs, 0.0) + return pc +end + +""" + increase_logweight!(pc::ParticleContainer, i::Int, x) +Increase the unnormalized logarithmic weight of the `i`th particle with `x`. +""" +function increase_logweight!(pc::ParticleContainer, i, logw) + pc.logWs[i] += logw + return pc +end + +""" + getweights(pc::ParticleContainer) +Compute the normalized weights of the particles. +""" +getweights(pc::ParticleContainer) = softmax(pc.logWs) + +""" + getweight(pc::ParticleContainer, i) +Compute the normalized weight of the `i`th particle. +""" +getweight(pc::ParticleContainer, i) = exp(pc.logWs[i] - logZ(pc)) + +""" + logZ(pc::ParticleContainer) +Return the logarithm of the normalizing constant of the unnormalized logarithmic weights. +""" +logZ(pc::ParticleContainer) = logsumexp(pc.logWs) + +""" + effectiveSampleSize(pc::ParticleContainer) +Compute the effective sample size ``1 / ∑ wᵢ²``, where ``wᵢ```are the normalized weights. +""" +function effectiveSampleSize(pc::ParticleContainer) + Ws = getweights(pc) + return inv(sum(abs2, Ws)) +end + +""" + resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; + weights = getweights(pc)]) +Resample and propagate the particles in `pc`. +Function `randcat` is used for sampling ancestor indices from the categorical distribution +of the particle `weights`. For Particle Gibbs sampling, one can provide a reference particle +`ref` that is ensured to survive the resampling step. +""" +function resample_propagate!( + pc::ParticleContainer, + randcat = Turing.Inference.resample_systematic, + ref::Union{Particle, Nothing} = nothing; + weights = getweights(pc) +) + # check that weights are not NaN + @assert !any(isnan, weights) + + # sample ancestor indices + n = length(pc) + nresamples = ref === nothing ? n : n - 1 + indx = randcat(weights, nresamples) + + # count number of children for each particle + num_children = zeros(Int, n) + @inbounds for i in indx + num_children[i] += 1 + end + + # fork particles + particles = collect(pc) + children = similar(particles) + j = 0 + @inbounds for i in 1:n + ni = num_children[i] + + if ni > 0 + # fork first child + pi = particles[i] + isref = pi === ref + p = isref ? fork(pi, isref) : pi + children[j += 1] = p + + # fork additional children + for _ in 2:ni + children[j += 1] = fork(p, isref) + end + end + end + + if ref !== nothing + # Insert the retained particle. This is based on the replaying trick for efficiency + # reasons. If we implement PG using task copying, we need to store Nx * T particles! + @inbounds children[n] = ref + end + + # replace particles and log weights in the container with new particles and weights + pc.vals = children + reset_logweights!(pc) + + pc +end + +""" + reweight!(pc::ParticleContainer) +Check if the final time step is reached, and otherwise reweight the particles by +considering the next observation. +""" +function reweight!(pc::ParticleContainer) + n = length(pc) + + particles = collect(pc) + numdone = 0 + for i in 1:n + p = particles[i] + + # Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the + # the execution of the model is finished. + # Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and + # ``θᵢ`` are variables of other samplers. + score = Libtask.consume(p) + + if score === nothing + numdone += 1 + else + # Increase the unnormalized logarithmic weights, accounting for the variables + # of other samplers. + increase_logweight!(pc, i, score + getlogp(p.vi)) + + # Reset the accumulator of the log probability in the model so that we can + # accumulate log probabilities of variables of other samplers until the next + # observation. + resetlogp!(p.vi) + end + end + + # Check if all particles are propagated to the final time point. + numdone == n && return true + + # The posterior for models with random number of observations is not well-defined. + if numdone != 0 + error("mis-aligned execution traces: # particles = ", n, + " # completed trajectories = ", numdone, + ". Please make sure the number of observations is NOT random.") + end + + return false +end + +""" + sweep!(pc::ParticleContainer, resampler) +Perform a particle sweep and return an unbiased estimate of the log evidence. +The resampling steps use the given `resampler`. +# Reference +Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. +Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(3), 411-436. +""" +function sweep!(pc::ParticleContainer, resampler) + # Initial step: + + # Resample and propagate particles. + resample_propagate!(pc, resampler) + + # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic + # weights. + # Usually it is equal to the number of particles in the beginning but this + # implementation covers also the unlikely case of a particle container that is + # initialized with non-zero logarithmic weights. + logZ0 = logZ(pc) + + # Reweight the particles by including the first observation ``y₁``. + isdone = reweight!(pc) + + # Compute the normalizing constant ``Z₁`` after reweighting. + logZ1 = logZ(pc) + + # Compute the estimate of the log evidence ``\\log p(y₁)``. + logevidence = logZ1 - logZ0 + + # For observations ``y₂, …, yₜ``: + while !isdone + # Resample and propagate particles. + resample_propagate!(pc, resampler) + + # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic + # weights. + logZ0 = logZ(pc) + + # Reweight the particles by including the next observation ``yₜ``. + isdone = reweight!(pc) + + # Compute the normalizing constant ``Z₁`` after reweighting. + logZ1 = logZ(pc) + + # Compute the estimate of the log evidence ``\\log p(y₁, …, yₜ)``. + logevidence += logZ1 - logZ0 + end + + return logevidence +end + +struct ResampleWithESSThreshold{R, T<:Real} + resampler::R + threshold::T +end + +function ResampleWithESSThreshold(resampler = Turing.Inference.resample_systematic) + ResampleWithESSThreshold(resampler, 0.5) +end + +function resample_propagate!( + pc::ParticleContainer, + resampler::ResampleWithESSThreshold, + ref::Union{Particle,Nothing} = nothing; + weights = getweights(pc) +) + # Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ`` + ess = inv(sum(abs2, weights)) + + if ess ≤ resampler.threshold * length(pc) + resample_propagate!(pc, resampler.resampler, ref; weights = weights) + end + + pc +end \ No newline at end of file diff --git a/resampling.jl b/resampling.jl index e69de29b..25409aad 100644 --- a/resampling.jl +++ b/resampling.jl @@ -0,0 +1,149 @@ + +#### +#### Resampling schemes for particle filters +#### + +# Some references +# - http://arxiv.org/pdf/1301.4019.pdf +# - http://people.isy.liu.se/rt/schon/Publications/HolSG2006.pdf +# Code adapted from: http://uk.mathworks.com/matlabcentral/fileexchange/24968-resampling-methods-for-particle-filtering + +# Default resampling scheme +function resample(w::AbstractVector{<:Real}, num_particles::Integer=length(w)) + return resample_systematic(w, num_particles) +end + +# More stable, faster version of rand(Categorical) +function randcat(p::AbstractVector{<:Real}) + T = eltype(p) + r = rand(T) + s = 1 + for j in eachindex(p) + r -= p[j] + if r <= zero(T) + s = j + break + end + end + return s +end + +function resample_multinomial(w::AbstractVector{<:Real}, num_particles::Integer) + return rand(Distributions.sampler(Categorical(w)), num_particles) +end + +function resample_residual(w::AbstractVector{<:Real}, num_particles::Integer) + + M = length(w) + + # "Repetition counts" (plus the random part, later on): + Ns = floor.(length(w) .* w) + + # The "remainder" or "residual" count: + R = Int(sum(Ns)) + + # The number of particles which will be drawn stocastically: + M_rdn = num_particles - R + + # The modified weights: + Ws = (M .* w - floor.(M .* w)) / M_rdn + + # Draw the deterministic part: + indx1, i = Array{Int}(undef, R), 1 + for j in 1:M + for k in 1:Ns[j] + indx1[i] = j + i += 1 + end + end + + # And now draw the stocastic (Multinomial) part: + return append!(indx1, rand(Distributions.sampler(Categorical(w)), M_rdn)) +end + +""" + resample_stratified(weights, n) +Return a vector of `n` samples `x₁`, ..., `xₙ` from the numbers 1, ..., `length(weights)`, +generated by stratified resampling. +In stratified resampling `n` ordered random numbers `u₁`, ..., `uₙ` are generated, where +``uₖ \\sim U[(k - 1) / n, k / n)``. Based on these numbers the samples `x₁`, ..., `xₙ` +are selected according to the multinomial distribution defined by the normalized `weights`, +i.e., `xᵢ = j` if and only if +``uᵢ \\in [\\sum_{s=1}^{j-1} weights_{s}, \\sum_{s=1}^{j} weights_{s})``. +""" +function resample_stratified(weights::AbstractVector{<:Real}, n::Integer) + # check input + m = length(weights) + m > 0 || error("weight vector is empty") + + # pre-calculations + @inbounds v = n * weights[1] + + # generate all samples + samples = Array{Int}(undef, n) + sample = 1 + @inbounds for i in 1:n + # sample next `u` (scaled by `n`) + u = oftype(v, i - 1 + rand()) + + # as long as we have not found the next sample + while v < u + # increase and check the sample + sample += 1 + sample > m && + error("sample could not be selected (are the weights normalized?)") + + # update the cumulative sum of weights (scaled by `n`) + v += n * weights[sample] + end + + # save the next sample + samples[i] = sample + end + + return samples +end + +""" + resample_systematic(weights, n) +Return a vector of `n` samples `x₁`, ..., `xₙ` from the numbers 1, ..., `length(weights)`, +generated by systematic resampling. +In systematic resampling a random number ``u \\sim U[0, 1)`` is used to generate `n` ordered +numbers `u₁`, ..., `uₙ` where ``uₖ = (u + k − 1) / n``. Based on these numbers the samples +`x₁`, ..., `xₙ` are selected according to the multinomial distribution defined by the +normalized `weights`, i.e., `xᵢ = j` if and only if +``uᵢ \\in [\\sum_{s=1}^{j-1} weights_{s}, \\sum_{s=1}^{j} weights_{s})``. +""" +function resample_systematic(weights::AbstractVector{<:Real}, n::Integer) + # check input + m = length(weights) + m > 0 || error("weight vector is empty") + + # pre-calculations + @inbounds v = n * weights[1] + u = oftype(v, rand()) + + # find all samples + samples = Array{Int}(undef, n) + sample = 1 + @inbounds for i in 1:n + # as long as we have not found the next sample + while v < u + # increase and check the sample + sample += 1 + sample > m && + error("sample could not be selected (are the weights normalized?)") + + # update the cumulative sum of weights (scaled by `n`) + v += n * weights[sample] + end + + # save the next sample + samples[i] = sample + + # update `u` + u += one(u) + end + + return samples +end \ No newline at end of file diff --git a/trace.jl b/trace.jl index e69de29b..1903f3c7 100644 --- a/trace.jl +++ b/trace.jl @@ -0,0 +1,78 @@ +mutable struct Trace{Tspl<:AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} + model::Tmodel + spl::Tspl + vi::Tvi + ctask::CTask + + function Trace{SampleFromPrior}(model::Model, spl::AbstractSampler, vi::AbstractVarInfo) + return new{SampleFromPrior,typeof(vi),typeof(model)}(model, SampleFromPrior(), vi) + end + function Trace{S}(model::Model, spl::S, vi::AbstractVarInfo) where S<:Sampler + return new{S,typeof(vi),typeof(model)}(model, spl, vi) + end +end + +function Base.copy(trace::Trace) + vi = deepcopy(trace.vi) + res = Trace{typeof(trace.spl)}(trace.model, trace.spl, vi) + res.ctask = copy(trace.ctask) + return res +end + +# NOTE: this function is called by `forkr` +function Trace(f, m::Model, spl::AbstractSampler, vi::AbstractVarInfo) + res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) + ctask = CTask() do + res = f() + produce(nothing) + return res + end + task = ctask.task + if task.storage === nothing + task.storage = IdDict() + end + task.storage[:turing_trace] = res # create a backward reference in task_local_storage + res.ctask = ctask + return res +end + +function Trace(m::Model, spl::AbstractSampler, vi::AbstractVarInfo) + res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) + reset_num_produce!(res.vi) + ctask = CTask() do + res = m(vi, spl) + produce(nothing) + return res + end + task = ctask.task + if task.storage === nothing + task.storage = IdDict() + end + task.storage[:turing_trace] = res # create a backward reference in task_local_storage + res.ctask = ctask + return res +end + +# step to the next observe statement, return log likelihood +Libtask.consume(t::Trace) = (increment_num_produce!(t.vi); consume(t.ctask)) + +# Task copying version of fork for Trace. +function fork(trace :: Trace, is_ref :: Bool = false) + newtrace = copy(trace) + is_ref && set_retained_vns_del_by_spl!(newtrace.vi, newtrace.spl) + newtrace.ctask.task.storage[:turing_trace] = newtrace + return newtrace +end + +# PG requires keeping all randomness for the reference particle +# Create new task and copy randomness +function forkr(trace::Trace) + newtrace = Trace(trace.ctask.task.code, trace.model, trace.spl, deepcopy(trace.vi)) + newtrace.spl = trace.spl + reset_num_produce!(newtrace.vi) + return newtrace +end + +current_trace() = current_task().storage[:turing_trace] + +const Particle = Trace \ No newline at end of file From 34feb3fbabe67ecaa70b50edc2aa61e9b5ce4808 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Mon, 22 Jun 2020 09:28:34 +0200 Subject: [PATCH 04/44] created sweep.jl, improved resampling structure --- AdvancedSMC.jl | 38 +++++++++ particlecontainer.jl | 185 ------------------------------------------- resampling.jl | 43 ++++++++-- sweep.jl | 180 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 255 insertions(+), 191 deletions(-) create mode 100644 sweep.jl diff --git a/AdvancedSMC.jl b/AdvancedSMC.jl index e69de29b..a911f798 100644 --- a/AdvancedSMC.jl +++ b/AdvancedSMC.jl @@ -0,0 +1,38 @@ +module AdvancedSMC +import Libtask, + Random # doesn't seem like there is anything else to import? DynamicPPL and AbstractMCMC interfacing is handled in inference/ + +# must I export overloaded Base functions? +# perhaps: Inference.jl exports overloaded DynamicPPL functions + +include("particlecontainer.jl") +export ParticleContainer, + reset_logweights!, + increase_logweight!, + getweights, + getweight, + logZ, + effectiveSampleSize + +include("sweep.jl") +export resample_propagate!, + reweight!, + sweep! + +include("resampling.jl") +export ResampleWithESSThreshold, + resample, + randcat, + resample_multinomial, + resample_residual, + resample_stratified, + resample_systematic + +include("trace.jl") +export Trace, + fork, + forkr, + current_trace, + Particle + +end \ No newline at end of file diff --git a/particlecontainer.jl b/particlecontainer.jl index 06ba0c19..cd3f545e 100644 --- a/particlecontainer.jl +++ b/particlecontainer.jl @@ -82,188 +82,3 @@ function effectiveSampleSize(pc::ParticleContainer) Ws = getweights(pc) return inv(sum(abs2, Ws)) end - -""" - resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; - weights = getweights(pc)]) -Resample and propagate the particles in `pc`. -Function `randcat` is used for sampling ancestor indices from the categorical distribution -of the particle `weights`. For Particle Gibbs sampling, one can provide a reference particle -`ref` that is ensured to survive the resampling step. -""" -function resample_propagate!( - pc::ParticleContainer, - randcat = Turing.Inference.resample_systematic, - ref::Union{Particle, Nothing} = nothing; - weights = getweights(pc) -) - # check that weights are not NaN - @assert !any(isnan, weights) - - # sample ancestor indices - n = length(pc) - nresamples = ref === nothing ? n : n - 1 - indx = randcat(weights, nresamples) - - # count number of children for each particle - num_children = zeros(Int, n) - @inbounds for i in indx - num_children[i] += 1 - end - - # fork particles - particles = collect(pc) - children = similar(particles) - j = 0 - @inbounds for i in 1:n - ni = num_children[i] - - if ni > 0 - # fork first child - pi = particles[i] - isref = pi === ref - p = isref ? fork(pi, isref) : pi - children[j += 1] = p - - # fork additional children - for _ in 2:ni - children[j += 1] = fork(p, isref) - end - end - end - - if ref !== nothing - # Insert the retained particle. This is based on the replaying trick for efficiency - # reasons. If we implement PG using task copying, we need to store Nx * T particles! - @inbounds children[n] = ref - end - - # replace particles and log weights in the container with new particles and weights - pc.vals = children - reset_logweights!(pc) - - pc -end - -""" - reweight!(pc::ParticleContainer) -Check if the final time step is reached, and otherwise reweight the particles by -considering the next observation. -""" -function reweight!(pc::ParticleContainer) - n = length(pc) - - particles = collect(pc) - numdone = 0 - for i in 1:n - p = particles[i] - - # Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the - # the execution of the model is finished. - # Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and - # ``θᵢ`` are variables of other samplers. - score = Libtask.consume(p) - - if score === nothing - numdone += 1 - else - # Increase the unnormalized logarithmic weights, accounting for the variables - # of other samplers. - increase_logweight!(pc, i, score + getlogp(p.vi)) - - # Reset the accumulator of the log probability in the model so that we can - # accumulate log probabilities of variables of other samplers until the next - # observation. - resetlogp!(p.vi) - end - end - - # Check if all particles are propagated to the final time point. - numdone == n && return true - - # The posterior for models with random number of observations is not well-defined. - if numdone != 0 - error("mis-aligned execution traces: # particles = ", n, - " # completed trajectories = ", numdone, - ". Please make sure the number of observations is NOT random.") - end - - return false -end - -""" - sweep!(pc::ParticleContainer, resampler) -Perform a particle sweep and return an unbiased estimate of the log evidence. -The resampling steps use the given `resampler`. -# Reference -Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. -Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(3), 411-436. -""" -function sweep!(pc::ParticleContainer, resampler) - # Initial step: - - # Resample and propagate particles. - resample_propagate!(pc, resampler) - - # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic - # weights. - # Usually it is equal to the number of particles in the beginning but this - # implementation covers also the unlikely case of a particle container that is - # initialized with non-zero logarithmic weights. - logZ0 = logZ(pc) - - # Reweight the particles by including the first observation ``y₁``. - isdone = reweight!(pc) - - # Compute the normalizing constant ``Z₁`` after reweighting. - logZ1 = logZ(pc) - - # Compute the estimate of the log evidence ``\\log p(y₁)``. - logevidence = logZ1 - logZ0 - - # For observations ``y₂, …, yₜ``: - while !isdone - # Resample and propagate particles. - resample_propagate!(pc, resampler) - - # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic - # weights. - logZ0 = logZ(pc) - - # Reweight the particles by including the next observation ``yₜ``. - isdone = reweight!(pc) - - # Compute the normalizing constant ``Z₁`` after reweighting. - logZ1 = logZ(pc) - - # Compute the estimate of the log evidence ``\\log p(y₁, …, yₜ)``. - logevidence += logZ1 - logZ0 - end - - return logevidence -end - -struct ResampleWithESSThreshold{R, T<:Real} - resampler::R - threshold::T -end - -function ResampleWithESSThreshold(resampler = Turing.Inference.resample_systematic) - ResampleWithESSThreshold(resampler, 0.5) -end - -function resample_propagate!( - pc::ParticleContainer, - resampler::ResampleWithESSThreshold, - ref::Union{Particle,Nothing} = nothing; - weights = getweights(pc) -) - # Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ`` - ess = inv(sum(abs2, weights)) - - if ess ≤ resampler.threshold * length(pc) - resample_propagate!(pc, resampler.resampler, ref; weights = weights) - end - - pc -end \ No newline at end of file diff --git a/resampling.jl b/resampling.jl index 25409aad..8c68f34f 100644 --- a/resampling.jl +++ b/resampling.jl @@ -1,3 +1,23 @@ +# TODO: 2 dichotomies between resamplers: +# - whether or not to use thresholds +# - whether to use systematic, residual, multinomial, or stratified resampling +# build a struct for all of this +# also the use of randcat for an implementation of rand(Categorical()) *and* as the name of the resampler in resample_propagate! is confusing + +#### +#### Resample only when ESS ≤ a preset value +#### + + +# modifies dispatch in resample_propagate! +struct ResampleWithESSThreshold{R, T<:Real} + resampler::R + threshold::T +end + +function ResampleWithESSThreshold(resampler = resample_systematic) + ResampleWithESSThreshold(resampler, 0.5) +end #### #### Resampling schemes for particle filters @@ -8,11 +28,6 @@ # - http://people.isy.liu.se/rt/schon/Publications/HolSG2006.pdf # Code adapted from: http://uk.mathworks.com/matlabcentral/fileexchange/24968-resampling-methods-for-particle-filtering -# Default resampling scheme -function resample(w::AbstractVector{<:Real}, num_particles::Integer=length(w)) - return resample_systematic(w, num_particles) -end - # More stable, faster version of rand(Categorical) function randcat(p::AbstractVector{<:Real}) T = eltype(p) @@ -28,10 +43,26 @@ function randcat(p::AbstractVector{<:Real}) return s end +""" + resample(w, num_particles) +Default resampling scheme: systematic resampling +""" +function resample(w::AbstractVector{<:Real}, num_particles::Integer=length(w)) + return resample_systematic(w, num_particles) +end + +""" + resample_multinomial(w, num_particles) +Multinomial resampling scheme +""" function resample_multinomial(w::AbstractVector{<:Real}, num_particles::Integer) return rand(Distributions.sampler(Categorical(w)), num_particles) end +""" + resample_residual(w, num_particles) +Residual resampling scheme +""" function resample_residual(w::AbstractVector{<:Real}, num_particles::Integer) M = length(w) @@ -57,7 +88,7 @@ function resample_residual(w::AbstractVector{<:Real}, num_particles::Integer) end end - # And now draw the stocastic (Multinomial) part: + # And now draw the stochastic (Multinomial) part: return append!(indx1, rand(Distributions.sampler(Categorical(w)), M_rdn)) end diff --git a/sweep.jl b/sweep.jl new file mode 100644 index 00000000..1b5a4e5d --- /dev/null +++ b/sweep.jl @@ -0,0 +1,180 @@ +# TODO: + +""" +resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; + weights = getweights(pc)]) +Resample and propagate the particles in `pc`. +Function `randcat` is used for sampling ancestor indices from the categorical distribution +of the particle `weights`. For Particle Gibbs sampling, one can provide a reference particle +`ref` that is ensured to survive the resampling step. +""" +function resample_propagate!( +pc::ParticleContainer, +randcat = resample_systematic, +ref::Union{Particle, Nothing} = nothing; +weights = getweights(pc) +) +# check that weights are not NaN +@assert !any(isnan, weights) + +# sample ancestor indices +n = length(pc) +nresamples = ref === nothing ? n : n - 1 +indx = randcat(weights, nresamples) + +# count number of children for each particle +num_children = zeros(Int, n) +@inbounds for i in indx + num_children[i] += 1 +end + +# fork particles +particles = collect(pc) +children = similar(particles) +j = 0 +@inbounds for i in 1:n + ni = num_children[i] + + if ni > 0 + # fork first child + pi = particles[i] + isref = pi === ref + p = isref ? fork(pi, isref) : pi + children[j += 1] = p + + # fork additional children + for _ in 2:ni + children[j += 1] = fork(p, isref) + end + end +end + +if ref !== nothing + # Insert the retained particle. This is based on the replaying trick for efficiency + # reasons. If we implement PG using task copying, we need to store Nx * T particles! + @inbounds children[n] = ref +end + +# replace particles and log weights in the container with new particles and weights +pc.vals = children +reset_logweights!(pc) + +pc +end + + + +function resample_propagate!( +pc::ParticleContainer, +resampler::ResampleWithESSThreshold, +ref::Union{Particle,Nothing} = nothing; +weights = getweights(pc) +) +# Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ`` +ess = inv(sum(abs2, weights)) + +if ess ≤ resampler.threshold * length(pc) + resample_propagate!(pc, resampler.resampler, ref; weights = weights) +end + +pc +end + + +""" +reweight!(pc::ParticleContainer) +Check if the final time step is reached, and otherwise reweight the particles by +considering the next observation. +""" +function reweight!(pc::ParticleContainer) +n = length(pc) + +particles = collect(pc) +numdone = 0 +for i in 1:n + p = particles[i] + + # Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the + # the execution of the model is finished. + # Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and + # ``θᵢ`` are variables of other samplers. + score = Libtask.consume(p) + + if score === nothing + numdone += 1 + else + # Increase the unnormalized logarithmic weights, accounting for the variables + # of other samplers. + increase_logweight!(pc, i, score + getlogp(p.vi)) + + # Reset the accumulator of the log probability in the model so that we can + # accumulate log probabilities of variables of other samplers until the next + # observation. + resetlogp!(p.vi) + end +end + +# Check if all particles are propagated to the final time point. +numdone == n && return true + +# The posterior for models with random number of observations is not well-defined. +if numdone != 0 + error("mis-aligned execution traces: # particles = ", n, + " # completed trajectories = ", numdone, + ". Please make sure the number of observations is NOT random.") +end + +return false +end + +""" +sweep!(pc::ParticleContainer, resampler) +Perform a particle sweep and return an unbiased estimate of the log evidence. +The resampling steps use the given `resampler`. +# Reference +Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. +Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(3), 411-436. +""" +function sweep!(pc::ParticleContainer, resampler) +# Initial step: + +# Resample and propagate particles. +resample_propagate!(pc, resampler) + +# Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic +# weights. +# Usually it is equal to the number of particles in the beginning but this +# implementation covers also the unlikely case of a particle container that is +# initialized with non-zero logarithmic weights. +logZ0 = logZ(pc) + +# Reweight the particles by including the first observation ``y₁``. +isdone = reweight!(pc) + +# Compute the normalizing constant ``Z₁`` after reweighting. +logZ1 = logZ(pc) + +# Compute the estimate of the log evidence ``\\log p(y₁)``. +logevidence = logZ1 - logZ0 + +# For observations ``y₂, …, yₜ``: +while !isdone + # Resample and propagate particles. + resample_propagate!(pc, resampler) + + # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic + # weights. + logZ0 = logZ(pc) + + # Reweight the particles by including the next observation ``yₜ``. + isdone = reweight!(pc) + + # Compute the normalizing constant ``Z₁`` after reweighting. + logZ1 = logZ(pc) + + # Compute the estimate of the log evidence ``\\log p(y₁, …, yₜ)``. + logevidence += logZ1 - logZ0 +end + +return logevidence +end From 87a80223e2d92bc0422b1677e30d6d5e91911173 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Mon, 22 Jun 2020 13:45:26 +0200 Subject: [PATCH 05/44] build package structure --- Project.toml | 6 ++++++ AdvancedSMC.jl => src/AdvancedSMC.jl | 0 particlecontainer.jl => src/particlecontainer.jl | 0 resampling.jl => src/resampling.jl | 0 sweep.jl => src/sweep.jl | 0 trace.jl => src/trace.jl | 0 6 files changed, 6 insertions(+) create mode 100644 Project.toml rename AdvancedSMC.jl => src/AdvancedSMC.jl (100%) rename particlecontainer.jl => src/particlecontainer.jl (100%) rename resampling.jl => src/resampling.jl (100%) rename sweep.jl => src/sweep.jl (100%) rename trace.jl => src/trace.jl (100%) diff --git a/Project.toml b/Project.toml new file mode 100644 index 00000000..28d783af --- /dev/null +++ b/Project.toml @@ -0,0 +1,6 @@ +name = "AdvancedSMC" +uuid = "9c00393c-822d-4781-8df5-4c3c33f9866d" +authors = ["JS Denain "] +version = "0.1.0" + + diff --git a/AdvancedSMC.jl b/src/AdvancedSMC.jl similarity index 100% rename from AdvancedSMC.jl rename to src/AdvancedSMC.jl diff --git a/particlecontainer.jl b/src/particlecontainer.jl similarity index 100% rename from particlecontainer.jl rename to src/particlecontainer.jl diff --git a/resampling.jl b/src/resampling.jl similarity index 100% rename from resampling.jl rename to src/resampling.jl diff --git a/sweep.jl b/src/sweep.jl similarity index 100% rename from sweep.jl rename to src/sweep.jl diff --git a/trace.jl b/src/trace.jl similarity index 100% rename from trace.jl rename to src/trace.jl From 07468630c960a3195b54c2153c28e404896ba6ce Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 23 Jun 2020 13:11:32 +0200 Subject: [PATCH 06/44] update dependencies and reorder exports --- Manifest.toml | 70 ++++++++++++++++++++++++++++++++++++++++++++++ Project.toml | 3 +- src/AdvancedSMC.jl | 25 +++++++++-------- 3 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 00000000..2bb04931 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,70 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinaryProvider]] +deps = ["Libdl", "Logging", "SHA"] +git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.10" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[LibGit2]] +deps = ["Printf"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[Libtask]] +deps = ["BinaryProvider", "Libdl", "Pkg"] +git-tree-sha1 = "68a658db4792dfc468ea2aabcf06f3f74f153f23" +uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" +version = "0.4.1" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/Project.toml b/Project.toml index 28d783af..4ef16b27 100644 --- a/Project.toml +++ b/Project.toml @@ -3,4 +3,5 @@ uuid = "9c00393c-822d-4781-8df5-4c3c33f9866d" authors = ["JS Denain "] version = "0.1.0" - +[deps] +Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index a911f798..d7c7ce86 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -5,6 +5,14 @@ import Libtask, # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions +include("trace.jl") +export Trace, + fork, + forkr, + current_trace, + Particle + + include("particlecontainer.jl") export ParticleContainer, reset_logweights!, @@ -14,11 +22,6 @@ export ParticleContainer, logZ, effectiveSampleSize -include("sweep.jl") -export resample_propagate!, - reweight!, - sweep! - include("resampling.jl") export ResampleWithESSThreshold, resample, @@ -28,11 +31,9 @@ export ResampleWithESSThreshold, resample_stratified, resample_systematic -include("trace.jl") -export Trace, - fork, - forkr, - current_trace, - Particle - +include("sweep.jl") +export resample_propagate!, + reweight!, + sweep! + end \ No newline at end of file From 4ddb0b9cd4172ca75665546cf16653315504917b Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 08:46:16 +0200 Subject: [PATCH 07/44] import AbstractMCMC --- src/AdvancedSMC.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index d7c7ce86..c1b96702 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -1,7 +1,7 @@ module AdvancedSMC import Libtask, - Random # doesn't seem like there is anything else to import? DynamicPPL and AbstractMCMC interfacing is handled in inference/ - + Random, + AbstractMCMC # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions @@ -35,5 +35,5 @@ include("sweep.jl") export resample_propagate!, reweight!, sweep! - + end \ No newline at end of file From 0c7a88a49623a9002dbb5f7e1065637904d67f3d Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 08:50:29 +0200 Subject: [PATCH 08/44] replace import by using --- Manifest.toml | 101 +++++++++++++++++++++++++++++++++++++++++++++ Project.toml | 1 + src/AdvancedSMC.jl | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/Manifest.toml b/Manifest.toml index 2bb04931..bbda783d 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,5 +1,17 @@ # This file is machine-generated - editing it directly is not advised +[[AbstractMCMC]] +deps = ["ConsoleProgressMonitor", "Distributed", "Logging", "LoggingExtras", "ProgressLogging", "Random", "StatsBase", "TerminalLoggers"] +git-tree-sha1 = "31a0a7b957525748e05599488ca6eef476fef12b" +uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001" +version = "1.0.1" + +[[AbstractTrees]] +deps = ["Markdown"] +git-tree-sha1 = "33e450545eaf7699da1a6e755f9ea65f14077a45" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.3.3" + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -9,14 +21,41 @@ git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.5.10" +[[ConsoleProgressMonitor]] +deps = ["Logging", "ProgressMeter"] +git-tree-sha1 = "3ab7b2136722890b9af903859afcf457fa3059e8" +uuid = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b" +version = "0.1.2" + +[[DataAPI]] +git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.3.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.17.18" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + [[InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[LeftChildRightSiblingTrees]] +deps = ["AbstractTrees"] +git-tree-sha1 = "71be1eb5ad19cb4f61fa8c73395c0338fd092ae0" +uuid = "1d6d02ad-be62-4b6b-8a6d-2f90e265016e" +version = "0.1.2" + [[LibGit2]] deps = ["Printf"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" @@ -30,13 +69,33 @@ git-tree-sha1 = "68a658db4792dfc468ea2aabcf06f3f74f153f23" uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" version = "0.4.1" +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + [[Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" +[[LoggingExtras]] +git-tree-sha1 = "b60616c70eff0cc2c0831b6aace75940aeb0939d" +uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" +version = "0.4.1" + [[Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" +[[Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.3" + +[[OrderedCollections]] +git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.2.0" + [[Pkg]] deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -45,6 +104,18 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" +[[ProgressLogging]] +deps = ["Logging", "SHA", "UUIDs"] +git-tree-sha1 = "59398022b661b6fd569f25de6b18fde39843196a" +uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c" +version = "0.1.3" + +[[ProgressMeter]] +deps = ["Distributed", "Printf"] +git-tree-sha1 = "3e1784c27847bba115815d4d4e668b99873985e5" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "1.3.1" + [[REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" @@ -62,6 +133,36 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"] +git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.33.0" + +[[TerminalLoggers]] +deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] +git-tree-sha1 = "cbea752b5eef52a3e1188fb31580c3e4fa0cbc35" +uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" +version = "0.1.2" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" diff --git a/Project.toml b/Project.toml index 4ef16b27..aab7627e 100644 --- a/Project.toml +++ b/Project.toml @@ -4,4 +4,5 @@ authors = ["JS Denain "] version = "0.1.0" [deps] +AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index c1b96702..3e64ee3f 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -1,5 +1,5 @@ module AdvancedSMC -import Libtask, +using Libtask, Random, AbstractMCMC # must I export overloaded Base functions? From 99c52627689737ebcaafa969222bc66674b19e09 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 08:58:14 +0200 Subject: [PATCH 09/44] add prefix in front of AbstractSampler --- src/trace.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace.jl b/src/trace.jl index 1903f3c7..3d39d528 100644 --- a/src/trace.jl +++ b/src/trace.jl @@ -1,4 +1,4 @@ -mutable struct Trace{Tspl<:AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} +mutable struct Trace{Tspl<:AbstractMCMC.AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} model::Tmodel spl::Tspl vi::Tvi From bddb3a57d2abe88883f9b8f03ebba2b7864316e3 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 09:10:22 +0200 Subject: [PATCH 10/44] export specific functions --- Manifest.toml | 157 +++++++++++++++++++++++++++++++++++++++++++++ Project.toml | 1 + src/AdvancedSMC.jl | 8 ++- src/trace.jl | 2 +- 4 files changed, 164 insertions(+), 4 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index bbda783d..4565587a 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -12,15 +12,50 @@ git-tree-sha1 = "33e450545eaf7699da1a6e755f9ea65f14077a45" uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" version = "0.3.3" +[[ArgCheck]] +git-tree-sha1 = "59c256cf71c3982484ae4486ee86a3d7da891dea" +uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" +version = "2.0.0" + +[[Arpack]] +deps = ["Arpack_jll", "Libdl", "LinearAlgebra"] +git-tree-sha1 = "2ff92b71ba1747c5fdd541f8fc87736d82f40ec9" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.4.0" + +[[Arpack_jll]] +deps = ["Libdl", "OpenBLAS_jll", "Pkg"] +git-tree-sha1 = "e214a9b9bd1b4e1b4f15b22c0994862b66af7ff7" +uuid = "68821587-b530-5797-8361-c406ea357684" +version = "3.5.0+3" + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +[[Bijectors]] +deps = ["ArgCheck", "Compat", "Distributions", "LinearAlgebra", "MappedArrays", "NNlib", "Random", "Reexport", "Requires", "Roots", "SparseArrays", "Statistics", "StatsFuns"] +git-tree-sha1 = "84836b7f35952ec814869174f0e55a385b7d00cd" +uuid = "76274a88-744f-5084-9051-94815aaf08c4" +version = "0.8.0" + [[BinaryProvider]] deps = ["Libdl", "Logging", "SHA"] git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.5.10" +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "054993b6611376ddb40203e973e954fd9d1d1902" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "3.12.0" + +[[CompilerSupportLibraries_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612" +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "0.3.3+0" + [[ConsoleProgressMonitor]] deps = ["Logging", "ProgressMeter"] git-tree-sha1 = "3ab7b2136722890b9af903859afcf457fa3059e8" @@ -42,10 +77,32 @@ version = "0.17.18" deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + [[Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" +[[Distributions]] +deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"] +git-tree-sha1 = "78c4c32a2357a00a0a7d614880f02c2c6e1ec73c" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.23.4" + +[[DynamicPPL]] +deps = ["AbstractMCMC", "Bijectors", "Distributions", "MacroTools", "Random", "ZygoteRules"] +git-tree-sha1 = "b46046c78801149cc9f2b80e806fbd5a2891b652" +uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" +version = "0.8.2" + +[[FillArrays]] +deps = ["LinearAlgebra", "Random", "SparseArrays"] +git-tree-sha1 = "bf726ba7ce99e00d10bf63c031285fb9ab3676ae" +uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" +version = "0.8.11" + [[InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" @@ -81,6 +138,17 @@ git-tree-sha1 = "b60616c70eff0cc2c0831b6aace75940aeb0939d" uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" version = "0.4.1" +[[MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.5" + +[[MappedArrays]] +git-tree-sha1 = "e2a02fe7ee86a10c707ff1756ab1650b40b140bb" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.2" + [[Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" @@ -91,11 +159,38 @@ git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" version = "0.4.3" +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Requires", "Statistics"] +git-tree-sha1 = "d9f196d911f55aeaff11b11f681b135980783824" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.6.6" + +[[OpenBLAS_jll]] +deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] +git-tree-sha1 = "1887096f6897306a4662f7c5af936da7d5d1a062" +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" +version = "0.3.9+4" + +[[OpenSpecFun_jll]] +deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] +git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" +uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" +version = "0.5.3+3" + [[OrderedCollections]] git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" version = "1.2.0" +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "2fc6f50ddd959e462f0a2dbc802ddf2a539c6e35" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.12" + [[Pkg]] deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -116,6 +211,12 @@ git-tree-sha1 = "3e1784c27847bba115815d4d4e668b99873985e5" uuid = "92933f4c-e287-5a05-a399-4b506db050ca" version = "1.3.1" +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra"] +git-tree-sha1 = "dc84e810393cfc6294248c9032a9cdacc14a3db4" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.3.1" + [[REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" @@ -124,12 +225,46 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["UUIDs"] +git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "1.0.1" + +[[Rmath]] +deps = ["Random", "Rmath_jll"] +git-tree-sha1 = "86c5647b565873641538d8f812c04e4c9dbeb370" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.6.1" + +[[Rmath_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "d76185aa1f421306dec73c057aa384bad74188f0" +uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" +version = "0.2.2+1" + +[[Roots]] +deps = ["Printf"] +git-tree-sha1 = "c2f7348c55d1433d1cab0159b4d2c6d27af36fc4" +uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" +version = "1.0.2" + [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" @@ -143,6 +278,12 @@ version = "0.3.1" deps = ["LinearAlgebra", "Random"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +[[SpecialFunctions]] +deps = ["OpenSpecFun_jll"] +git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.10.3" + [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" @@ -153,6 +294,16 @@ git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45" uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" version = "0.33.0" +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions"] +git-tree-sha1 = "04a5a8e6ab87966b43f247920eab053fd5fdc925" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.9.5" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + [[TerminalLoggers]] deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] git-tree-sha1 = "cbea752b5eef52a3e1188fb31580c3e4fa0cbc35" @@ -169,3 +320,9 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[ZygoteRules]] +deps = ["MacroTools"] +git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" +uuid = "700de1a5-db45-46bc-99cf-38207098b444" +version = "0.2.0" diff --git a/Project.toml b/Project.toml index aab7627e..59cbe0b6 100644 --- a/Project.toml +++ b/Project.toml @@ -5,4 +5,5 @@ version = "0.1.0" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" +DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index 3e64ee3f..eca5bd27 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -1,7 +1,9 @@ module AdvancedSMC -using Libtask, - Random, - AbstractMCMC +using Libtask +using Random +using AbstractMCMC: AbstractSampler +using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler + # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions diff --git a/src/trace.jl b/src/trace.jl index 3d39d528..1903f3c7 100644 --- a/src/trace.jl +++ b/src/trace.jl @@ -1,4 +1,4 @@ -mutable struct Trace{Tspl<:AbstractMCMC.AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} +mutable struct Trace{Tspl<:AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} model::Tmodel spl::Tspl vi::Tvi From 77e2729fa64c47957b5f510ad1f5ef2ac839471f Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 11:11:38 +0200 Subject: [PATCH 11/44] add functions from DynamicPPL --- src/AdvancedSMC.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index eca5bd27..9137f662 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -1,8 +1,9 @@ module AdvancedSMC -using Libtask +using Libtask using Random using AbstractMCMC: AbstractSampler -using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler +using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler, reset_num_produce!, set_retained_vns_del_by_spl!, increment_num_produce!, getlogp, resetlogp! +using Distributions # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions From 8e906404696d9febe4928635f98225b7fabbba40 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 11:29:28 +0200 Subject: [PATCH 12/44] add StatsFuns --- Project.toml | 1 + src/AdvancedSMC.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index 59cbe0b6..0e135e5e 100644 --- a/Project.toml +++ b/Project.toml @@ -7,3 +7,4 @@ version = "0.1.0" AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" +StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index 9137f662..c032b863 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -4,6 +4,7 @@ using Random using AbstractMCMC: AbstractSampler using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler, reset_num_produce!, set_retained_vns_del_by_spl!, increment_num_produce!, getlogp, resetlogp! using Distributions +using StatsFuns # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions From 44ae13823dacc83964a36463c3a0540862fcab42 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 11:34:21 +0200 Subject: [PATCH 13/44] add softmax and logsumexp to used StatsFuns functions --- src/AdvancedSMC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index c032b863..d79335c3 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -4,7 +4,7 @@ using Random using AbstractMCMC: AbstractSampler using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler, reset_num_produce!, set_retained_vns_del_by_spl!, increment_num_produce!, getlogp, resetlogp! using Distributions -using StatsFuns +using StatsFuns: softmax, logsumexp # must I export overloaded Base functions? # perhaps: Inference.jl exports overloaded DynamicPPL functions From 32ee17feb6f7b162cc5edb3d51c204e9b54254a7 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 12:08:57 +0200 Subject: [PATCH 14/44] add Rando --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 0e135e5e..391fc29a 100644 --- a/Project.toml +++ b/Project.toml @@ -7,4 +7,5 @@ version = "0.1.0" AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" From c1a6f1c6605fb659e8ba0e7a1ad5637f45340246 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 24 Jun 2020 12:17:28 +0200 Subject: [PATCH 15/44] add Distributions --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 391fc29a..4fe861a3 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.1.0" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" From 19ec20173346b62a1ba441587a4f25f8b3612920 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 08:47:21 +0200 Subject: [PATCH 16/44] add test folder --- test/particlecontainer.jl | 0 test/resampling.jl | 16 ++++++++++++++++ test/runtests.jl | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 test/particlecontainer.jl create mode 100644 test/resampling.jl create mode 100644 test/runtests.jl diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl new file mode 100644 index 00000000..e69de29b diff --git a/test/resampling.jl b/test/resampling.jl new file mode 100644 index 00000000..3fc35221 --- /dev/null +++ b/test/resampling.jl @@ -0,0 +1,16 @@ +@turing_testset "resample.jl" begin + D = [0.3, 0.4, 0.3] + num_samples = Int(1e6) + resSystematic = resample_systematic(D, num_samples ) + resStratified = resample_stratified(D, num_samples ) + resMultinomial= resample_multinomial(D, num_samples ) + resResidual = resample_residual(D, num_samples ) + resample(D) + resSystematic2=resample(D, num_samples ) + + @test sum(resSystematic .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples + @test sum(resSystematic2 .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples + @test sum(resStratified .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples + @test sum(resMultinomial .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples + @test sum(resResidual .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 00000000..27e90000 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,2 @@ +using Test +using AdvancedSMC \ No newline at end of file From 0057ecc442e1326b7697c9711d82e2d7646c1361 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 08:51:10 +0200 Subject: [PATCH 17/44] add Test --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 4fe861a3..0154a83e 100644 --- a/Project.toml +++ b/Project.toml @@ -10,3 +10,4 @@ DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From 1da316834f7833175af2db9d274fe063bcd58397 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 08:56:37 +0200 Subject: [PATCH 18/44] replace @turing_testset by @testset, make resampling tests work --- test/resampling.jl | 2 +- test/runtests.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/resampling.jl b/test/resampling.jl index 3fc35221..473e748e 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -1,4 +1,4 @@ -@turing_testset "resample.jl" begin +@testset "resample.jl" begin D = [0.3, 0.4, 0.3] num_samples = Int(1e6) resSystematic = resample_systematic(D, num_samples ) diff --git a/test/runtests.jl b/test/runtests.jl index 27e90000..54255f44 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,2 +1,4 @@ using Test -using AdvancedSMC \ No newline at end of file +using AdvancedSMC + +include("resampling.jl") \ No newline at end of file From 6c46e1edfb4d950c4a15ce3d47f25f67d47d0f6f Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 09:30:49 +0200 Subject: [PATCH 19/44] add tests that were in test/core/container.jl --- test/particlecontainer.jl | 86 +++++++++++++++++++++++++++++++++++++++ test/resampling.jl | 5 ++- test/trace.jl | 35 ++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/trace.jl diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index e69de29b..8f8d92a1 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -0,0 +1,86 @@ +using AdvancedSMC +using Test + +@testset "particlecontainer.jl" begin + @testset "copy particle container" begin + pc = ParticleContainer(Trace[]) + newpc = copy(pc) + + @test newpc.logWs == pc.logWs + @test typeof(pc) === typeof(newpc) + end + + @testset "particle container" begin + # Create a resumable function that always yields `logp`. + function fpc(logp) + f = let logp = logp + () -> begin + while true + produce(logp) + end + end + end + return f + end + + # Dummy sampler that is not actually used. + sampler = Sampler(PG(5), empty_model()) + + # Create particle container. + logps = [0.0, -1.0, -2.0] + particles = [Trace(fpc(logp), empty_model(), sampler, VarInfo()) for logp in logps] + pc = ParticleContainer(particles) + + # Initial state. + @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) + @test pc.logWs == zeros(3) + @test getweights(pc) == fill(1/3, 3) + @test all(getweight(pc, i) == 1/3 for i in 1:3) + @test logZ(pc) ≈ log(3) + @test effectiveSampleSize(pc) == 3 + + # Reweight particles. + reweight!(pc) + @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) + @test pc.logWs == logps + @test getweights(pc) ≈ exp.(logps) ./ sum(exp, logps) + @test all(getweight(pc, i) ≈ exp(logps[i]) / sum(exp, logps) for i in 1:3) + @test logZ(pc) == log(sum(exp, logps)) + + # Reweight particles. + reweight!(pc) + @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) + @test pc.logWs == 2 .* logps + @test getweights(pc) == exp.(2 .* logps) ./ sum(exp, 2 .* logps) + @test all(getweight(pc, i) ≈ exp(2 * logps[i]) / sum(exp, 2 .* logps) for i in 1:3) + @test logZ(pc) == log(sum(exp, 2 .* logps)) + + # Resample and propagate particles. + resample_propagate!(pc) + @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) + @test pc.logWs == zeros(3) + @test getweights(pc) == fill(1/3, 3) + @test all(getweight(pc, i) == 1/3 for i in 1:3) + @test logZ(pc) ≈ log(3) + @test effectiveSampleSize(pc) == 3 + + # Reweight particles. + reweight!(pc) + @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) + @test pc.logWs ⊆ logps + @test getweights(pc) == exp.(pc.logWs) ./ sum(exp, pc.logWs) + @test all(getweight(pc, i) ≈ exp(pc.logWs[i]) / sum(exp, pc.logWs) for i in 1:3) + @test logZ(pc) == log(sum(exp, pc.logWs)) + + # Increase unnormalized logarithmic weights. + logws = copy(pc.logWs) + increase_logweight!(pc, 2, 1.41) + @test pc.logWs == logws + [0, 1.41, 0] + + # Reset unnormalized logarithmic weights. + logws = pc.logWs + reset_logweights!(pc) + @test pc.logWs === logws + @test all(iszero, pc.logWs) + end +end diff --git a/test/resampling.jl b/test/resampling.jl index 473e748e..a8de69b2 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -1,4 +1,7 @@ -@testset "resample.jl" begin +using Test +using AdvancedSMC + +@testset "resampling.jl" begin D = [0.3, 0.4, 0.3] num_samples = Int(1e6) resSystematic = resample_systematic(D, num_samples ) diff --git a/test/trace.jl b/test/trace.jl new file mode 100644 index 00000000..0cda2dda --- /dev/null +++ b/test/trace.jl @@ -0,0 +1,35 @@ +using AdvancedSMC +using Test + +@testset "trace.jl" begin + n = Ref(0) + + alg = PG(5) + spl = Sampler(alg, empty_model()) + dist = Normal(0, 1) + function f2() + t = TArray(Int, 1); + t[1] = 0; + while true + ct = current_trace() + vn = @varname x[n] + Turing.assume(Random.GLOBAL_RNG, spl, dist, vn, ct.vi) + n[] += 1 + produce(t[1]) + vn = @varname x[n] + Turing.assume(Random.GLOBAL_RNG, spl, dist, vn, ct.vi) + n[] += 1 + t[1] = 1 + t[1] + end + end + + # Test task copy version of trace + tr = Trace(f2, empty_model(), spl, VarInfo()) + + consume(tr); consume(tr) + a = fork(tr); + consume(a); consume(a) + + @test consume(tr) == 2 + @test consume(a) == 4 + end \ No newline at end of file From b1b58cbd440c85d6fa711960450bd0dceaa1fdc3 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 09:46:56 +0200 Subject: [PATCH 20/44] removed trace.jl --- test/runtests.jl | 3 ++- test/trace.jl | 35 ----------------------------------- 2 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 test/trace.jl diff --git a/test/runtests.jl b/test/runtests.jl index 54255f44..719e380f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using Test using AdvancedSMC -include("resampling.jl") \ No newline at end of file +include("resampling.jl") +include("particlecontainer.jl") \ No newline at end of file diff --git a/test/trace.jl b/test/trace.jl deleted file mode 100644 index 0cda2dda..00000000 --- a/test/trace.jl +++ /dev/null @@ -1,35 +0,0 @@ -using AdvancedSMC -using Test - -@testset "trace.jl" begin - n = Ref(0) - - alg = PG(5) - spl = Sampler(alg, empty_model()) - dist = Normal(0, 1) - function f2() - t = TArray(Int, 1); - t[1] = 0; - while true - ct = current_trace() - vn = @varname x[n] - Turing.assume(Random.GLOBAL_RNG, spl, dist, vn, ct.vi) - n[] += 1 - produce(t[1]) - vn = @varname x[n] - Turing.assume(Random.GLOBAL_RNG, spl, dist, vn, ct.vi) - n[] += 1 - t[1] = 1 + t[1] - end - end - - # Test task copy version of trace - tr = Trace(f2, empty_model(), spl, VarInfo()) - - consume(tr); consume(tr) - a = fork(tr); - consume(a); consume(a) - - @test consume(tr) == 2 - @test consume(a) == 4 - end \ No newline at end of file From 39b79a22ac393359ba7e2fa425025622cd39b1b0 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 10:05:15 +0200 Subject: [PATCH 21/44] remove trace.jl --- src/particlecontainer.jl | 2 ++ src/trace.jl | 78 ---------------------------------------- 2 files changed, 2 insertions(+), 78 deletions(-) delete mode 100644 src/trace.jl diff --git a/src/particlecontainer.jl b/src/particlecontainer.jl index cd3f545e..1e5577e8 100644 --- a/src/particlecontainer.jl +++ b/src/particlecontainer.jl @@ -1,3 +1,5 @@ +using Turing.Core +const Particle = Trace """ Data structure for particle filters diff --git a/src/trace.jl b/src/trace.jl deleted file mode 100644 index 1903f3c7..00000000 --- a/src/trace.jl +++ /dev/null @@ -1,78 +0,0 @@ -mutable struct Trace{Tspl<:AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} - model::Tmodel - spl::Tspl - vi::Tvi - ctask::CTask - - function Trace{SampleFromPrior}(model::Model, spl::AbstractSampler, vi::AbstractVarInfo) - return new{SampleFromPrior,typeof(vi),typeof(model)}(model, SampleFromPrior(), vi) - end - function Trace{S}(model::Model, spl::S, vi::AbstractVarInfo) where S<:Sampler - return new{S,typeof(vi),typeof(model)}(model, spl, vi) - end -end - -function Base.copy(trace::Trace) - vi = deepcopy(trace.vi) - res = Trace{typeof(trace.spl)}(trace.model, trace.spl, vi) - res.ctask = copy(trace.ctask) - return res -end - -# NOTE: this function is called by `forkr` -function Trace(f, m::Model, spl::AbstractSampler, vi::AbstractVarInfo) - res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) - ctask = CTask() do - res = f() - produce(nothing) - return res - end - task = ctask.task - if task.storage === nothing - task.storage = IdDict() - end - task.storage[:turing_trace] = res # create a backward reference in task_local_storage - res.ctask = ctask - return res -end - -function Trace(m::Model, spl::AbstractSampler, vi::AbstractVarInfo) - res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) - reset_num_produce!(res.vi) - ctask = CTask() do - res = m(vi, spl) - produce(nothing) - return res - end - task = ctask.task - if task.storage === nothing - task.storage = IdDict() - end - task.storage[:turing_trace] = res # create a backward reference in task_local_storage - res.ctask = ctask - return res -end - -# step to the next observe statement, return log likelihood -Libtask.consume(t::Trace) = (increment_num_produce!(t.vi); consume(t.ctask)) - -# Task copying version of fork for Trace. -function fork(trace :: Trace, is_ref :: Bool = false) - newtrace = copy(trace) - is_ref && set_retained_vns_del_by_spl!(newtrace.vi, newtrace.spl) - newtrace.ctask.task.storage[:turing_trace] = newtrace - return newtrace -end - -# PG requires keeping all randomness for the reference particle -# Create new task and copy randomness -function forkr(trace::Trace) - newtrace = Trace(trace.ctask.task.code, trace.model, trace.spl, deepcopy(trace.vi)) - newtrace.spl = trace.spl - reset_num_produce!(newtrace.vi) - return newtrace -end - -current_trace() = current_task().storage[:turing_trace] - -const Particle = Trace \ No newline at end of file From 949e2cfd837fdb2e52930116a9ffede37b472ef7 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 26 Jun 2020 11:29:11 +0200 Subject: [PATCH 22/44] add TODOs --- src/AdvancedSMC.jl | 3 +-- src/particlecontainer.jl | 2 ++ test/particlecontainer.jl | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index d79335c3..50a1a076 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -6,9 +6,8 @@ using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler, reset_num_pr using Distributions using StatsFuns: softmax, logsumexp -# must I export overloaded Base functions? -# perhaps: Inference.jl exports overloaded DynamicPPL functions +# TODO: trace.jl no longer in AdvancedSMC.jl, must import Turing.jl/src/core/trace.jl include("trace.jl") export Trace, fork, diff --git a/src/particlecontainer.jl b/src/particlecontainer.jl index 1e5577e8..2cabda7d 100644 --- a/src/particlecontainer.jl +++ b/src/particlecontainer.jl @@ -1,3 +1,5 @@ +# TODO: find a way to import Turing.jl/src/core/trace.jl +# maybe do the import in AdvancedSMC.jl using Turing.Core const Particle = Trace diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index 8f8d92a1..334c3ade 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -1,3 +1,10 @@ +# TODO: this doesn't work because: +# 1. src/particlecontainer.jl doesn't import Turing/src/core/trace.jl well +# 2. some tests use turing/inference/: eg line 31 +# ====> decide which tests to move, and what to import + +# TODO: this tests functions in particlecontainer.jl but also sweep.jl ====> must rename + using AdvancedSMC using Test From 966c3ee4fd34ed75e3cbf4afeb17896913e26c72 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 1 Jul 2020 10:06:57 +0200 Subject: [PATCH 23/44] repair comments --- src/particlecontainer.jl | 3 +-- src/sweep.jl | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/particlecontainer.jl b/src/particlecontainer.jl index 2cabda7d..fea211a6 100644 --- a/src/particlecontainer.jl +++ b/src/particlecontainer.jl @@ -1,5 +1,4 @@ -# TODO: find a way to import Turing.jl/src/core/trace.jl -# maybe do the import in AdvancedSMC.jl +# TODO: Trace not recognized: it is a struct of trace.jl which currently lives in Turing.jl/src/core using Turing.Core const Particle = Trace diff --git a/src/sweep.jl b/src/sweep.jl index 1b5a4e5d..d2842a40 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -1,4 +1,4 @@ -# TODO: +# TODO: fork not recognized: it is a function from trace.jl which currently lives inside Turing.jl/src/core/ """ resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; From 8e8e018d392b24e60fe0a484f3b7209aa48f7659 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Wed, 1 Jul 2020 10:28:10 +0200 Subject: [PATCH 24/44] wrote import Turing.Core - doesn't want to add Turing or Turing.Core though --- src/AdvancedSMC.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index 50a1a076..77127b2c 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -8,13 +8,7 @@ using StatsFuns: softmax, logsumexp # TODO: trace.jl no longer in AdvancedSMC.jl, must import Turing.jl/src/core/trace.jl -include("trace.jl") -export Trace, - fork, - forkr, - current_trace, - Particle - +import Turing.Core include("particlecontainer.jl") export ParticleContainer, From 2d6c28c29b65f841155207f6a2d624e23b49dc4a Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 2 Jul 2020 09:48:40 +0200 Subject: [PATCH 25/44] specify Turing.Core imports --- src/AdvancedSMC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index 77127b2c..d28fbd50 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -8,7 +8,7 @@ using StatsFuns: softmax, logsumexp # TODO: trace.jl no longer in AdvancedSMC.jl, must import Turing.jl/src/core/trace.jl -import Turing.Core +import Turing.Core: Trace, fork, forkr include("particlecontainer.jl") export ParticleContainer, From 5bcfee304e739a42cd09f8377a0f764c18386bb7 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 2 Jul 2020 10:02:42 +0200 Subject: [PATCH 26/44] rename repo --- Project.toml | 2 +- README.md | 2 +- src/AdvancedSMC.jl | 4 ++-- test/particlecontainer.jl | 2 +- test/resampling.jl | 2 +- test/runtests.jl | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 0154a83e..ee1aa878 100644 --- a/Project.toml +++ b/Project.toml @@ -1,4 +1,4 @@ -name = "AdvancedSMC" +name = "AdvancedPS" uuid = "9c00393c-822d-4781-8df5-4c3c33f9866d" authors = ["JS Denain "] version = "0.1.0" diff --git a/README.md b/README.md index f0398e39..52d77f18 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# AdvancedSMC.jl \ No newline at end of file +# AdvancedPS.jl \ No newline at end of file diff --git a/src/AdvancedSMC.jl b/src/AdvancedSMC.jl index d28fbd50..9774e49a 100644 --- a/src/AdvancedSMC.jl +++ b/src/AdvancedSMC.jl @@ -1,4 +1,4 @@ -module AdvancedSMC +module AdvancedPS using Libtask using Random using AbstractMCMC: AbstractSampler @@ -7,7 +7,7 @@ using Distributions using StatsFuns: softmax, logsumexp -# TODO: trace.jl no longer in AdvancedSMC.jl, must import Turing.jl/src/core/trace.jl +# TODO: trace.jl no longer in AdvancedPS.jl package, must import Turing.jl/src/core/trace.jl import Turing.Core: Trace, fork, forkr include("particlecontainer.jl") diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index 334c3ade..2f13fc4a 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -5,7 +5,7 @@ # TODO: this tests functions in particlecontainer.jl but also sweep.jl ====> must rename -using AdvancedSMC +using AdvancedPS using Test @testset "particlecontainer.jl" begin diff --git a/test/resampling.jl b/test/resampling.jl index a8de69b2..2081bca9 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -1,5 +1,5 @@ using Test -using AdvancedSMC +using AdvancedPS @testset "resampling.jl" begin D = [0.3, 0.4, 0.3] diff --git a/test/runtests.jl b/test/runtests.jl index 719e380f..bafd4163 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Test -using AdvancedSMC +using AdvancedPS include("resampling.jl") include("particlecontainer.jl") \ No newline at end of file From f898d4f519d2604554f67b4112f35635226ad98e Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 2 Jul 2020 10:06:26 +0200 Subject: [PATCH 27/44] rename repo --- src/{AdvancedSMC.jl => AdvancedPS.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{AdvancedSMC.jl => AdvancedPS.jl} (100%) diff --git a/src/AdvancedSMC.jl b/src/AdvancedPS.jl similarity index 100% rename from src/AdvancedSMC.jl rename to src/AdvancedPS.jl From ffb37723a363fadb86cfa940af949a8079b38306 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 2 Jul 2020 13:51:06 +0200 Subject: [PATCH 28/44] add newlines at EOF --- README.md | 2 +- src/AdvancedPS.jl | 2 +- src/resampling.jl | 2 +- test/resampling.jl | 2 +- test/runtests.jl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 52d77f18..4c40f03e 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# AdvancedPS.jl \ No newline at end of file +# AdvancedPS.jl diff --git a/src/AdvancedPS.jl b/src/AdvancedPS.jl index 9774e49a..818c4c7d 100644 --- a/src/AdvancedPS.jl +++ b/src/AdvancedPS.jl @@ -33,4 +33,4 @@ export resample_propagate!, reweight!, sweep! -end \ No newline at end of file +end diff --git a/src/resampling.jl b/src/resampling.jl index 8c68f34f..46c2bcc6 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -177,4 +177,4 @@ function resample_systematic(weights::AbstractVector{<:Real}, n::Integer) end return samples -end \ No newline at end of file +end diff --git a/test/resampling.jl b/test/resampling.jl index 2081bca9..4556b07a 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -16,4 +16,4 @@ using AdvancedPS @test sum(resStratified .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples @test sum(resMultinomial .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples @test sum(resResidual .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index bafd4163..d392b1e4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,4 +2,4 @@ using Test using AdvancedPS include("resampling.jl") -include("particlecontainer.jl") \ No newline at end of file +include("particlecontainer.jl") From 6809d9e4b9e729591b7978fc1ac2da6e081a09f0 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 2 Jul 2020 14:36:59 +0200 Subject: [PATCH 29/44] add trace.jl --- src/AdvancedPS.jl | 8 +++-- src/particlecontainer.jl | 2 -- src/sweep.jl | 2 -- src/trace.jl | 76 +++++++++++++++++++++++++++++++++++++++ test/particlecontainer.jl | 6 +--- 5 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 src/trace.jl diff --git a/src/AdvancedPS.jl b/src/AdvancedPS.jl index 818c4c7d..ce2cfb78 100644 --- a/src/AdvancedPS.jl +++ b/src/AdvancedPS.jl @@ -6,9 +6,11 @@ using DynamicPPL: AbstractVarInfo, Model, SampleFromPrior, Sampler, reset_num_pr using Distributions using StatsFuns: softmax, logsumexp - -# TODO: trace.jl no longer in AdvancedPS.jl package, must import Turing.jl/src/core/trace.jl -import Turing.Core: Trace, fork, forkr +include("trace.jl") +export Trace, + fork, + forkr, + current_trace include("particlecontainer.jl") export ParticleContainer, diff --git a/src/particlecontainer.jl b/src/particlecontainer.jl index fea211a6..9ddc427d 100644 --- a/src/particlecontainer.jl +++ b/src/particlecontainer.jl @@ -1,5 +1,3 @@ -# TODO: Trace not recognized: it is a struct of trace.jl which currently lives in Turing.jl/src/core -using Turing.Core const Particle = Trace """ diff --git a/src/sweep.jl b/src/sweep.jl index d2842a40..a0269d9a 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -1,5 +1,3 @@ -# TODO: fork not recognized: it is a function from trace.jl which currently lives inside Turing.jl/src/core/ - """ resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; weights = getweights(pc)]) diff --git a/src/trace.jl b/src/trace.jl new file mode 100644 index 00000000..2b72fcf4 --- /dev/null +++ b/src/trace.jl @@ -0,0 +1,76 @@ +mutable struct Trace{Tspl<:AbstractSampler, Tvi<:AbstractVarInfo, Tmodel<:Model} + model::Tmodel + spl::Tspl + vi::Tvi + ctask::CTask + + function Trace{SampleFromPrior}(model::Model, spl::AbstractSampler, vi::AbstractVarInfo) + return new{SampleFromPrior,typeof(vi),typeof(model)}(model, SampleFromPrior(), vi) + end + function Trace{S}(model::Model, spl::S, vi::AbstractVarInfo) where S<:Sampler + return new{S,typeof(vi),typeof(model)}(model, spl, vi) + end +end + +function Base.copy(trace::Trace) + vi = deepcopy(trace.vi) + res = Trace{typeof(trace.spl)}(trace.model, trace.spl, vi) + res.ctask = copy(trace.ctask) + return res +end + +# NOTE: this function is called by `forkr` +function Trace(f, m::Model, spl::AbstractSampler, vi::AbstractVarInfo) + res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) + ctask = CTask() do + res = f() + produce(nothing) + return res + end + task = ctask.task + if task.storage === nothing + task.storage = IdDict() + end + task.storage[:turing_trace] = res # create a backward reference in task_local_storage + res.ctask = ctask + return res +end + +function Trace(m::Model, spl::AbstractSampler, vi::AbstractVarInfo) + res = Trace{typeof(spl)}(m, spl, deepcopy(vi)) + reset_num_produce!(res.vi) + ctask = CTask() do + res = m(vi, spl) + produce(nothing) + return res + end + task = ctask.task + if task.storage === nothing + task.storage = IdDict() + end + task.storage[:turing_trace] = res # create a backward reference in task_local_storage + res.ctask = ctask + return res +end + +# step to the next observe statement, return log likelihood +Libtask.consume(t::Trace) = (increment_num_produce!(t.vi); consume(t.ctask)) + +# Task copying version of fork for Trace. +function fork(trace :: Trace, is_ref :: Bool = false) + newtrace = copy(trace) + is_ref && set_retained_vns_del_by_spl!(newtrace.vi, newtrace.spl) + newtrace.ctask.task.storage[:turing_trace] = newtrace + return newtrace +end + +# PG requires keeping all randomness for the reference particle +# Create new task and copy randomness +function forkr(trace::Trace) + newtrace = Trace(trace.ctask.task.code, trace.model, trace.spl, deepcopy(trace.vi)) + newtrace.spl = trace.spl + reset_num_produce!(newtrace.vi) + return newtrace +end + +current_trace() = current_task().storage[:turing_trace] diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index 2f13fc4a..308f2185 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -1,8 +1,4 @@ -# TODO: this doesn't work because: -# 1. src/particlecontainer.jl doesn't import Turing/src/core/trace.jl well -# 2. some tests use turing/inference/: eg line 31 -# ====> decide which tests to move, and what to import - +# TODO: this doesn't work because some tests use turing/inference/: eg line 31 # TODO: this tests functions in particlecontainer.jl but also sweep.jl ====> must rename using AdvancedPS From 3a3d421998d29c45a5df71d27b2b4ed5fa6ce485 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Fri, 3 Jul 2020 12:33:15 +0200 Subject: [PATCH 30/44] particlecontainer.jl test still doesn't pass --- Manifest.toml | 536 ++++++++++++++++++++++++++++++++++++++ Project.toml | 1 + test/particlecontainer.jl | 6 +- 3 files changed, 541 insertions(+), 2 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 4565587a..cae7f1df 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,5 +1,11 @@ # This file is machine-generated - editing it directly is not advised +[[AbstractFFTs]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.5.0" + [[AbstractMCMC]] deps = ["ConsoleProgressMonitor", "Distributed", "Logging", "LoggingExtras", "ProgressLogging", "Random", "StatsBase", "TerminalLoggers"] git-tree-sha1 = "31a0a7b957525748e05599488ca6eef476fef12b" @@ -12,6 +18,18 @@ git-tree-sha1 = "33e450545eaf7699da1a6e755f9ea65f14077a45" uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" version = "0.3.3" +[[Adapt]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "fd04049c7dd78cfef0b06cdc1f0f181467655712" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "1.1.0" + +[[AdvancedHMC]] +deps = ["ArgCheck", "DocStringExtensions", "InplaceOps", "LinearAlgebra", "Parameters", "ProgressMeter", "Random", "Requires", "Statistics", "StatsBase", "StatsFuns"] +git-tree-sha1 = "573080c224795309a965ff61d2b442c7e14d8c04" +uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d" +version = "0.2.25" + [[ArgCheck]] git-tree-sha1 = "59c256cf71c3982484ae4486ee86a3d7da891dea" uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" @@ -29,6 +47,30 @@ git-tree-sha1 = "e214a9b9bd1b4e1b4f15b22c0994862b66af7ff7" uuid = "68821587-b530-5797-8361-c406ea357684" version = "3.5.0+3" +[[ArrayInterface]] +deps = ["LinearAlgebra", "Requires", "SparseArrays"] +git-tree-sha1 = "851de9a8acd7b8863aa2ec2af0a44f375502c878" +uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" +version = "2.9.0" + +[[ArrayLayouts]] +deps = ["FillArrays", "LinearAlgebra"] +git-tree-sha1 = "a3254b3780a3544838ca0b7e23b1e9b06eb71bd8" +uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" +version = "0.3.5" + +[[AxisAlgorithms]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] +git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "1.0.0" + +[[AxisArrays]] +deps = ["Dates", "IntervalSets", "IterTools", "RangeArrays"] +git-tree-sha1 = "f31f50712cbdf40ee8287f0443b57503e34122ef" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.4.3" + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -44,6 +86,59 @@ git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.5.10" +[[Bzip2_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "3663bfffede2ef41358b6fc2e1d8a6d50b3c3904" +uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" +version = "1.0.6+2" + +[[CategoricalArrays]] +deps = ["DataAPI", "Future", "JSON", "Missings", "Printf", "Statistics", "Unicode"] +git-tree-sha1 = "a6c17353ee38ddab30e73dcfaa1107752de724ec" +uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" +version = "0.8.1" + +[[ChainRules]] +deps = ["ChainRulesCore", "LinearAlgebra", "Reexport", "Requires", "Statistics"] +git-tree-sha1 = "76cd719cb7ab57bd2687dcb3b186c4f99820a79d" +uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2" +version = "0.6.5" + +[[ChainRulesCore]] +deps = ["MuladdMacro"] +git-tree-sha1 = "c384e0e4fe6bfeb6bec0d41f71cc5e391cd110ba" +uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +version = "0.8.1" + +[[ColorSchemes]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"] +git-tree-sha1 = "7a15e3690529fd1042f0ab954dff7445b1efc8a5" +uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4" +version = "3.9.0" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random"] +git-tree-sha1 = "cd19496d8943326b752d1712afd6ab79c7514d28" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.10.5" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"] +git-tree-sha1 = "5639e44833cfcf78c6a73fbceb4da75611d312cd" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.12.3" + +[[Combinatorics]] +git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860" +uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" +version = "1.0.2" + +[[CommonSubexpressions]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.3.0" + [[Compat]] deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] git-tree-sha1 = "054993b6611376ddb40203e973e954fd9d1d1902" @@ -62,17 +157,34 @@ git-tree-sha1 = "3ab7b2136722890b9af903859afcf457fa3059e8" uuid = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b" version = "0.1.2" +[[Contour]] +deps = ["StaticArrays"] +git-tree-sha1 = "0b17db36e7e03f8437e0d1f55aea3e4a60c74353" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.3" + [[DataAPI]] git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.3.0" +[[DataFrames]] +deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] +git-tree-sha1 = "d4436b646615928b634b37e99a3288588072f851" +uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +version = "0.21.4" + [[DataStructures]] deps = ["InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.17.18" +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -81,6 +193,18 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" +[[DiffResults]] +deps = ["StaticArrays"] +git-tree-sha1 = "da24935df8e0c6cf28de340b958f6aac88eaa0cc" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "1.0.2" + +[[DiffRules]] +deps = ["NaNMath", "Random", "SpecialFunctions"] +git-tree-sha1 = "eb0c34204c8410888844ada5359ac8b96292cfd1" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "1.0.1" + [[Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" @@ -91,22 +215,190 @@ git-tree-sha1 = "78c4c32a2357a00a0a7d614880f02c2c6e1ec73c" uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" version = "0.23.4" +[[DistributionsAD]] +deps = ["Combinatorics", "Compat", "DiffRules", "Distributions", "FillArrays", "ForwardDiff", "LinearAlgebra", "MacroTools", "NaNMath", "PDMats", "Random", "Requires", "SpecialFunctions", "StaticArrays", "StatsBase", "StatsFuns", "Tracker", "ZygoteRules"] +git-tree-sha1 = "dca00b83d17809f402460010723a6e8facb151d3" +uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c" +version = "0.6.2" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.2" + [[DynamicPPL]] deps = ["AbstractMCMC", "Bijectors", "Distributions", "MacroTools", "Random", "ZygoteRules"] git-tree-sha1 = "b46046c78801149cc9f2b80e806fbd5a2891b652" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" version = "0.8.2" +[[EllipsisNotation]] +git-tree-sha1 = "65dad386e877850e6fce4fc77f60fe75a468ce9d" +uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" +version = "0.4.0" + +[[FFMPEG]] +deps = ["FFMPEG_jll"] +git-tree-sha1 = "c82bef6fc01e30d500f588cd01d29bdd44f1924e" +uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" +version = "0.3.0" + +[[FFMPEG_jll]] +deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"] +git-tree-sha1 = "0fa07f43e5609ea54848b82b4bb330b250e9645b" +uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" +version = "4.1.0+3" + +[[FFTW]] +deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"] +git-tree-sha1 = "14536c95939aadcee44014728a459d2fe3ca9acf" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "1.2.2" + +[[FFTW_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "6c975cd606128d45d1df432fb812d6eb10fee00b" +uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" +version = "3.3.9+5" + [[FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays"] git-tree-sha1 = "bf726ba7ce99e00d10bf63c031285fb9ab3676ae" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" version = "0.8.11" +[[FiniteDiff]] +deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"] +git-tree-sha1 = "fec7c2cb45c27071ef487fa7cae4fcac7509aa10" +uuid = "6a86dc24-6348-571c-b903-95158fe2bd41" +version = "2.3.2" + +[[FixedPointNumbers]] +git-tree-sha1 = "8fb797c37a3b7ced4327a05ac4ca0dd6a4f1ba92" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.8.1" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "NaNMath", "Random", "SpecialFunctions", "StaticArrays"] +git-tree-sha1 = "1d090099fb82223abc48f7ce176d3f7696ede36d" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.12" + +[[FreeType2_jll]] +deps = ["Bzip2_jll", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "7d900f32a3788d4eacac2bfa3bf5c770179c8afd" +uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" +version = "2.10.1+2" + +[[FriBidi_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "2f56bee16bd0151de7b6a1eeea2ced190a2ad8d4" +uuid = "559328eb-81f9-559d-9380-de523a88c83c" +version = "1.0.5+3" + +[[Future]] +deps = ["Random"] +uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "HTTP", "JSON", "LinearAlgebra", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"] +git-tree-sha1 = "247adbd2b33c0c4b42efa20d1e807acf6312145f" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.50.1" + +[[GeometryBasics]] +deps = ["IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"] +git-tree-sha1 = "119f32f9c2b497b49cd3f7f513b358b82660294c" +uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" +version = "0.2.15" + +[[GeometryTypes]] +deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"] +git-tree-sha1 = "34bfa994967e893ab2f17b864eec221b3521ba4d" +uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb" +version = "0.8.3" + +[[HTTP]] +deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] +git-tree-sha1 = "eca61b35cdd8cd2fcc5eec1eda766424a995b02f" +uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" +version = "0.8.16" + +[[IRTools]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "6875ae3cfcb9a50af80553d5cc825f406e8d13bc" +uuid = "7869d1d1-7146-5819-86e3-90919afe41df" +version = "0.4.0" + +[[IniFile]] +deps = ["Test"] +git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" +uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" +version = "0.5.0" + +[[InplaceOps]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "50b41d59e7164ab6fda65e71049fee9d890731ff" +uuid = "505f98c9-085e-5b2c-8e89-488be7bf1f34" +version = "0.3.0" + +[[IntelOpenMP_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6" +uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0" +version = "2018.0.3+0" + [[InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] +git-tree-sha1 = "2b7d4e9be8b74f03115e64cf36ed2f48ae83d946" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.12.10" + +[[IntervalSets]] +deps = ["Dates", "EllipsisNotation", "Statistics"] +git-tree-sha1 = "3b1cef135bc532b3c3401b309e1b8a2a2ba26af5" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.5.1" + +[[InvertedIndices]] +deps = ["Test"] +git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc" +uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" +version = "1.0.0" + +[[IterTools]] +git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.3.0" + +[[IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[KernelDensity]] +deps = ["Distributions", "FFTW", "Interpolations", "Optim", "StatsBase", "Test"] +git-tree-sha1 = "c1048817fe5711f699abc8fabd47b1ac6ba4db04" +uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b" +version = "0.5.1" + +[[LAME_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "221cc8998b9060677448cbb6375f00032554c4fd" +uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d" +version = "3.100.0+1" + [[LeftChildRightSiblingTrees]] deps = ["AbstractTrees"] git-tree-sha1 = "71be1eb5ad19cb4f61fa8c73395c0338fd092ae0" @@ -117,6 +409,12 @@ version = "0.1.2" deps = ["Printf"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" +[[LibVPX_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "e3549ca9bf35feb9d9d954f4c6a9032e92f46e7c" +uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a" +version = "1.8.1+1" + [[Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" @@ -126,6 +424,12 @@ git-tree-sha1 = "68a658db4792dfc468ea2aabcf06f3f74f153f23" uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" version = "0.4.1" +[[LineSearches]] +deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf", "Test"] +git-tree-sha1 = "54eb90e8dbe745d617c78dee1d6ae95c7f6f5779" +uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" +version = "7.0.1" + [[LinearAlgebra]] deps = ["Libdl"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -138,6 +442,18 @@ git-tree-sha1 = "b60616c70eff0cc2c0831b6aace75940aeb0939d" uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" version = "0.4.1" +[[MCMCChains]] +deps = ["AxisArrays", "DataFrames", "Distributions", "KernelDensity", "LinearAlgebra", "Plots", "Random", "RecipesBase", "Serialization", "Showoff", "SpecialFunctions", "Statistics", "StatsBase"] +git-tree-sha1 = "54a33641c1be24a4d254b785f42b545c4b65253b" +uuid = "c7f686f2-ff18-58e9-bc7b-31028e88f75d" +version = "0.3.14" + +[[MKL_jll]] +deps = ["IntelOpenMP_jll", "Libdl", "Pkg"] +git-tree-sha1 = "0ce9a7fa68c70cf83c49d05d2c04d91b47404b08" +uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" +version = "2020.1.216+0" + [[MacroTools]] deps = ["Markdown", "Random"] git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" @@ -153,6 +469,23 @@ version = "0.2.2" deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" +[[MbedTLS]] +deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"] +git-tree-sha1 = "426a6978b03a97ceb7ead77775a1da066343ec6e" +uuid = "739be429-bea8-5141-9913-cc70e7f3736d" +version = "1.0.2" + +[[MbedTLS_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "f85473aeb7a2561a5c58c06c4868971ebe2bcbff" +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.16.6+0" + +[[Measures]] +git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.1" + [[Missings]] deps = ["DataAPI"] git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" @@ -162,24 +495,69 @@ version = "0.4.3" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[MuladdMacro]] +git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68" +uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +version = "0.2.2" + +[[NLSolversBase]] +deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"] +git-tree-sha1 = "7c4e66c47848562003250f28b579c584e55becc0" +uuid = "d41bc354-129a-5804-8e4c-c37616107c6c" +version = "7.6.1" + [[NNlib]] deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Requires", "Statistics"] git-tree-sha1 = "d9f196d911f55aeaff11b11f681b135980783824" uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" version = "0.6.6" +[[NaNMath]] +git-tree-sha1 = "928b8ca9b2791081dc71a51c55347c27c618760f" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.3" + +[[OffsetArrays]] +git-tree-sha1 = "ab697473e983a7499f463b696da8e8feb1b20ffd" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "1.1.0" + +[[Ogg_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "59cf7a95bf5ac39feac80b796e0f39f9d69dc887" +uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051" +version = "1.3.4+0" + [[OpenBLAS_jll]] deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] git-tree-sha1 = "1887096f6897306a4662f7c5af936da7d5d1a062" uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" version = "0.3.9+4" +[[OpenSSL_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "7aaaded15bf393b5f34c2aad5b765c18d26cb495" +uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" +version = "1.1.1+4" + [[OpenSpecFun_jll]] deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" version = "0.5.3+3" +[[Optim]] +deps = ["Compat", "FillArrays", "LineSearches", "LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "PositiveFactorizations", "Printf", "SparseArrays", "StatsBase"] +git-tree-sha1 = "c05aa6b694d426df87ff493306c1c5b4b215e148" +uuid = "429524aa-4258-5aef-a3af-852621145aeb" +version = "0.22.0" + +[[Opus_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "002c18f222a542907e16c83c64a1338992da7e2c" +uuid = "91d4177d-7536-5919-b921-800302f37372" +version = "1.3.1+1" + [[OrderedCollections]] git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" @@ -191,10 +569,52 @@ git-tree-sha1 = "2fc6f50ddd959e462f0a2dbc802ddf2a539c6e35" uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" version = "0.9.12" +[[Parameters]] +deps = ["OrderedCollections", "UnPack"] +git-tree-sha1 = "38b2e970043613c187bd56a995fe2e551821eb4a" +uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" +version = "0.12.1" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "20ef902ea02f7000756a4bc19f7b9c24867c6211" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "1.0.6" + [[Pkg]] deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Statistics"] +git-tree-sha1 = "c6f5ea535551b3b16835134697f0c65d06c94b91" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "2.0.0" + +[[PlotUtils]] +deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"] +git-tree-sha1 = "e18e0e51ff07bf92bb7e06dcb9c082a4e125e20c" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "1.0.5" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "GeometryTypes", "JSON", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"] +git-tree-sha1 = "d2790295d9b65b98c44fe74815743bc101df2e19" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "1.5.2" + +[[PooledArrays]] +deps = ["DataAPI"] +git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c" +uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" +version = "0.5.3" + +[[PositiveFactorizations]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "127c47b91990c101ee3752291c4f45640eeb03d1" +uuid = "85a6dd25-e78a-55b7-8502-1745935b8125" +version = "0.2.3" + [[Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" @@ -225,6 +645,27 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[[RangeArrays]] +git-tree-sha1 = "b9039e93773ddcfc828f12aadf7115b4b4d225f5" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.2" + +[[Ratios]] +git-tree-sha1 = "37d210f612d70f3f7d57d488cb3b6eff56ad4e41" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.4.0" + +[[RecipesBase]] +git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "1.0.1" + +[[RecipesPipeline]] +deps = ["Dates", "PlotUtils", "RecipesBase"] +git-tree-sha1 = "d2a58b8291d1c0abae6a91489973f8a92bf5c04a" +uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" +version = "0.1.11" + [[Reexport]] deps = ["Pkg"] git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" @@ -265,6 +706,12 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" deps = ["Distributed", "Mmap", "Random", "Serialization"] uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" +[[Showoff]] +deps = ["Dates"] +git-tree-sha1 = "e032c9df551fb23c9f98ae1064de074111b7bc39" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.3.1" + [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" @@ -284,6 +731,12 @@ git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" version = "0.10.3" +[[StaticArrays]] +deps = ["LinearAlgebra", "Random", "Statistics"] +git-tree-sha1 = "5c06c0aeb81bef54aed4b3f446847905eb6cbda0" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.12.3" + [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" @@ -300,10 +753,28 @@ git-tree-sha1 = "04a5a8e6ab87966b43f247920eab053fd5fdc925" uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" version = "0.9.5" +[[StructArrays]] +deps = ["Adapt", "DataAPI", "Tables"] +git-tree-sha1 = "8099ed9fb90b6e754d6ba8c6ed8670f010eadca0" +uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" +version = "0.4.4" + [[SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" +[[TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.0" + +[[Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "1.0.4" + [[TerminalLoggers]] deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] git-tree-sha1 = "cbea752b5eef52a3e1188fb31580c3e4fa0cbc35" @@ -314,15 +785,80 @@ version = "0.1.2" deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[Tracker]] +deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"] +git-tree-sha1 = "1e0b60f070020ed18ef364cccecabcb75c8bc23c" +uuid = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" +version = "0.2.7" + +[[Turing]] +deps = ["AdvancedHMC", "Bijectors", "BinaryProvider", "Distributions", "DistributionsAD", "ForwardDiff", "Libtask", "LinearAlgebra", "MCMCChains", "MacroTools", "Markdown", "PDMats", "ProgressMeter", "Random", "Reexport", "Requires", "SpecialFunctions", "Statistics", "StatsFuns", "Tracker", "Zygote"] +git-tree-sha1 = "f2332f24adc1a3a1c5c451caea90dc72093dd709" +uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" +version = "0.7.0" + [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" +[[UnPack]] +git-tree-sha1 = "d4bfa022cd30df012700cf380af2141961bb3bfb" +uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" +version = "1.0.1" + [[Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "28ffe06d28b1ba8fdb2f36ec7bb079fac81bac0d" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.5.2" + +[[Zlib_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "622d8b6dc0c7e8029f17127703de9819134d1b71" +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.11+14" + +[[Zygote]] +deps = ["AbstractFFTs", "ArrayLayouts", "ChainRules", "FillArrays", "ForwardDiff", "Future", "IRTools", "InteractiveUtils", "LinearAlgebra", "MacroTools", "NNlib", "Random", "Requires", "Statistics", "ZygoteRules"] +git-tree-sha1 = "2e2c82549fb0414df10469082fd001e2ede8547c" +uuid = "e88e6eb3-aa80-5325-afca-941959d7151f" +version = "0.4.22" + [[ZygoteRules]] deps = ["MacroTools"] git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" uuid = "700de1a5-db45-46bc-99cf-38207098b444" version = "0.2.0" + +[[libass_jll]] +deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "027a304b2a90de84f690949a21f94e5ae0f92c73" +uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0" +version = "0.14.0+2" + +[[libfdk_aac_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "480c7ed04f68ea3edd4c757f5db5b6a0a4e0bd99" +uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280" +version = "0.1.6+2" + +[[libvorbis_jll]] +deps = ["Libdl", "Ogg_jll", "Pkg"] +git-tree-sha1 = "6a66f65b5275dfa799036c8a3a26616a0a271c4a" +uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a" +version = "1.3.6+4" + +[[x264_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "d89346fe63a6465a9f44e958ac0e3d366af90b74" +uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a" +version = "2019.5.25+2" + +[[x265_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "61324ad346b00a6e541896b94201c9426591e43a" +uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76" +version = "3.0.0+1" diff --git a/Project.toml b/Project.toml index ee1aa878..797b2fc1 100644 --- a/Project.toml +++ b/Project.toml @@ -11,3 +11,4 @@ Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index 308f2185..00ebd85b 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -1,8 +1,9 @@ # TODO: this doesn't work because some tests use turing/inference/: eg line 31 -# TODO: this tests functions in particlecontainer.jl but also sweep.jl ====> must rename +# TODO: this file tests functions in particlecontainer.jl but also sweep.jl ====> must rename anyway using AdvancedPS using Test +using DynamicPPL, Turing @testset "particlecontainer.jl" begin @testset "copy particle container" begin @@ -27,7 +28,8 @@ using Test end # Dummy sampler that is not actually used. - sampler = Sampler(PG(5), empty_model()) + Turing.@model empty_model() = begin x = 1; end + sampler = Turing.Sampler(PG(5), empty_model()) # Create particle container. logps = [0.0, -1.0, -2.0] From 1bfdbb8eadbf26da3a802d217fe5f3555478eddf Mon Sep 17 00:00:00 2001 From: JS Denain Date: Mon, 6 Jul 2020 11:43:45 +0200 Subject: [PATCH 31/44] moved some tests to Turing.jl --- test/particlecontainer.jl | 81 +-------------------------------------- test/runtests.jl | 1 + 2 files changed, 2 insertions(+), 80 deletions(-) diff --git a/test/particlecontainer.jl b/test/particlecontainer.jl index 00ebd85b..54dc1ce6 100644 --- a/test/particlecontainer.jl +++ b/test/particlecontainer.jl @@ -1,9 +1,5 @@ -# TODO: this doesn't work because some tests use turing/inference/: eg line 31 -# TODO: this file tests functions in particlecontainer.jl but also sweep.jl ====> must rename anyway - using AdvancedPS using Test -using DynamicPPL, Turing @testset "particlecontainer.jl" begin @testset "copy particle container" begin @@ -13,79 +9,4 @@ using DynamicPPL, Turing @test newpc.logWs == pc.logWs @test typeof(pc) === typeof(newpc) end - - @testset "particle container" begin - # Create a resumable function that always yields `logp`. - function fpc(logp) - f = let logp = logp - () -> begin - while true - produce(logp) - end - end - end - return f - end - - # Dummy sampler that is not actually used. - Turing.@model empty_model() = begin x = 1; end - sampler = Turing.Sampler(PG(5), empty_model()) - - # Create particle container. - logps = [0.0, -1.0, -2.0] - particles = [Trace(fpc(logp), empty_model(), sampler, VarInfo()) for logp in logps] - pc = ParticleContainer(particles) - - # Initial state. - @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) - @test pc.logWs == zeros(3) - @test getweights(pc) == fill(1/3, 3) - @test all(getweight(pc, i) == 1/3 for i in 1:3) - @test logZ(pc) ≈ log(3) - @test effectiveSampleSize(pc) == 3 - - # Reweight particles. - reweight!(pc) - @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) - @test pc.logWs == logps - @test getweights(pc) ≈ exp.(logps) ./ sum(exp, logps) - @test all(getweight(pc, i) ≈ exp(logps[i]) / sum(exp, logps) for i in 1:3) - @test logZ(pc) == log(sum(exp, logps)) - - # Reweight particles. - reweight!(pc) - @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) - @test pc.logWs == 2 .* logps - @test getweights(pc) == exp.(2 .* logps) ./ sum(exp, 2 .* logps) - @test all(getweight(pc, i) ≈ exp(2 * logps[i]) / sum(exp, 2 .* logps) for i in 1:3) - @test logZ(pc) == log(sum(exp, 2 .* logps)) - - # Resample and propagate particles. - resample_propagate!(pc) - @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) - @test pc.logWs == zeros(3) - @test getweights(pc) == fill(1/3, 3) - @test all(getweight(pc, i) == 1/3 for i in 1:3) - @test logZ(pc) ≈ log(3) - @test effectiveSampleSize(pc) == 3 - - # Reweight particles. - reweight!(pc) - @test all(iszero(getlogp(particle.vi)) for particle in pc.vals) - @test pc.logWs ⊆ logps - @test getweights(pc) == exp.(pc.logWs) ./ sum(exp, pc.logWs) - @test all(getweight(pc, i) ≈ exp(pc.logWs[i]) / sum(exp, pc.logWs) for i in 1:3) - @test logZ(pc) == log(sum(exp, pc.logWs)) - - # Increase unnormalized logarithmic weights. - logws = copy(pc.logWs) - increase_logweight!(pc, 2, 1.41) - @test pc.logWs == logws + [0, 1.41, 0] - - # Reset unnormalized logarithmic weights. - logws = pc.logWs - reset_logweights!(pc) - @test pc.logWs === logws - @test all(iszero, pc.logWs) - end -end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d392b1e4..2dccc019 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,3 +3,4 @@ using AdvancedPS include("resampling.jl") include("particlecontainer.jl") +# more tests for structs and functions from particlecontainer.jl and sweep.jl require smc.jl and are tested with it \ No newline at end of file From da821d91494f10a554ab720961c977799bbe0d2b Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 7 Jul 2020 15:43:55 +0200 Subject: [PATCH 32/44] in resampling.jl rename resampler attribute to scheme, in sweep.jl rename randcat to scheme --- src/resampling.jl | 28 +++++++++++++--------------- src/sweep.jl | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/resampling.jl b/src/resampling.jl index 46c2bcc6..c5306f94 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -1,27 +1,25 @@ -# TODO: 2 dichotomies between resamplers: -# - whether or not to use thresholds -# - whether to use systematic, residual, multinomial, or stratified resampling -# build a struct for all of this -# also the use of randcat for an implementation of rand(Categorical()) *and* as the name of the resampler in resample_propagate! is confusing +# 2 dichotomies between resamplers: +# - whether or not to use ESS thresholds +# - whether to use systematic, residual, multinomial, or stratified resampling schemes -#### -#### Resample only when ESS ≤ a preset value -#### +############################################# +## Resample only when ESS ≤ a preset value ## +############################################# # modifies dispatch in resample_propagate! struct ResampleWithESSThreshold{R, T<:Real} - resampler::R + scheme::R threshold::T end -function ResampleWithESSThreshold(resampler = resample_systematic) - ResampleWithESSThreshold(resampler, 0.5) +function ResampleWithESSThreshold(scheme = resample_systematic) + ResampleWithESSThreshold(scheme, 0.5) end -#### -#### Resampling schemes for particle filters -#### +############################################# +## Resampling schemes for particle filters ## +############################################# # Some references # - http://arxiv.org/pdf/1301.4019.pdf @@ -44,7 +42,7 @@ function randcat(p::AbstractVector{<:Real}) end """ - resample(w, num_particles) +resample(w, num_particles) Default resampling scheme: systematic resampling """ function resample(w::AbstractVector{<:Real}, num_particles::Integer=length(w)) diff --git a/src/sweep.jl b/src/sweep.jl index a0269d9a..06e75c91 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -1,14 +1,13 @@ """ -resample_propagate!(pc::ParticleContainer[, randcat = resample_systematic, ref = nothing; +resample_propagate!(pc::ParticleContainer[, scheme = resample_systematic, ref = nothing; weights = getweights(pc)]) -Resample and propagate the particles in `pc`. -Function `randcat` is used for sampling ancestor indices from the categorical distribution -of the particle `weights`. For Particle Gibbs sampling, one can provide a reference particle -`ref` that is ensured to survive the resampling step. +Resample and propagate the particles in `pc`, without ESS thresholding. +Function `scheme` is the scheme used to resample ancestor indices based on the particle weights. +For Particle Gibbs sampling, one can provide a reference particle `ref` that is ensured to survive the resampling step. """ function resample_propagate!( pc::ParticleContainer, -randcat = resample_systematic, +scheme = resample_systematic, ref::Union{Particle, Nothing} = nothing; weights = getweights(pc) ) @@ -18,7 +17,7 @@ weights = getweights(pc) # sample ancestor indices n = length(pc) nresamples = ref === nothing ? n : n - 1 -indx = randcat(weights, nresamples) +indx = scheme(weights, nresamples) # count number of children for each particle num_children = zeros(Int, n) @@ -61,7 +60,12 @@ pc end - +""" +resample_propagate!(pc::ParticleContainer, resampler::ResampleWithESSThreshold[, ref = nothing; + weights = getweights(pc)]) +Resample and propagate the particles in `pc`, with ESS thresholding. +For Particle Gibbs sampling, one can provide a reference particle `ref` that is ensured to survive the resampling step. +""" function resample_propagate!( pc::ParticleContainer, resampler::ResampleWithESSThreshold, @@ -72,7 +76,7 @@ weights = getweights(pc) ess = inv(sum(abs2, weights)) if ess ≤ resampler.threshold * length(pc) - resample_propagate!(pc, resampler.resampler, ref; weights = weights) + resample_propagate!(pc, resampler.scheme, ref; weights = weights) end pc From ccb8634ba40a09511eb017e641a1e0d7f2ea198e Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 7 Jul 2020 17:29:07 +0200 Subject: [PATCH 33/44] remove function resample --- src/resampling.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/resampling.jl b/src/resampling.jl index c5306f94..3fd6aaf7 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -41,14 +41,6 @@ function randcat(p::AbstractVector{<:Real}) return s end -""" -resample(w, num_particles) -Default resampling scheme: systematic resampling -""" -function resample(w::AbstractVector{<:Real}, num_particles::Integer=length(w)) - return resample_systematic(w, num_particles) -end - """ resample_multinomial(w, num_particles) Multinomial resampling scheme From 93d0ddb5c071ba928eb8c24b839d8d5fc384a4f4 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 7 Jul 2020 17:29:49 +0200 Subject: [PATCH 34/44] remove function resample from tests --- test/resampling.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/resampling.jl b/test/resampling.jl index 4556b07a..7302e20a 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -8,11 +8,9 @@ using AdvancedPS resStratified = resample_stratified(D, num_samples ) resMultinomial= resample_multinomial(D, num_samples ) resResidual = resample_residual(D, num_samples ) - resample(D) - resSystematic2=resample(D, num_samples ) + @test sum(resSystematic .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples - @test sum(resSystematic2 .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples @test sum(resStratified .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples @test sum(resMultinomial .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples @test sum(resResidual .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples From 1c24a011c9b2fe57d7df6154d3eb8a42786b620e Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 7 Jul 2020 17:31:48 +0200 Subject: [PATCH 35/44] remove default scheme from function resample_propagate\! --- src/sweep.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sweep.jl b/src/sweep.jl index 06e75c91..eb3af204 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -1,5 +1,5 @@ """ -resample_propagate!(pc::ParticleContainer[, scheme = resample_systematic, ref = nothing; +resample_propagate!(pc::ParticleContainer[, scheme, ref = nothing; weights = getweights(pc)]) Resample and propagate the particles in `pc`, without ESS thresholding. Function `scheme` is the scheme used to resample ancestor indices based on the particle weights. @@ -7,7 +7,7 @@ For Particle Gibbs sampling, one can provide a reference particle `ref` that is """ function resample_propagate!( pc::ParticleContainer, -scheme = resample_systematic, +scheme, ref::Union{Particle, Nothing} = nothing; weights = getweights(pc) ) From bd08f5e8f82a62c6eed1e59137f37ccc015ddd7b Mon Sep 17 00:00:00 2001 From: denainjs <43207175+denainjs@users.noreply.github.com> Date: Thu, 9 Jul 2020 14:49:03 +0200 Subject: [PATCH 36/44] Delete README.md --- README.md | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 49974209..00000000 --- a/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# AdvancedParticleSamplers.jl - - - -### Reference - -1. Doucet, Arnaud, and Adam M. Johansen. "A tutorial on particle filtering and smoothing: Fifteen years later." Handbook of nonlinear filtering 12, no. 656-704 (2009): 3. - -2. Andrieu, Christophe, Arnaud Doucet, and Roman Holenstein. "Particle Markov chain Monte Carlo methods." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 72, no. 3 (2010): 269-342. - -3. Tripuraneni, Nilesh, Shixiang Shane Gu, Hong Ge, and Zoubin Ghahramani. "Particle gibbs for infinite hidden Markov models." In Advances in Neural Information Processing Systems, pp. 2395-2403. 2015. - -4. Lindsten, Fredrik, Michael I. Jordan, and Thomas B. Schön. "Particle Gibbs with ancestor sampling." The Journal of Machine Learning Research 15, no. 1 (2014): 2145-2184. - -5. Pitt, Michael K., and Neil Shephard. "Filtering via simulation: Auxiliary particle filters." Journal of the American statistical association 94, no. 446 (1999): 590-599. - -6. Doucet, Arnaud, Nando de Freitas, and Neil Gordon. "Sequential Monte Carlo Methods in Practice." - -7. Del Moral, Pierre, Arnaud Doucet, and Ajay Jasra. "Sequential Monte Carlo samplers." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 68, no. 3 (2006): 411-436. - - - - From 66fd6eacac7546730aac48d02fd5ef9dd0002a3d Mon Sep 17 00:00:00 2001 From: JS Denain Date: Thu, 9 Jul 2020 15:06:13 +0200 Subject: [PATCH 37/44] remove useless resample function --- src/AdvancedPS.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AdvancedPS.jl b/src/AdvancedPS.jl index ce2cfb78..25b412e3 100644 --- a/src/AdvancedPS.jl +++ b/src/AdvancedPS.jl @@ -23,7 +23,6 @@ export ParticleContainer, include("resampling.jl") export ResampleWithESSThreshold, - resample, randcat, resample_multinomial, resample_residual, From 455f17c05c1d83bff3a6a2aa8e0b2cf753fa02a0 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Mon, 13 Jul 2020 16:07:03 +0200 Subject: [PATCH 38/44] add indentation and return to return statements in sweep.jl --- src/sweep.jl | 214 +++++++++++++++++++++++++-------------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/src/sweep.jl b/src/sweep.jl index eb3af204..e8f95ac1 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -11,52 +11,52 @@ scheme, ref::Union{Particle, Nothing} = nothing; weights = getweights(pc) ) -# check that weights are not NaN -@assert !any(isnan, weights) - -# sample ancestor indices -n = length(pc) -nresamples = ref === nothing ? n : n - 1 -indx = scheme(weights, nresamples) - -# count number of children for each particle -num_children = zeros(Int, n) -@inbounds for i in indx - num_children[i] += 1 -end + # check that weights are not NaN + @assert !any(isnan, weights) + + # sample ancestor indices + n = length(pc) + nresamples = ref === nothing ? n : n - 1 + indx = scheme(weights, nresamples) + + # count number of children for each particle + num_children = zeros(Int, n) + @inbounds for i in indx + num_children[i] += 1 + end -# fork particles -particles = collect(pc) -children = similar(particles) -j = 0 -@inbounds for i in 1:n - ni = num_children[i] - - if ni > 0 - # fork first child - pi = particles[i] - isref = pi === ref - p = isref ? fork(pi, isref) : pi - children[j += 1] = p - - # fork additional children - for _ in 2:ni - children[j += 1] = fork(p, isref) + # fork particles + particles = collect(pc) + children = similar(particles) + j = 0 + @inbounds for i in 1:n + ni = num_children[i] + + if ni > 0 + # fork first child + pi = particles[i] + isref = pi === ref + p = isref ? fork(pi, isref) : pi + children[j += 1] = p + + # fork additional children + for _ in 2:ni + children[j += 1] = fork(p, isref) + end end end -end -if ref !== nothing - # Insert the retained particle. This is based on the replaying trick for efficiency - # reasons. If we implement PG using task copying, we need to store Nx * T particles! - @inbounds children[n] = ref -end + if ref !== nothing + # Insert the retained particle. This is based on the replaying trick for efficiency + # reasons. If we implement PG using task copying, we need to store Nx * T particles! + @inbounds children[n] = ref + end -# replace particles and log weights in the container with new particles and weights -pc.vals = children -reset_logweights!(pc) + # replace particles and log weights in the container with new particles and weights + pc.vals = children + reset_logweights!(pc) -pc + return pc end @@ -72,14 +72,14 @@ resampler::ResampleWithESSThreshold, ref::Union{Particle,Nothing} = nothing; weights = getweights(pc) ) -# Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ`` -ess = inv(sum(abs2, weights)) + # Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ`` + ess = inv(sum(abs2, weights)) -if ess ≤ resampler.threshold * length(pc) - resample_propagate!(pc, resampler.scheme, ref; weights = weights) -end + if ess ≤ resampler.threshold * length(pc) + resample_propagate!(pc, resampler.scheme, ref; weights = weights) + end -pc + return pc end @@ -89,44 +89,44 @@ Check if the final time step is reached, and otherwise reweight the particles by considering the next observation. """ function reweight!(pc::ParticleContainer) -n = length(pc) - -particles = collect(pc) -numdone = 0 -for i in 1:n - p = particles[i] - - # Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the - # the execution of the model is finished. - # Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and - # ``θᵢ`` are variables of other samplers. - score = Libtask.consume(p) - - if score === nothing - numdone += 1 - else - # Increase the unnormalized logarithmic weights, accounting for the variables - # of other samplers. - increase_logweight!(pc, i, score + getlogp(p.vi)) - - # Reset the accumulator of the log probability in the model so that we can - # accumulate log probabilities of variables of other samplers until the next - # observation. - resetlogp!(p.vi) + n = length(pc) + + particles = collect(pc) + numdone = 0 + for i in 1:n + p = particles[i] + + # Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the + # the execution of the model is finished. + # Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and + # ``θᵢ`` are variables of other samplers. + score = Libtask.consume(p) + + if score === nothing + numdone += 1 + else + # Increase the unnormalized logarithmic weights, accounting for the variables + # of other samplers. + increase_logweight!(pc, i, score + getlogp(p.vi)) + + # Reset the accumulator of the log probability in the model so that we can + # accumulate log probabilities of variables of other samplers until the next + # observation. + resetlogp!(p.vi) + end end -end -# Check if all particles are propagated to the final time point. -numdone == n && return true + # Check if all particles are propagated to the final time point. + numdone == n && return true -# The posterior for models with random number of observations is not well-defined. -if numdone != 0 - error("mis-aligned execution traces: # particles = ", n, - " # completed trajectories = ", numdone, - ". Please make sure the number of observations is NOT random.") -end + # The posterior for models with random number of observations is not well-defined. + if numdone != 0 + error("mis-aligned execution traces: # particles = ", n, + " # completed trajectories = ", numdone, + ". Please make sure the number of observations is NOT random.") + end -return false + return false end """ @@ -138,45 +138,45 @@ Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(3), 411-436. """ function sweep!(pc::ParticleContainer, resampler) -# Initial step: - -# Resample and propagate particles. -resample_propagate!(pc, resampler) + # Initial step: -# Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic -# weights. -# Usually it is equal to the number of particles in the beginning but this -# implementation covers also the unlikely case of a particle container that is -# initialized with non-zero logarithmic weights. -logZ0 = logZ(pc) - -# Reweight the particles by including the first observation ``y₁``. -isdone = reweight!(pc) - -# Compute the normalizing constant ``Z₁`` after reweighting. -logZ1 = logZ(pc) - -# Compute the estimate of the log evidence ``\\log p(y₁)``. -logevidence = logZ1 - logZ0 - -# For observations ``y₂, …, yₜ``: -while !isdone # Resample and propagate particles. resample_propagate!(pc, resampler) # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic # weights. + # Usually it is equal to the number of particles in the beginning but this + # implementation covers also the unlikely case of a particle container that is + # initialized with non-zero logarithmic weights. logZ0 = logZ(pc) - # Reweight the particles by including the next observation ``yₜ``. + # Reweight the particles by including the first observation ``y₁``. isdone = reweight!(pc) # Compute the normalizing constant ``Z₁`` after reweighting. logZ1 = logZ(pc) - # Compute the estimate of the log evidence ``\\log p(y₁, …, yₜ)``. - logevidence += logZ1 - logZ0 -end + # Compute the estimate of the log evidence ``\\log p(y₁)``. + logevidence = logZ1 - logZ0 + + # For observations ``y₂, …, yₜ``: + while !isdone + # Resample and propagate particles. + resample_propagate!(pc, resampler) + + # Compute the current normalizing constant ``Z₀`` of the unnormalized logarithmic + # weights. + logZ0 = logZ(pc) + + # Reweight the particles by including the next observation ``yₜ``. + isdone = reweight!(pc) + + # Compute the normalizing constant ``Z₁`` after reweighting. + logZ1 = logZ(pc) + + # Compute the estimate of the log evidence ``\\log p(y₁, …, yₜ)``. + logevidence += logZ1 - logZ0 + end -return logevidence + return logevidence end From 16a2fa8fae0783b8bde10e2274c4d30feb91a223 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:12:28 +0200 Subject: [PATCH 39/44] remove Manifest file --- Manifest.toml | 864 -------------------------------------------------- 1 file changed, 864 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index cae7f1df..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,864 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[AbstractFFTs]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716" -uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" -version = "0.5.0" - -[[AbstractMCMC]] -deps = ["ConsoleProgressMonitor", "Distributed", "Logging", "LoggingExtras", "ProgressLogging", "Random", "StatsBase", "TerminalLoggers"] -git-tree-sha1 = "31a0a7b957525748e05599488ca6eef476fef12b" -uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001" -version = "1.0.1" - -[[AbstractTrees]] -deps = ["Markdown"] -git-tree-sha1 = "33e450545eaf7699da1a6e755f9ea65f14077a45" -uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" -version = "0.3.3" - -[[Adapt]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "fd04049c7dd78cfef0b06cdc1f0f181467655712" -uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "1.1.0" - -[[AdvancedHMC]] -deps = ["ArgCheck", "DocStringExtensions", "InplaceOps", "LinearAlgebra", "Parameters", "ProgressMeter", "Random", "Requires", "Statistics", "StatsBase", "StatsFuns"] -git-tree-sha1 = "573080c224795309a965ff61d2b442c7e14d8c04" -uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d" -version = "0.2.25" - -[[ArgCheck]] -git-tree-sha1 = "59c256cf71c3982484ae4486ee86a3d7da891dea" -uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" -version = "2.0.0" - -[[Arpack]] -deps = ["Arpack_jll", "Libdl", "LinearAlgebra"] -git-tree-sha1 = "2ff92b71ba1747c5fdd541f8fc87736d82f40ec9" -uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" -version = "0.4.0" - -[[Arpack_jll]] -deps = ["Libdl", "OpenBLAS_jll", "Pkg"] -git-tree-sha1 = "e214a9b9bd1b4e1b4f15b22c0994862b66af7ff7" -uuid = "68821587-b530-5797-8361-c406ea357684" -version = "3.5.0+3" - -[[ArrayInterface]] -deps = ["LinearAlgebra", "Requires", "SparseArrays"] -git-tree-sha1 = "851de9a8acd7b8863aa2ec2af0a44f375502c878" -uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" -version = "2.9.0" - -[[ArrayLayouts]] -deps = ["FillArrays", "LinearAlgebra"] -git-tree-sha1 = "a3254b3780a3544838ca0b7e23b1e9b06eb71bd8" -uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "0.3.5" - -[[AxisAlgorithms]] -deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] -git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9" -uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" -version = "1.0.0" - -[[AxisArrays]] -deps = ["Dates", "IntervalSets", "IterTools", "RangeArrays"] -git-tree-sha1 = "f31f50712cbdf40ee8287f0443b57503e34122ef" -uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" -version = "0.4.3" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[Bijectors]] -deps = ["ArgCheck", "Compat", "Distributions", "LinearAlgebra", "MappedArrays", "NNlib", "Random", "Reexport", "Requires", "Roots", "SparseArrays", "Statistics", "StatsFuns"] -git-tree-sha1 = "84836b7f35952ec814869174f0e55a385b7d00cd" -uuid = "76274a88-744f-5084-9051-94815aaf08c4" -version = "0.8.0" - -[[BinaryProvider]] -deps = ["Libdl", "Logging", "SHA"] -git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.10" - -[[Bzip2_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "3663bfffede2ef41358b6fc2e1d8a6d50b3c3904" -uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" -version = "1.0.6+2" - -[[CategoricalArrays]] -deps = ["DataAPI", "Future", "JSON", "Missings", "Printf", "Statistics", "Unicode"] -git-tree-sha1 = "a6c17353ee38ddab30e73dcfaa1107752de724ec" -uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" -version = "0.8.1" - -[[ChainRules]] -deps = ["ChainRulesCore", "LinearAlgebra", "Reexport", "Requires", "Statistics"] -git-tree-sha1 = "76cd719cb7ab57bd2687dcb3b186c4f99820a79d" -uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2" -version = "0.6.5" - -[[ChainRulesCore]] -deps = ["MuladdMacro"] -git-tree-sha1 = "c384e0e4fe6bfeb6bec0d41f71cc5e391cd110ba" -uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -version = "0.8.1" - -[[ColorSchemes]] -deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"] -git-tree-sha1 = "7a15e3690529fd1042f0ab954dff7445b1efc8a5" -uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4" -version = "3.9.0" - -[[ColorTypes]] -deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "cd19496d8943326b752d1712afd6ab79c7514d28" -uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.10.5" - -[[Colors]] -deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"] -git-tree-sha1 = "5639e44833cfcf78c6a73fbceb4da75611d312cd" -uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" -version = "0.12.3" - -[[Combinatorics]] -git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860" -uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" -version = "1.0.2" - -[[CommonSubexpressions]] -deps = ["MacroTools", "Test"] -git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7" -uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" -version = "0.3.0" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "054993b6611376ddb40203e973e954fd9d1d1902" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.12.0" - -[[CompilerSupportLibraries_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612" -uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "0.3.3+0" - -[[ConsoleProgressMonitor]] -deps = ["Logging", "ProgressMeter"] -git-tree-sha1 = "3ab7b2136722890b9af903859afcf457fa3059e8" -uuid = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b" -version = "0.1.2" - -[[Contour]] -deps = ["StaticArrays"] -git-tree-sha1 = "0b17db36e7e03f8437e0d1f55aea3e4a60c74353" -uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" -version = "0.5.3" - -[[DataAPI]] -git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" -uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.3.0" - -[[DataFrames]] -deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] -git-tree-sha1 = "d4436b646615928b634b37e99a3288588072f851" -uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.21.4" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.18" - -[[DataValueInterfaces]] -git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" -uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" -version = "1.0.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[DiffResults]] -deps = ["StaticArrays"] -git-tree-sha1 = "da24935df8e0c6cf28de340b958f6aac88eaa0cc" -uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" -version = "1.0.2" - -[[DiffRules]] -deps = ["NaNMath", "Random", "SpecialFunctions"] -git-tree-sha1 = "eb0c34204c8410888844ada5359ac8b96292cfd1" -uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "1.0.1" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[Distributions]] -deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"] -git-tree-sha1 = "78c4c32a2357a00a0a7d614880f02c2c6e1ec73c" -uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" -version = "0.23.4" - -[[DistributionsAD]] -deps = ["Combinatorics", "Compat", "DiffRules", "Distributions", "FillArrays", "ForwardDiff", "LinearAlgebra", "MacroTools", "NaNMath", "PDMats", "Random", "Requires", "SpecialFunctions", "StaticArrays", "StatsBase", "StatsFuns", "Tracker", "ZygoteRules"] -git-tree-sha1 = "dca00b83d17809f402460010723a6e8facb151d3" -uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c" -version = "0.6.2" - -[[DocStringExtensions]] -deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.2" - -[[DynamicPPL]] -deps = ["AbstractMCMC", "Bijectors", "Distributions", "MacroTools", "Random", "ZygoteRules"] -git-tree-sha1 = "b46046c78801149cc9f2b80e806fbd5a2891b652" -uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.8.2" - -[[EllipsisNotation]] -git-tree-sha1 = "65dad386e877850e6fce4fc77f60fe75a468ce9d" -uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" -version = "0.4.0" - -[[FFMPEG]] -deps = ["FFMPEG_jll"] -git-tree-sha1 = "c82bef6fc01e30d500f588cd01d29bdd44f1924e" -uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" -version = "0.3.0" - -[[FFMPEG_jll]] -deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"] -git-tree-sha1 = "0fa07f43e5609ea54848b82b4bb330b250e9645b" -uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" -version = "4.1.0+3" - -[[FFTW]] -deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"] -git-tree-sha1 = "14536c95939aadcee44014728a459d2fe3ca9acf" -uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -version = "1.2.2" - -[[FFTW_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "6c975cd606128d45d1df432fb812d6eb10fee00b" -uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" -version = "3.3.9+5" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "bf726ba7ce99e00d10bf63c031285fb9ab3676ae" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.8.11" - -[[FiniteDiff]] -deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"] -git-tree-sha1 = "fec7c2cb45c27071ef487fa7cae4fcac7509aa10" -uuid = "6a86dc24-6348-571c-b903-95158fe2bd41" -version = "2.3.2" - -[[FixedPointNumbers]] -git-tree-sha1 = "8fb797c37a3b7ced4327a05ac4ca0dd6a4f1ba92" -uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" -version = "0.8.1" - -[[ForwardDiff]] -deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "NaNMath", "Random", "SpecialFunctions", "StaticArrays"] -git-tree-sha1 = "1d090099fb82223abc48f7ce176d3f7696ede36d" -uuid = "f6369f11-7733-5829-9624-2563aa707210" -version = "0.10.12" - -[[FreeType2_jll]] -deps = ["Bzip2_jll", "Libdl", "Pkg", "Zlib_jll"] -git-tree-sha1 = "7d900f32a3788d4eacac2bfa3bf5c770179c8afd" -uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" -version = "2.10.1+2" - -[[FriBidi_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "2f56bee16bd0151de7b6a1eeea2ced190a2ad8d4" -uuid = "559328eb-81f9-559d-9380-de523a88c83c" -version = "1.0.5+3" - -[[Future]] -deps = ["Random"] -uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" - -[[GR]] -deps = ["Base64", "DelimitedFiles", "HTTP", "JSON", "LinearAlgebra", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"] -git-tree-sha1 = "247adbd2b33c0c4b42efa20d1e807acf6312145f" -uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" -version = "0.50.1" - -[[GeometryBasics]] -deps = ["IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"] -git-tree-sha1 = "119f32f9c2b497b49cd3f7f513b358b82660294c" -uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" -version = "0.2.15" - -[[GeometryTypes]] -deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"] -git-tree-sha1 = "34bfa994967e893ab2f17b864eec221b3521ba4d" -uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb" -version = "0.8.3" - -[[HTTP]] -deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] -git-tree-sha1 = "eca61b35cdd8cd2fcc5eec1eda766424a995b02f" -uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "0.8.16" - -[[IRTools]] -deps = ["InteractiveUtils", "MacroTools", "Test"] -git-tree-sha1 = "6875ae3cfcb9a50af80553d5cc825f406e8d13bc" -uuid = "7869d1d1-7146-5819-86e3-90919afe41df" -version = "0.4.0" - -[[IniFile]] -deps = ["Test"] -git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" -uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" -version = "0.5.0" - -[[InplaceOps]] -deps = ["LinearAlgebra", "Test"] -git-tree-sha1 = "50b41d59e7164ab6fda65e71049fee9d890731ff" -uuid = "505f98c9-085e-5b2c-8e89-488be7bf1f34" -version = "0.3.0" - -[[IntelOpenMP_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6" -uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0" -version = "2018.0.3+0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[Interpolations]] -deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] -git-tree-sha1 = "2b7d4e9be8b74f03115e64cf36ed2f48ae83d946" -uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" -version = "0.12.10" - -[[IntervalSets]] -deps = ["Dates", "EllipsisNotation", "Statistics"] -git-tree-sha1 = "3b1cef135bc532b3c3401b309e1b8a2a2ba26af5" -uuid = "8197267c-284f-5f27-9208-e0e47529a953" -version = "0.5.1" - -[[InvertedIndices]] -deps = ["Test"] -git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc" -uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" -version = "1.0.0" - -[[IterTools]] -git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" -uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" -version = "1.3.0" - -[[IteratorInterfaceExtensions]] -git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" -uuid = "82899510-4779-5014-852e-03e436cf321d" -version = "1.0.0" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.0" - -[[KernelDensity]] -deps = ["Distributions", "FFTW", "Interpolations", "Optim", "StatsBase", "Test"] -git-tree-sha1 = "c1048817fe5711f699abc8fabd47b1ac6ba4db04" -uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b" -version = "0.5.1" - -[[LAME_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "221cc8998b9060677448cbb6375f00032554c4fd" -uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d" -version = "3.100.0+1" - -[[LeftChildRightSiblingTrees]] -deps = ["AbstractTrees"] -git-tree-sha1 = "71be1eb5ad19cb4f61fa8c73395c0338fd092ae0" -uuid = "1d6d02ad-be62-4b6b-8a6d-2f90e265016e" -version = "0.1.2" - -[[LibGit2]] -deps = ["Printf"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[LibVPX_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "e3549ca9bf35feb9d9d954f4c6a9032e92f46e7c" -uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a" -version = "1.8.1+1" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[Libtask]] -deps = ["BinaryProvider", "Libdl", "Pkg"] -git-tree-sha1 = "68a658db4792dfc468ea2aabcf06f3f74f153f23" -uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" -version = "0.4.1" - -[[LineSearches]] -deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf", "Test"] -git-tree-sha1 = "54eb90e8dbe745d617c78dee1d6ae95c7f6f5779" -uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" -version = "7.0.1" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[LoggingExtras]] -git-tree-sha1 = "b60616c70eff0cc2c0831b6aace75940aeb0939d" -uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" -version = "0.4.1" - -[[MCMCChains]] -deps = ["AxisArrays", "DataFrames", "Distributions", "KernelDensity", "LinearAlgebra", "Plots", "Random", "RecipesBase", "Serialization", "Showoff", "SpecialFunctions", "Statistics", "StatsBase"] -git-tree-sha1 = "54a33641c1be24a4d254b785f42b545c4b65253b" -uuid = "c7f686f2-ff18-58e9-bc7b-31028e88f75d" -version = "0.3.14" - -[[MKL_jll]] -deps = ["IntelOpenMP_jll", "Libdl", "Pkg"] -git-tree-sha1 = "0ce9a7fa68c70cf83c49d05d2c04d91b47404b08" -uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" -version = "2020.1.216+0" - -[[MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.5" - -[[MappedArrays]] -git-tree-sha1 = "e2a02fe7ee86a10c707ff1756ab1650b40b140bb" -uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" -version = "0.2.2" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MbedTLS]] -deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"] -git-tree-sha1 = "426a6978b03a97ceb7ead77775a1da066343ec6e" -uuid = "739be429-bea8-5141-9913-cc70e7f3736d" -version = "1.0.2" - -[[MbedTLS_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "f85473aeb7a2561a5c58c06c4868971ebe2bcbff" -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.16.6+0" - -[[Measures]] -git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" -uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" -version = "0.3.1" - -[[Missings]] -deps = ["DataAPI"] -git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" -uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "0.4.3" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[MuladdMacro]] -git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68" -uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" -version = "0.2.2" - -[[NLSolversBase]] -deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"] -git-tree-sha1 = "7c4e66c47848562003250f28b579c584e55becc0" -uuid = "d41bc354-129a-5804-8e4c-c37616107c6c" -version = "7.6.1" - -[[NNlib]] -deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Requires", "Statistics"] -git-tree-sha1 = "d9f196d911f55aeaff11b11f681b135980783824" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.6.6" - -[[NaNMath]] -git-tree-sha1 = "928b8ca9b2791081dc71a51c55347c27c618760f" -uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" -version = "0.3.3" - -[[OffsetArrays]] -git-tree-sha1 = "ab697473e983a7499f463b696da8e8feb1b20ffd" -uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.1.0" - -[[Ogg_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "59cf7a95bf5ac39feac80b796e0f39f9d69dc887" -uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051" -version = "1.3.4+0" - -[[OpenBLAS_jll]] -deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] -git-tree-sha1 = "1887096f6897306a4662f7c5af936da7d5d1a062" -uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" -version = "0.3.9+4" - -[[OpenSSL_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "7aaaded15bf393b5f34c2aad5b765c18d26cb495" -uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "1.1.1+4" - -[[OpenSpecFun_jll]] -deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] -git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" -uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" -version = "0.5.3+3" - -[[Optim]] -deps = ["Compat", "FillArrays", "LineSearches", "LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "PositiveFactorizations", "Printf", "SparseArrays", "StatsBase"] -git-tree-sha1 = "c05aa6b694d426df87ff493306c1c5b4b215e148" -uuid = "429524aa-4258-5aef-a3af-852621145aeb" -version = "0.22.0" - -[[Opus_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "002c18f222a542907e16c83c64a1338992da7e2c" -uuid = "91d4177d-7536-5919-b921-800302f37372" -version = "1.3.1+1" - -[[OrderedCollections]] -git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.2.0" - -[[PDMats]] -deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] -git-tree-sha1 = "2fc6f50ddd959e462f0a2dbc802ddf2a539c6e35" -uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" -version = "0.9.12" - -[[Parameters]] -deps = ["OrderedCollections", "UnPack"] -git-tree-sha1 = "38b2e970043613c187bd56a995fe2e551821eb4a" -uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" -version = "0.12.1" - -[[Parsers]] -deps = ["Dates", "Test"] -git-tree-sha1 = "20ef902ea02f7000756a4bc19f7b9c24867c6211" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "1.0.6" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[PlotThemes]] -deps = ["PlotUtils", "Requires", "Statistics"] -git-tree-sha1 = "c6f5ea535551b3b16835134697f0c65d06c94b91" -uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" -version = "2.0.0" - -[[PlotUtils]] -deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"] -git-tree-sha1 = "e18e0e51ff07bf92bb7e06dcb9c082a4e125e20c" -uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" -version = "1.0.5" - -[[Plots]] -deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "GeometryTypes", "JSON", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"] -git-tree-sha1 = "d2790295d9b65b98c44fe74815743bc101df2e19" -uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -version = "1.5.2" - -[[PooledArrays]] -deps = ["DataAPI"] -git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c" -uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" -version = "0.5.3" - -[[PositiveFactorizations]] -deps = ["LinearAlgebra", "Test"] -git-tree-sha1 = "127c47b91990c101ee3752291c4f45640eeb03d1" -uuid = "85a6dd25-e78a-55b7-8502-1745935b8125" -version = "0.2.3" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[ProgressLogging]] -deps = ["Logging", "SHA", "UUIDs"] -git-tree-sha1 = "59398022b661b6fd569f25de6b18fde39843196a" -uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c" -version = "0.1.3" - -[[ProgressMeter]] -deps = ["Distributed", "Printf"] -git-tree-sha1 = "3e1784c27847bba115815d4d4e668b99873985e5" -uuid = "92933f4c-e287-5a05-a399-4b506db050ca" -version = "1.3.1" - -[[QuadGK]] -deps = ["DataStructures", "LinearAlgebra"] -git-tree-sha1 = "dc84e810393cfc6294248c9032a9cdacc14a3db4" -uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" -version = "2.3.1" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[RangeArrays]] -git-tree-sha1 = "b9039e93773ddcfc828f12aadf7115b4b4d225f5" -uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" -version = "0.3.2" - -[[Ratios]] -git-tree-sha1 = "37d210f612d70f3f7d57d488cb3b6eff56ad4e41" -uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" -version = "0.4.0" - -[[RecipesBase]] -git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc" -uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" -version = "1.0.1" - -[[RecipesPipeline]] -deps = ["Dates", "PlotUtils", "RecipesBase"] -git-tree-sha1 = "d2a58b8291d1c0abae6a91489973f8a92bf5c04a" -uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" -version = "0.1.11" - -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - -[[Requires]] -deps = ["UUIDs"] -git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.0.1" - -[[Rmath]] -deps = ["Random", "Rmath_jll"] -git-tree-sha1 = "86c5647b565873641538d8f812c04e4c9dbeb370" -uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" -version = "0.6.1" - -[[Rmath_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "d76185aa1f421306dec73c057aa384bad74188f0" -uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" -version = "0.2.2+1" - -[[Roots]] -deps = ["Printf"] -git-tree-sha1 = "c2f7348c55d1433d1cab0159b4d2c6d27af36fc4" -uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" -version = "1.0.2" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Showoff]] -deps = ["Dates"] -git-tree-sha1 = "e032c9df551fb23c9f98ae1064de074111b7bc39" -uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" -version = "0.3.1" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SortingAlgorithms]] -deps = ["DataStructures", "Random", "Test"] -git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" -uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "0.3.1" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[SpecialFunctions]] -deps = ["OpenSpecFun_jll"] -git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.10.3" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "5c06c0aeb81bef54aed4b3f446847905eb6cbda0" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.12.3" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[StatsBase]] -deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"] -git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45" -uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -version = "0.33.0" - -[[StatsFuns]] -deps = ["Rmath", "SpecialFunctions"] -git-tree-sha1 = "04a5a8e6ab87966b43f247920eab053fd5fdc925" -uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" -version = "0.9.5" - -[[StructArrays]] -deps = ["Adapt", "DataAPI", "Tables"] -git-tree-sha1 = "8099ed9fb90b6e754d6ba8c6ed8670f010eadca0" -uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.4.4" - -[[SuiteSparse]] -deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] -uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" - -[[TableTraits]] -deps = ["IteratorInterfaceExtensions"] -git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" -uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" -version = "1.0.0" - -[[Tables]] -deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] -git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3" -uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.0.4" - -[[TerminalLoggers]] -deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] -git-tree-sha1 = "cbea752b5eef52a3e1188fb31580c3e4fa0cbc35" -uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" -version = "0.1.2" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[Tracker]] -deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"] -git-tree-sha1 = "1e0b60f070020ed18ef364cccecabcb75c8bc23c" -uuid = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" -version = "0.2.7" - -[[Turing]] -deps = ["AdvancedHMC", "Bijectors", "BinaryProvider", "Distributions", "DistributionsAD", "ForwardDiff", "Libtask", "LinearAlgebra", "MCMCChains", "MacroTools", "Markdown", "PDMats", "ProgressMeter", "Random", "Reexport", "Requires", "SpecialFunctions", "Statistics", "StatsFuns", "Tracker", "Zygote"] -git-tree-sha1 = "f2332f24adc1a3a1c5c451caea90dc72093dd709" -uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" -version = "0.7.0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[UnPack]] -git-tree-sha1 = "d4bfa022cd30df012700cf380af2141961bb3bfb" -uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" -version = "1.0.1" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[WoodburyMatrices]] -deps = ["LinearAlgebra", "SparseArrays"] -git-tree-sha1 = "28ffe06d28b1ba8fdb2f36ec7bb079fac81bac0d" -uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" -version = "0.5.2" - -[[Zlib_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "622d8b6dc0c7e8029f17127703de9819134d1b71" -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.11+14" - -[[Zygote]] -deps = ["AbstractFFTs", "ArrayLayouts", "ChainRules", "FillArrays", "ForwardDiff", "Future", "IRTools", "InteractiveUtils", "LinearAlgebra", "MacroTools", "NNlib", "Random", "Requires", "Statistics", "ZygoteRules"] -git-tree-sha1 = "2e2c82549fb0414df10469082fd001e2ede8547c" -uuid = "e88e6eb3-aa80-5325-afca-941959d7151f" -version = "0.4.22" - -[[ZygoteRules]] -deps = ["MacroTools"] -git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" -uuid = "700de1a5-db45-46bc-99cf-38207098b444" -version = "0.2.0" - -[[libass_jll]] -deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "Libdl", "Pkg", "Zlib_jll"] -git-tree-sha1 = "027a304b2a90de84f690949a21f94e5ae0f92c73" -uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0" -version = "0.14.0+2" - -[[libfdk_aac_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "480c7ed04f68ea3edd4c757f5db5b6a0a4e0bd99" -uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280" -version = "0.1.6+2" - -[[libvorbis_jll]] -deps = ["Libdl", "Ogg_jll", "Pkg"] -git-tree-sha1 = "6a66f65b5275dfa799036c8a3a26616a0a271c4a" -uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a" -version = "1.3.6+4" - -[[x264_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "d89346fe63a6465a9f44e958ac0e3d366af90b74" -uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a" -version = "2019.5.25+2" - -[[x265_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "61324ad346b00a6e541896b94201c9426591e43a" -uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76" -version = "3.0.0+1" From 9d3bb1c015fec89a4d295f890af2f48c526f8f3a Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:15:12 +0200 Subject: [PATCH 40/44] remove Test and Turing from Project.toml, not DynamicPPL (needed in trace.jl) --- Project.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 797b2fc1..771218b2 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,4 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" +StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" \ No newline at end of file From e2b4897a53c8c53c6146840ee572a04bf6be29ad Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:17:11 +0200 Subject: [PATCH 41/44] add references to README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4c40f03e..0b241dae 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ # AdvancedPS.jl + +## References + +* Doucet, Arnaud, and Adam M. Johansen. "A tutorial on particle filtering and smoothing: Fifteen years later." Handbook of nonlinear filtering 12, no. 656-704 (2009): 3. + +* Andrieu, Christophe, Arnaud Doucet, and Roman Holenstein. "Particle Markov chain Monte Carlo methods." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 72, no. 3 (2010): 269-342. + +* Tripuraneni, Nilesh, Shixiang Shane Gu, Hong Ge, and Zoubin Ghahramani. "Particle gibbs for infinite hidden Markov models." In Advances in Neural Information Processing Systems, pp. 2395-2403. 2015. + +* Lindsten, Fredrik, Michael I. Jordan, and Thomas B. Schön. "Particle Gibbs with ancestor sampling." The Journal of Machine Learning Research 15, no. 1 (2014): 2145-2184. + +* Pitt, Michael K., and Neil Shephard. "Filtering via simulation: Auxiliary particle filters." Journal of the American statistical association 94, no. 446 (1999): 590-599. + +* Doucet, Arnaud, Nando de Freitas, and Neil Gordon. "Sequential Monte Carlo Methods in Practice." + +* Del Moral, Pierre, Arnaud Doucet, and Ajay Jasra. "Sequential Monte Carlo samplers." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 68, no. 3 (2006): 411-436. From d165401b5500b5670a3f05a833001b40d40fbef3 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:24:29 +0200 Subject: [PATCH 42/44] improve docstrings --- src/particlecontainer.jl | 6 ++++++ src/resampling.jl | 4 ++++ src/sweep.jl | 18 ++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/particlecontainer.jl b/src/particlecontainer.jl index 9ddc427d..05577616 100644 --- a/src/particlecontainer.jl +++ b/src/particlecontainer.jl @@ -41,6 +41,7 @@ end """ reset_logweights!(pc::ParticleContainer) + Reset all unnormalized logarithmic weights to zero. """ function reset_logweights!(pc::ParticleContainer) @@ -50,6 +51,7 @@ end """ increase_logweight!(pc::ParticleContainer, i::Int, x) + Increase the unnormalized logarithmic weight of the `i`th particle with `x`. """ function increase_logweight!(pc::ParticleContainer, i, logw) @@ -59,24 +61,28 @@ end """ getweights(pc::ParticleContainer) + Compute the normalized weights of the particles. """ getweights(pc::ParticleContainer) = softmax(pc.logWs) """ getweight(pc::ParticleContainer, i) + Compute the normalized weight of the `i`th particle. """ getweight(pc::ParticleContainer, i) = exp(pc.logWs[i] - logZ(pc)) """ logZ(pc::ParticleContainer) + Return the logarithm of the normalizing constant of the unnormalized logarithmic weights. """ logZ(pc::ParticleContainer) = logsumexp(pc.logWs) """ effectiveSampleSize(pc::ParticleContainer) + Compute the effective sample size ``1 / ∑ wᵢ²``, where ``wᵢ```are the normalized weights. """ function effectiveSampleSize(pc::ParticleContainer) diff --git a/src/resampling.jl b/src/resampling.jl index 3fd6aaf7..d0a7d29c 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -43,6 +43,7 @@ end """ resample_multinomial(w, num_particles) + Multinomial resampling scheme """ function resample_multinomial(w::AbstractVector{<:Real}, num_particles::Integer) @@ -51,6 +52,7 @@ end """ resample_residual(w, num_particles) + Residual resampling scheme """ function resample_residual(w::AbstractVector{<:Real}, num_particles::Integer) @@ -84,6 +86,7 @@ end """ resample_stratified(weights, n) + Return a vector of `n` samples `x₁`, ..., `xₙ` from the numbers 1, ..., `length(weights)`, generated by stratified resampling. In stratified resampling `n` ordered random numbers `u₁`, ..., `uₙ` are generated, where @@ -127,6 +130,7 @@ end """ resample_systematic(weights, n) + Return a vector of `n` samples `x₁`, ..., `xₙ` from the numbers 1, ..., `length(weights)`, generated by systematic resampling. In systematic resampling a random number ``u \\sim U[0, 1)`` is used to generate `n` ordered diff --git a/src/sweep.jl b/src/sweep.jl index e8f95ac1..e0a3890f 100644 --- a/src/sweep.jl +++ b/src/sweep.jl @@ -1,6 +1,6 @@ """ -resample_propagate!(pc::ParticleContainer[, scheme, ref = nothing; - weights = getweights(pc)]) + resample_propagate!(pc::ParticleContainer[, scheme, ref = nothing; weights = getweights(pc)]) + Resample and propagate the particles in `pc`, without ESS thresholding. Function `scheme` is the scheme used to resample ancestor indices based on the particle weights. For Particle Gibbs sampling, one can provide a reference particle `ref` that is ensured to survive the resampling step. @@ -61,8 +61,9 @@ end """ -resample_propagate!(pc::ParticleContainer, resampler::ResampleWithESSThreshold[, ref = nothing; - weights = getweights(pc)]) + resample_propagate!(pc::ParticleContainer, resampler::ResampleWithESSThreshold[, + ref = nothing; weights = getweights(pc)]) + Resample and propagate the particles in `pc`, with ESS thresholding. For Particle Gibbs sampling, one can provide a reference particle `ref` that is ensured to survive the resampling step. """ @@ -84,7 +85,8 @@ end """ -reweight!(pc::ParticleContainer) + reweight!(pc::ParticleContainer) + Check if the final time step is reached, and otherwise reweight the particles by considering the next observation. """ @@ -130,11 +132,11 @@ function reweight!(pc::ParticleContainer) end """ -sweep!(pc::ParticleContainer, resampler) + sweep!(pc::ParticleContainer, resampler) + Perform a particle sweep and return an unbiased estimate of the log evidence. The resampling steps use the given `resampler`. -# Reference -Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. +# Reference: Del Moral, P., Doucet, A., & Jasra, A. (2006). Sequential monte carlo samplers. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(3), 411-436. """ function sweep!(pc::ParticleContainer, resampler) From fbb3b75866916d6100e545143ea04efa91c4bb46 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:26:51 +0200 Subject: [PATCH 43/44] correct reasmpling.jl tests --- test/resampling.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/resampling.jl b/test/resampling.jl index 7302e20a..61ea7b56 100644 --- a/test/resampling.jl +++ b/test/resampling.jl @@ -9,9 +9,8 @@ using AdvancedPS resMultinomial= resample_multinomial(D, num_samples ) resResidual = resample_residual(D, num_samples ) - - @test sum(resSystematic .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples - @test sum(resStratified .== 2) ≈ (num_samples * 0.4) atol=1e-3*num_samples - @test sum(resMultinomial .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples - @test sum(resResidual .== 2) ≈ (num_samples * 0.4) atol=1e-2*num_samples + @test count(==(2), resSystematic) ≈ 0.4 * num_samples atol=1e-3*num_samples + @test count(==(2), resStratified) ≈ 0.4 * num_samples atol=1e-3*num_samples + @test count(==(2), resMultinomial) ≈ 0.4 * num_samples atol=1e-2*num_samples + @test count(==(2), resResidual) ≈ 0.4 * num_samples atol=1e-2*num_samples end From 3d25a1d2d445856a06a39c84fcd73a9daf62cf86 Mon Sep 17 00:00:00 2001 From: JS Denain Date: Tue, 18 Aug 2020 16:42:02 +0200 Subject: [PATCH 44/44] added [extras] and [target] to Project.toml for Test, does not work --- Manifest.toml | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++ Project.toml | 8 +- 2 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 00000000..e3c5b3b3 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,311 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractMCMC]] +deps = ["ConsoleProgressMonitor", "Distributed", "Logging", "LoggingExtras", "ProgressLogging", "Random", "StatsBase", "TerminalLoggers"] +git-tree-sha1 = "31a0a7b957525748e05599488ca6eef476fef12b" +uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001" +version = "1.0.1" + +[[AbstractTrees]] +deps = ["Markdown"] +git-tree-sha1 = "33e450545eaf7699da1a6e755f9ea65f14077a45" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.3.3" + +[[ArgCheck]] +git-tree-sha1 = "dedbbb2ddb876f899585c4ec4433265e3017215a" +uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" +version = "2.1.0" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Bijectors]] +deps = ["ArgCheck", "Compat", "Distributions", "LinearAlgebra", "MappedArrays", "NNlib", "Random", "Reexport", "Requires", "Roots", "SparseArrays", "Statistics", "StatsFuns"] +git-tree-sha1 = "7049f8682dab97b87c30759057058cfec63e4fc6" +uuid = "76274a88-744f-5084-9051-94815aaf08c4" +version = "0.8.2" + +[[BinaryProvider]] +deps = ["Libdl", "Logging", "SHA"] +git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.10" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "083e7e5ec3ef443e9dcb6dd3fbcb815879823bfa" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "3.14.0" + +[[CompilerSupportLibraries_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612" +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "0.3.3+0" + +[[ConsoleProgressMonitor]] +deps = ["Logging", "ProgressMeter"] +git-tree-sha1 = "3ab7b2136722890b9af903859afcf457fa3059e8" +uuid = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b" +version = "0.1.2" + +[[DataAPI]] +git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.3.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "88d48e133e6d3dd68183309877eac74393daa7eb" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.17.20" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"] +git-tree-sha1 = "dec9607adfa6a82399cce0bd9b8557f8cc3b7bcd" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.23.9" + +[[DynamicPPL]] +deps = ["AbstractMCMC", "Bijectors", "Distributions", "MacroTools", "Random", "ZygoteRules"] +git-tree-sha1 = "b46046c78801149cc9f2b80e806fbd5a2891b652" +uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" +version = "0.8.2" + +[[FillArrays]] +deps = ["LinearAlgebra", "Random", "SparseArrays"] +git-tree-sha1 = "9a457808000939be5f052291cbed7de409c2839d" +uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" +version = "0.9.4" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[LeftChildRightSiblingTrees]] +deps = ["AbstractTrees"] +git-tree-sha1 = "71be1eb5ad19cb4f61fa8c73395c0338fd092ae0" +uuid = "1d6d02ad-be62-4b6b-8a6d-2f90e265016e" +version = "0.1.2" + +[[LibGit2]] +deps = ["Printf"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[Libtask]] +deps = ["BinaryProvider", "Libdl", "Pkg"] +git-tree-sha1 = "68a658db4792dfc468ea2aabcf06f3f74f153f23" +uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" +version = "0.4.1" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[LoggingExtras]] +deps = ["Dates"] +git-tree-sha1 = "03289aba73c0abc25ff0229bed60f2a4129cd15c" +uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" +version = "0.4.2" + +[[MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.5" + +[[MappedArrays]] +git-tree-sha1 = "e2a02fe7ee86a10c707ff1756ab1650b40b140bb" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.2" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.3" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "Pkg", "Requires", "Statistics"] +git-tree-sha1 = "8ec4693a5422f0b064ce324f59351f24aa474893" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.7.4" + +[[OpenSpecFun_jll]] +deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] +git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" +uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" +version = "0.5.3+3" + +[[OrderedCollections]] +git-tree-sha1 = "293b70ac1780f9584c89268a6e2a560d938a7065" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.3.0" + +[[PDMats]] +deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b3405086eb6a974eba1958923d46bc0e1c2d2d63" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.10.0" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[ProgressLogging]] +deps = ["Logging", "SHA", "UUIDs"] +git-tree-sha1 = "59398022b661b6fd569f25de6b18fde39843196a" +uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c" +version = "0.1.3" + +[[ProgressMeter]] +deps = ["Distributed", "Printf"] +git-tree-sha1 = "2de4cddc0ceeddafb6b143b5b6cd9c659b64507c" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "1.3.2" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra"] +git-tree-sha1 = "0ab8a09d4478ebeb99a706ecbf8634a65077ccdc" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.4.0" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["UUIDs"] +git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "1.0.1" + +[[Rmath]] +deps = ["Random", "Rmath_jll"] +git-tree-sha1 = "86c5647b565873641538d8f812c04e4c9dbeb370" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.6.1" + +[[Rmath_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "d76185aa1f421306dec73c057aa384bad74188f0" +uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" +version = "0.2.2+1" + +[[Roots]] +deps = ["Printf"] +git-tree-sha1 = "1211c7c1928c1ed29cdcef65979b7a791e3b9fbe" +uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" +version = "1.0.5" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["OpenSpecFun_jll"] +git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.10.3" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"] +git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.33.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions"] +git-tree-sha1 = "04a5a8e6ab87966b43f247920eab053fd5fdc925" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.9.5" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[TerminalLoggers]] +deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] +git-tree-sha1 = "cbea752b5eef52a3e1188fb31580c3e4fa0cbc35" +uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" +version = "0.1.2" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[ZygoteRules]] +deps = ["MacroTools"] +git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" +uuid = "700de1a5-db45-46bc-99cf-38207098b444" +version = "0.2.0" diff --git a/Project.toml b/Project.toml index 771218b2..d27a4212 100644 --- a/Project.toml +++ b/Project.toml @@ -9,4 +9,10 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8" Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" \ No newline at end of file +StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[target] +test = ["Test"]