# Observed data with uncertainty described by an irregular distribution

**URL:** <https://discourse.pymc.io/t/observed-data-with-uncertainty-described-by-an-irregular-distribution/13876>\
**Category:** v5\
**Created:** [February 26, 2024, 7:30am UTC](https://discourse.pymc.io/t/observed-data-with-uncertainty-described-by-an-irregular-distribution/13876 "2024-02-26T07:30:08Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![iavicenna](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/iavicenna/32/7923_2.png) [@iavicenna](https://discourse.pymc.io/u/iavicenna)\
**Post date:** [February 26, 2024, 12:45pm UTC](https://discourse.pymc.io/t/observed-data-with-uncertainty-described-by-an-irregular-distribution/13876/2 "2024-02-26T12:45:02Z")

</div>

So if I understand you correctly, you want c and d to be source of random noise and not like priors that update and not use SMC-ABC. In that case, there is only one way (that I am aware of) to achieve this and this is defining your own updating step for c and d so that they are not updated like normal priors. This was discussed recently in

> [@How to add correlated noise to a mathematical model of observed data?](https://discourse.pymc.io/t/how-to-add-correlated-noise-to-a-mathematical-model-of-observed-data/13796/2):
>
> This is something I am a bit curious about too. I initially had asked my self if supplying c = pm.Normal("c",15, 3) would achieve a similar affect. Probably not to full effect and highly dependant on how the model evolves. Differences from a “regular noise” are: this affects your likelihood by multiplying the prior by the probability of sampled c given this distribution. Moreover, given your model, it is possible that the posterior for c could be something quite different which means that eve…

See also the links there. As a starters you can try the following:

```auto
class NormalNoiseStep(BlockedStep):
    def __init__ (self, var, mu, sd, size):
        model = pm.modelcontext(None)
        value_var = model.rvs_to_values[var]
        self.vars = [value_var]
        self.name = value_var.name
        self.mu = mu
        self.size = size
        self.sd = sd

    def step(self, point: dict):

        draw = np.random.normal(self.mu, self.sd, size=self.size)
        point[self.name] = draw
        return point, []

```

In your model then you would use this as

```auto
with pm.Model() as model:
  a = pm.Uniform("a", lower=0.1*16, upper=3*16)
  b = pm.Uniform("b", lower=0.1*14, upper=3*14)
  c = pm.Normal("c", mu ,sd, size=N)
  d = pm.Normal("d", mu ,sd, size=N)
  
  steps = [NormalNoiseStep(c, mu, sd, N), NormalNoiseStep(d, mu, sd, N)]

  #you can now use c and d as any tensor in your operations
  trace = pm.sample(**sample_parameters, step=steps)

```

This is outside the boundaries of regular Bayesian modelling though so stuff like convergence statistics, r\_hat may or may not be meaningful in this context. Perhaps a good thing to do is indeed cross-compare results with SMC-ABC. Never used this method in detail so don’t have intuition about it.

---

_[View the full topic](https://discourse.pymc.io/t/observed-data-with-uncertainty-described-by-an-irregular-distribution/13876)._
