Skip to content

A repo for testing Turing.jl with SparsityDetection.jl and SparseDiffTools.jl.

Notifications You must be signed in to change notification settings

mohamed82008/TuringSparseDiff.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

using Turing, SparsityDetection
using Turing.DynamicPPL: VarInfo, LazyVarInfo, resetlogp!, getlogpvec, Sampler
Turing.setadbackend(:sparseforwarddiff)

@model demo() = begin
    m ~ Normal()
end
model = demo()
varinfo = VarInfo(model)
lvi = LazyVarInfo(varinfo)
resetlogp!(lvi)
spl = Sampler(HMC(0.01, 1), model)
model(lvi, spl)
N = lvi.lastidx[]
resetlogp!(lvi)

function f(out, x)
    new_vi = VarInfo(lvi, spl, x)
    model(new_vi, spl)
    out .= getlogpvec(new_vi)
    return out
end

x = rand(1)
y = zeros(1)
f(y, x)
jacobian_sparsity(f, y, x)

# If the above works, the following line should also work.
# sample(demo(), HMC(0.01, 1), 10)

About

A repo for testing Turing.jl with SparsityDetection.jl and SparseDiffTools.jl.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published