Skip to content

Commit

Permalink
Fix deprecations (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Aug 26, 2021
1 parent 00da11a commit f8d63e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ julia = "1"
[extras]
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["StructArrays", "MCMCChains", "Test", "ForwardDiff", "DiffResults"]
test = ["DiffResults", "ForwardDiff", "LinearAlgebra", "MCMCChains", "StructArrays", "Test"]
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using AdvancedMH
using Distributions
using MCMCChains

using LinearAlgebra

# Generate a set of data from the posterior we want to estimate.
data = rand(Normal(0, 1), 30)

Expand All @@ -28,7 +30,7 @@ density(θ) = insupport(θ) ? sum(logpdf.(dist(θ), data)) : -Inf
model = DensityModel(density)

# Set up our sampler with a joint multivariate Normal proposal.
spl = RWMH(MvNormal(2,1))
spl = RWMH(MvNormal(zeros(2), I))

# Sample from the posterior.
chain = sample(model, spl, 100000; param_names=["μ", "σ"], chain_type=Chains)
Expand Down Expand Up @@ -135,6 +137,8 @@ using DiffResults
using ForwardDiff
using StructArrays

using LinearAlgebra

# Generate a set of data from the posterior we want to estimate.
data = rand(Normal(0, 1), 30)

Expand All @@ -147,8 +151,8 @@ density(θ) = insupport(θ) ? sum(logpdf.(dist(θ), data)) : -Inf
model = DensityModel(density)

# Set up the sampler with a multivariate Gaussian proposal.
sigma = 1e-1
spl = MALA(x -> MvNormal((sigma^2 / 2) .* x, sigma))
σ² = 0.01
spl = MALA(x -> MvNormal((σ² / 2) .* x, σ² * I))

# Sample from the posterior.
chain = sample(model, spl, 100000; init_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])
Expand Down
2 changes: 1 addition & 1 deletion test/emcee.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

# perform stretch move and sample from normal distribution in initial step
Random.seed!(100)
sampler = Ensemble(1_000, StretchProposal(MvNormal(2, 1)))
sampler = Ensemble(1_000, StretchProposal(MvNormal(zeros(2), I)))
chain = sample(model, sampler, 1_000;
param_names = ["logs", "m"], chain_type = Chains)
@test chain isa Chains
Expand Down
15 changes: 8 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using AdvancedMH
using DiffResults
using Distributions
using StructArrays
using ForwardDiff
using MCMCChains
using StructArrays

using LinearAlgebra
using Random
using Test
using DiffResults
using ForwardDiff

include("util.jl")

Expand All @@ -28,7 +29,7 @@ include("util.jl")
@testset "StaticMH" begin
# Set up our sampler with initial parameters.
spl1 = StaticMH([Normal(0,1), Normal(0, 1)])
spl2 = StaticMH(MvNormal([0.0, 0.0], 1))
spl2 = StaticMH(MvNormal(zeros(2), I))

# Sample from the posterior.
chain1 = sample(model, spl1, 100000; chain_type=StructArray, param_names=["μ", "σ"])
Expand All @@ -44,7 +45,7 @@ include("util.jl")
@testset "RandomWalk" begin
# Set up our sampler with initial parameters.
spl1 = RWMH([Normal(0,1), Normal(0, 1)])
spl2 = RWMH(MvNormal([0.0, 0.0], 1))
spl2 = RWMH(MvNormal(zeros(2), I))

# Sample from the posterior.
chain1 = sample(model, spl1, 100000; chain_type=StructArray, param_names=["μ", "σ"])
Expand Down Expand Up @@ -245,8 +246,8 @@ include("util.jl")

@testset "MALA" begin
# Set up the sampler.
sigma = 1e-1
spl1 = MALA(x -> MvNormal((sigma^2 / 2) .* x, sigma))
σ² = 0.01
spl1 = MALA(x -> MvNormal((σ² / 2) .* x, σ² * I))

# Sample from the posterior with initial parameters.
chain1 = sample(model, spl1, 100000; init_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])
Expand Down

0 comments on commit f8d63e2

Please sign in to comment.