Newer
Older
using Random, StatsBase, Distributions
using Graphs
using AbstractMCMC: MCMCSerial #, MCMCThreads, MCMCDistributed
using CairoMakie
using Test
using Revise
using MultilevelChainSampler
w = CyclicWalk()
s = MetropolisHastings(w)
# Test analytical log density
f = LogDensity(x->-x^2/2)
c = sample(f, s, 1000)
x = vcat(states(c)... )
@test abs(mean(x)) < 0.1
@test abs(std(x) - 0.539560) < 0.1
c = sample(f, s, MCMCSerial(), 100, 5)
display(c)
x = hcat(states(c)...)
@test abs(mean(x)) < 0.1
@test abs(std(x) - 0.539560) < 0.1
# Test sampled log density
g = SampledLogDensity(
[ rand(2) for i=1:100] ,
(x,z)->-4/pi*(sum(z.^2) < x^2) / 2
)
c = sample(g, s, MCMCSerial(), 100, 4)
display(c)
x = hcat(states(c)...)
@test abs(mean(x)) < 0.1
@test abs(std(x) - 0.539560) < 0.1