# Turing.jl - Create priors dynamically

**URL:** <https://discourse.julialang.org/t/turing-jl-create-priors-dynamically/110587>\
**Category:** Probabilistic Programming\
**Tags:** package, turing\
**Created:** [February 22, 2024, 3:30pm UTC](https://discourse.julialang.org/t/turing-jl-create-priors-dynamically/110587 "2024-02-22T15:30:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafalel\_Jupio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafalel_jupio/32/202530_2.png) [@Rafalel\_Jupio](https://discourse.julialang.org/u/Rafalel_Jupio)\
**Post date:** [February 22, 2024, 3:30pm UTC](https://discourse.julialang.org/t/turing-jl-create-priors-dynamically/110587/1 "2024-02-22T15:30:56Z")

</div>

Hello everyone,

So in the problem I am currently working on, my parameter space changes a lot, meaning the number of parameters I want to make inference on (using Bayesian statistics, through the Turing.jl package) is not constant.

What I would like to do is to pass a vector of “variable names” and a vector of priors to the Turing model, and it associates each variable name to the corresponding prior (using the tilde operator). So something like:

```julia
for (i,var) in enumerate(variable_names)
     var ~ prior_vector[i]
end

```

Is that possible? Hope the question is clear,  
RJ

---

<div class="post-metadata">

**Author:** ![sethaxen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sethaxen/32/35604_2.png) [@sethaxen](https://discourse.julialang.org/u/sethaxen)\
**Post date:** [February 26, 2024, 12:23pm UTC](https://discourse.julialang.org/t/turing-jl-create-priors-dynamically/110587/2 "2024-02-26T12:23:17Z")

</div>

Is anything in [Probabilistic Modelling using the Infinite Mixture Model](https://turinglang.org/v0.30/tutorials/06-infinite-mixture-model/) helpful for you?

---

<div class="post-metadata">

**Author:** ![Rafalel\_Jupio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafalel_jupio/32/202530_2.png) [@Rafalel\_Jupio](https://discourse.julialang.org/u/Rafalel_Jupio)\
**Post date:** [March 1, 2024, 3:22pm UTC](https://discourse.julialang.org/t/turing-jl-create-priors-dynamically/110587/3 "2024-03-01T15:22:34Z")

</div>

Yes! Actually that’s all I needed. For reference, what I did in the Turing model was to first initialise a vector or 0’s, and loop over it to sample from the priors:

```julia
p = zeros(float64, length(priors))
for i in eachindex(priors)
    p[i] ~ priors[i]
end

```

Thanks @sethaxen ! Helped a lot
