# Fixed distribution in Turing

**URL:** https://discourse.julialang.org/t/fixed-distribution-in-turing/103540
**Category:** General Usage
**Tags:** turing
**Created:** [September 5, 2023, 12:22pm UTC](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540 "2023-09-05T12:22:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![99dB](https://avatars.discourse-cdn.com/v4/letter/9/838e76/32.png) [@99dB](https://discourse.julialang.org/u/99dB)
#### Post date: [September 5, 2023, 12:22pm UTC](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540/1 "2023-09-05T12:22:36Z")

</div>

Hi all,

Is it possible to sample a distribution in Turing without updating it?

For example from this tutorial: [https://turing.ml/dev/tutorials/10-bayesian-differential-equations/](https://turing.ml/dev/tutorials/10-bayesian-differential-equations/)

```julia
@model function fitlv(data, prob)
    # Prior distributions.
    σ ~ InverseGamma(2, 3)
    α ~ truncated(Normal(1.5, 0.5), 0.5, 2.5)
    β ~ truncated(Normal(1.2, 0.5), 0, 2)
    γ ~ truncated(Normal(3.0, 0.5), 1, 4)
    δ ~ truncated(Normal(1.0, 0.5), 0, 2)

    # Simulate Lotka-Volterra model. 
    p = [α, β, γ, δ]
    predicted = solve(prob, Tsit5(); p=p, saveat=0.1)

    # Observations.
    for i in 1:length(predicted)
        data[:, i] ~ MvNormal(predicted[i], σ^2 * I)
    end

    return nothing
end

model = fitlv(odedata, prob)

# Sample 3 independent chains with forward-mode automatic differentiation (the default).
chain = sample(model, NUTS(0.65), MCMCSerial(), 1000, 3; progress=false)

```

Let’s say that I already know the distribution of `α` but not `β, γ, δ`. How to consider the `α` distribution as a “fixed” distribution and keep track of the samples while still estimating the posteriors for the other parameters?

Many thanks.

---

<div class="post-metadata">

### Author: ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)
#### Post date: [September 6, 2023, 12:26am UTC](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540/2 "2023-09-06T00:26:01Z")

</div>

This question came up here a few years ago:

> [@Turing.jl: fix some parameters to prior distribution](https://discourse.julialang.org/t/turing-jl-fix-some-parameters-to-prior-distribution/41095):
>
> I’m testing out Turing.jl and I’m wondering if I can specify a subset of parameters to remain fixed at their prior distribution. I would still like to sample these parameters to get a joint distribution with the other parameters that I do want the posterior for. For example, say I have the following model. Can I specify β to remain at its prior distribution? @model bayes\_sir(y) = begin # Calculate number of timepoints l = length(y) i₀ ~ Uniform(0.0,1.0) β ~ Uniform(0.0,1.0) …

See also this issue:

> <https://github.com/TuringLang/Turing.jl/issues/1321>
>
> As per this discussion, https://discourse.julialang.org/t/turing-jl-fix-some-par…ameters-to-prior-distribution/41095/11, I would like to be able force some parameters to remain at their prior distribution and only perform inference on a subset of parameters. Could this be achieved by enabling \`Prior\` Gibbs for compositional sampling? For example to do inference on \`a\` but not on \`b\`:
> 
> \`\`\`
> chn = sample(model, Gibbs(NUTS(-1, 0.65, :a), Prior(:b)), 1000)
> \`\`\`

I’ve had cases where this would be really useful. There is a `Prior()` sampler, but it doesn’t seem to have a method accepting a symbol to tell it which variables to apply it to inside a Gibbs sampler.

---

<div class="post-metadata">

### Author: ![99dB](https://avatars.discourse-cdn.com/v4/letter/9/838e76/32.png) [@99dB](https://discourse.julialang.org/u/99dB)
#### Post date: [September 11, 2023, 1:07pm UTC](https://discourse.julialang.org/t/fixed-distribution-in-turing/103540/3 "2023-09-11T13:07:29Z")

</div>

Thanks a lot @ElOceanografo!
