Skip to content

Commit f8d63e2

Browse files
authored
Fix deprecations (#62)
1 parent 00da11a commit f8d63e2

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ julia = "1"
1717
[extras]
1818
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
1919
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
20+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2021
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
2122
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
2223
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2324

2425
[targets]
25-
test = ["StructArrays", "MCMCChains", "Test", "ForwardDiff", "DiffResults"]
26+
test = ["DiffResults", "ForwardDiff", "LinearAlgebra", "MCMCChains", "StructArrays", "Test"]

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ using AdvancedMH
1616
using Distributions
1717
using MCMCChains
1818

19+
using LinearAlgebra
20+
1921
# Generate a set of data from the posterior we want to estimate.
2022
data = rand(Normal(0, 1), 30)
2123

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

3032
# Set up our sampler with a joint multivariate Normal proposal.
31-
spl = RWMH(MvNormal(2,1))
33+
spl = RWMH(MvNormal(zeros(2), I))
3234

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

140+
using LinearAlgebra
141+
138142
# Generate a set of data from the posterior we want to estimate.
139143
data = rand(Normal(0, 1), 30)
140144

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

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

153157
# Sample from the posterior.
154158
chain = sample(model, spl, 100000; init_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])

test/emcee.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
# perform stretch move and sample from normal distribution in initial step
5959
Random.seed!(100)
60-
sampler = Ensemble(1_000, StretchProposal(MvNormal(2, 1)))
60+
sampler = Ensemble(1_000, StretchProposal(MvNormal(zeros(2), I)))
6161
chain = sample(model, sampler, 1_000;
6262
param_names = ["logs", "m"], chain_type = Chains)
6363
@test chain isa Chains

test/runtests.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using AdvancedMH
2+
using DiffResults
23
using Distributions
3-
using StructArrays
4+
using ForwardDiff
45
using MCMCChains
6+
using StructArrays
57

8+
using LinearAlgebra
69
using Random
710
using Test
8-
using DiffResults
9-
using ForwardDiff
1011

1112
include("util.jl")
1213

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

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

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

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

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

0 commit comments

Comments
 (0)