Skip to content

Commit 7f58934

Browse files
committed
Seed inner sampling to ensure reproducibility of gradients
1 parent 70643f1 commit 7f58934

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

models/metabayesian_MH.jl

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ This is a "meta-Bayesian" model, where the generative model includes an inversio
33
These types of models are common in cognitive modelling, where systems of interest (e.g. human subjects) are thought to use Bayesian inference to navigate their environment.
44
Here we use a Metropolis-Hasting sampler implemented with Turing as the inversion of the inner "subjective" model.
55
=#
6+
using Random: Xoshiro
67

78
# Inner model function
89
@model function inner_model(observation, prior_μ = 0, prior_σ = 1)
9-
10-
# The innter model's prior
10+
# The inner model's prior
1111
mean ~ Normal(prior_μ, prior_σ)
12-
1312
# The inner model's likelihood
1413
observation ~ Normal(mean, 1)
1514
end
@@ -21,33 +20,25 @@ end
2120
inner_sampler = MH(),
2221
inner_n_samples = 20,
2322
)
24-
2523
### Sample parameters for the inner inference and response ###
26-
27-
#The inner model's prior's sufficient statistics
24+
# The inner model's prior's sufficient statistics
2825
subj_prior_μ ~ Normal(0, 1)
2926
subj_prior_σ = 1.0
30-
31-
# #Inverse temperature for actions
27+
# Inverse temperature for actions
3228
β = 1
3329

3430
### "Perceptual inference": running the inner model ###
35-
36-
#Condition the inner model
31+
# Condition the inner model
3732
inner_m = inner_model(observation, subj_prior_μ, subj_prior_σ)
38-
39-
#Run the inner Bayesian inference
40-
chns = sample(inner_m, inner_sampler, inner_n_samples, progress = false)
41-
42-
#Extract subjective point estimate
33+
# Run the inner Bayesian inference
34+
chns = sample(Xoshiro(468), inner_m, inner_sampler, inner_n_samples, progress = false)
35+
# Extract subjective point estimate
4336
subj_mean_expectationₜ = mean(chns[:mean])
4437

4538

4639
### "Response model": picking an action ###
47-
48-
#The action is a Gaussian-noise report of the subjective point estimate
40+
# The action is a Gaussian-noise report of the subjective point estimate
4941
action ~ Normal(subj_mean_expectationₜ, β)
50-
5142
end
5243

5344
model = metabayesian_MH(0.0, 1.0)

0 commit comments

Comments
 (0)