Skip to content

Commit 87384dd

Browse files
committed
added metabayesian model
1 parent 95e60ea commit 87384dd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

main.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ end
115115
@include_model "Effect of model size" "n500"
116116
@include_model "PosteriorDB" "pdb_eight_schools_centered"
117117
@include_model "PosteriorDB" "pdb_eight_schools_noncentered"
118+
@include_model "Miscellaneous features" "metabayesian_MH"
118119

119120
# The entry point to this script itself begins here
120121
if ARGS == ["--list-model-keys"]

models/metabayesian_MH.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#=
2+
This is a "meta-Bayesian" model, where the generative model includes an inversion of a different generative model.
3+
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.
4+
Here we use a Metropolis-Hasting sampler implemented with Turing as the inversion of the inner "subjective" model.
5+
=#
6+
7+
# Inner model function
8+
@model function inner_model(observation, prior_μ = 0, prior_σ = 1)
9+
10+
# The innter model's prior
11+
mean ~ Normal(prior_μ, prior_σ)
12+
13+
# The inner model's likelihood
14+
observation ~ Normal(mean, 1)
15+
end
16+
17+
# Outer model function
18+
@model function metabayesian_MH(observation, action, inner_sampler = MH(), inner_n_samples = 20)
19+
20+
### Sample parameters for the inner inference and response ###
21+
22+
#The inner model's prior's sufficient statistics
23+
subj_prior_μ ~ Normal(0, 1)
24+
subj_prior_σ = 1.0
25+
26+
# #Inverse temperature for actions
27+
β ~ Exponential(1)
28+
29+
### "Perceptual inference": running the inner model ###
30+
31+
#Condition the inner model
32+
inner_m = inner_model(observation, subj_prior_μ, subj_prior_σ)
33+
34+
#Run the inner Bayesian inference
35+
chns = sample(inner_m, inner_sampler, inner_n_samples, progress = false)
36+
37+
#Extract subjective point estimate
38+
subj_mean_expectationₜ = mean(chns[:mean])
39+
40+
41+
### "Response model": picking an action ###
42+
43+
#The action is a Gaussian-noise report of the subjective point estimate
44+
action ~ Normal(subj_mean_expectationₜ, β)
45+
46+
end
47+
48+
model = metabayesian_MH(0.0, 1.0)

0 commit comments

Comments
 (0)