# Parameter-dependent prior

**URL:** <https://discuss.bayesflow.org/t/parameter-dependent-prior/275>\
**Category:** General\
**Tags:** research\
**Created:** [July 14, 2026, 8:34am UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275 "2026-07-14T08:34:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MasterODF](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MasterODF](https://discuss.bayesflow.org/u/MasterODF)\
**Post date:** [July 14, 2026, 8:34am UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/1 "2026-07-14T08:34:53Z")

</div>

Hello! I’m working with BayesFlow on a birth-death process experiment, but I’ve hit a technical problem I can’t quite figure out.

My model uses a modified Gaussian prior that is not entirely independent. Specifically, in order to sample from it, this prior relies on certain external factors which vary by culture and requires one specific data point from the observation set itself.

I am trying to figure out how to structure this dependency within the BayesFlow framework:

- Is it possible to implement a prior that is conditional on a subset of the observed data? Accessing that data point is trivially easy, but I’m unsure on how to do this, specially for the “generating simulated data” part.

- If so, what is the best practice for passing this data-dependent information into the prior during the inference process?

I’m struggling to find documentation on this specific type of “self-referential” prior. Any pointers, code patterns, or high-level advice on how to handle this architecture would be incredibly helpful.

Thanks in advance for your time and insights!

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [July 14, 2026, 12:02pm UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/2 "2026-07-14T12:02:58Z")

</div>

Hi Oscar, if by “observed data” you mean the data you will later do inference on (post-training), why can’t you simply define your prior to use the data loaded in memory like so:

```auto
my_data = ...

def my_prior():
    # do stuff with my_data and RNG
    ...

```

The prior is NOT used during the inference process. Why would you want to pass the data to the prior then? Or maybe I am misunderstanding something?

---

<div class="post-metadata">

**Author:** ![MasterODF](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MasterODF](https://discuss.bayesflow.org/u/MasterODF)\
**Post date:** [July 14, 2026, 12:49pm UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/3 "2026-07-14T12:49:34Z")

</div>

Hi Stefan,

Thank you for the quick response! Let me clarify the setup.

If I hardcode the observed data x\_{t\_1} globally during training, the neural network will only learn to infer \\theta for that _one specific_ starting value. I want the neural network to generalize. It should be able to estimate \\theta for any observed starting value at t\_1.

Some more context on the experiment:

I have an observational gap. My data consists of:

- A single early observation at t\_1 (let’s call this value B(t\_1)).

- A gap with no data between t\_1 and t\_3.

- Continuous observations from t\_3 onwards B(t\>t\_3).

I want to infer a parameter \\theta (which represents the state of the system at t\_2, where t\_1 \< t\_2 \< t\_3, and which I could aswell name B(t\_2)). Because t\_2 is close to t\_1, my prior for \\theta is physically constrained by the value at t\_1.

Here’s my “theoretical setup”, so to speak:

- Prior: Gaussian centered at B(t\_1).
- Simulator: Gillespie algorithm which simulates from t\_1 onwards.

The workflow would be something like:

1. Load dataset B\_i(t).
2. Sample from the prior with a gaussian centered at B\_i(t\_1)
3. Simulate training data starting from sampled B\_i(t\_1).

To train this amortized network, the generative model needs to sample different values of the context B(t\_1) during training so the network learns the relationship across a wide range of starting conditions.

I am trying to figure out the best way to structure this within BayesFlow, Like, how do I cleanly wrap this in BayesFlow’s `GenerativeModel` so that the context generated in the prior is correctly passed as an argument to the simulator?

Hope this makes it clearer. Thanks again!

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [July 14, 2026, 12:57pm UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/4 "2026-07-14T12:57:54Z")

</div>

Ok, thanks for the clarification!

`GenerativeModel` gives me a hint: it is no longer a supported module (seems that you are using legacy bayesflow). I highly recommend switching to BayesFlow 2:

- [[2602.07098] BayesFlow 2: Multi-Backend Amortized Bayesian Inference in Python](https://arxiv.org/abs/2602.07098)
- [GitHub - bayesflow-org/bayesflow: A Python library for efficient Bayesian modeling with deep learning · GitHub](https://github.com/bayesflow-org/bayesflow)

In the new lib, `bf.make_simulator` can chain arbitrary functions that will match input-output arguments automatically by names. You can bypass the simulator altogether by passing your own class that exposes a `.sample(batch_size)` method.

---

<div class="post-metadata">

**Author:** ![MasterODF](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MasterODF](https://discuss.bayesflow.org/u/MasterODF)\
**Post date:** [July 15, 2026, 10:49am UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/5 "2026-07-15T10:49:52Z")

</div>

Hi Stefan,

Thanks again! Yeah, I’ve started using BayesFlow2 and rewritten my previous code to make sure I get the gist of it.

However, I’m still unsure on how to implement a single data-point dependent prior distribution. If you could give some pointers in the right direction I’d highly appreciate it.

Thanks again!

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [July 15, 2026, 12:45pm UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/6 "2026-07-15T12:45:38Z")

</div>

Not sure I understand completely still, but I can imagine something along the lines of:

```auto

import bayesflow as bf

rng = np.random.default_rng(42)

# Plausible / empirically observed values of B(t1)
# Could also be replaced by a parametric distro
B_t1 = np.array([8.0, 10.0, 12.0, 15.0, 18.0, 20.0])
OBSERVATION_TIMES = np.linspace(3.0, 10.0, 50) # or whatever

def sample_context():
    b_t1 = rng.choice(B_t1)
    return {"b_t1": b_t1}

def conditional_prior(b_t1):
    theta = rng.normal(loc=b_t1, scale=1.0)
    return {"theta": theta}

def observation_model(theta, b_t1):
    # Your Gillespie implementation
    x_post_gap = f(theta, OBSERVATION_TIMES)
    return {"x_post_gap": x_post_gap}

simulator = bf.make_simulator([
    sample_context,
    conditional_prior,
    observation_model,
])

adapter = (
    bf.adapters.Adapter()
    .to_array()
    .convert_dtype("float64", "float32")
    .rename("theta", "inference_variables")
    .rename("b_t1", "inference_conditions")
    .rename("x_post_gap", "summary_variables")
)

# Workflow as usual...
```

---

<div class="post-metadata">

**Author:** ![MasterODF](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MasterODF](https://discuss.bayesflow.org/u/MasterODF)\
**Post date:** [July 16, 2026, 7:30am UTC](https://discuss.bayesflow.org/t/parameter-dependent-prior/275/7 "2026-07-16T07:30:05Z")

</div>

Hi Stefan,

I think that could work, yeah!

Thanks lots!
