Really nice summary here of the different ways of thinking of priors https://statmodeling.stat.columbia.edu/2025/05/21/prior-as-data-prior-as-belief-prior-as-soft-constraint-prior-as-unconditional-distribution-in-a-generative-model/
For a while I’ve been a fan of the idea of prior stacking but in practice not made much use of it.
In unrelated but related thinking @sambrand was telling me about product distributions in Julia which I guess could be a neat way of expressing that Product Distributions · Distributions.jl
2 Likes
@sambrand was telling me about product distributions in Julia which I guess could be a neat way of expressing that Product Distributions · Distributions.jl
I wish I could claim credit but the lovely people over at Turing
put me onto this handy Distributional form
opened 01:44PM - 22 May 25 UTC
closed 05:46PM - 22 May 25 UTC
Hi everyone,
Suppose I have a struct type where I have guaranteed that every fi… eld is a Distribution type; what is the cleanest way to create a model constructor that automates just sampling from each dist?
### Desired behaviour
I'd like to automate the below to arbitrary struct types that have only distribution typed fields where `sample_struct` constructs the correct Turing model
```julia
using Distributions, Turing
struct MyDists{A,B}
a::A
b::B
end
mydists = MyDists(Normal(), Normal())
# Want to automate this
########
@model function sample_struct(mydists::MyDists)
a ~ mydists.a
b ~ mydists.b
return (;a, b)
end
########
mdl = sample_struct(mydists)
mdl()
# (a = -0.26088214704785606, b = -0.23951001313925616)
```
### Bad first passes
I can do something like this, but its pretty horrible and also the type inference will be bad (see the `Float64` specialisation)
```julia
@model function simple_sample(dist)
θ ~ dist
return θ
end
@model function testmodel(params)
names = fieldnames(typeof(params))
x = Vector{Float64}(undef, length(names))
for (i, field) in enumerate(names)
x[i] ~ to_submodel(prefix(simple_sample(getfield(params, field)), field), false)
end
return x
end
```
I've tried some metaprogramming but I get a bit lost with trying to wrap `@model` inside another macro call.
Does anyone have any nice ideas/suggestions?
1 Like
I think I know what you mean by prior stacking, but can you give an example? I’m thinking towards when you do some kind of rolling window inference and use the posteriors of the previous inference as prior in the next.
In speculation mode (and way off topic but there you go), I do wonder that if you are doing that kind of thing (which as you say is easier to reason about than to do in MCMC) then maybe its an indication that we should be doing SMC?
1 Like
I mean it in the sense they use it in the blog using a weakly informative prior to not be crazy with a second prior which is effectively data