# Setting boundaries for prior distributions

**URL:** <https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823>\
**Category:** Questions\
**Created:** [February 18, 2022, 1:50pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823 "2022-02-18T13:50:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [February 18, 2022, 1:50pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/1 "2022-02-18T13:50:53Z")

</div>

I was working around with creating custom distributions and went through problem with error:  
` "Initial evaluation of model at starting point failed!"` where I got the following values in parameters:

- mu\_p = 6.57
- sigma\_p = -0.77
- observed\_data = -inf

and I looked at the following link:“[Hyperbolic Secant Distribution with equations](https://www.vosesoftware.com/riskwiki/Hyperbolic-Secantequations.php)” I found out that sigma value should be above 0. I designed custom distribution using the code from this question link:“[My Hyperbolic Secant Distribution custom code](https://discourse.pymc.io/t/how-to-implement-the-bayesian-inference-correctly/8477/2)”.

So, I would like to know how to constrain the sigma parameter?

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [February 18, 2022, 2:59pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/2 "2022-02-18T14:59:17Z")

</div>

You can use one of the bounded distributions (half normal, half cauchy, half student) as a prior (or something like an exponential or gamma). That will prevent negative values from being sampled. But it looks like you may already being doing that? Can you include the full error message you are getting?

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [February 18, 2022, 3:46pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/3 "2022-02-18T15:46:49Z")

</div>

Thank you for reply, here is the full error message:

```auto
SamplingError: Initial evaluation of model at starting point failed!

Starting values:

{'sigma __log__': array(-7.36189677), 'mu_': array(0.00395141)}

 

Initial evaluation results:

sigma_ _log__ -0.77

mu_ 6.57

observed_data_ -inf

Name: Log-probability of test_point, dtype: float64

```

this error occurs when it enters the trace part (sample) of code

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [February 18, 2022, 4:16pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/4 "2022-02-18T16:16:53Z")

</div>

The problem seems to be in the likelihood (i.e., `observed_data`), not in the `sigma`. The initial value of `sigma` is e^{-7.36189677}=0.00063, which is small but positive and has a prior logp of e^{-.77}=0.46301306831.

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [February 18, 2022, 4:18pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/5 "2022-02-18T16:18:49Z")

</div>

Okay, is there a way to prevent the error from occuring in the likelihood part?

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [February 18, 2022, 4:52pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/6 "2022-02-18T16:52:22Z")

</div>

Something is breaking inside your likelihood which is likely causing the data you have observed to essentially be impossible under your model. So it will take some digging around in `observed_data` to figure out why.

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [February 18, 2022, 5:59pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/7 "2022-02-18T17:59:34Z")

</div>

thank for all the guidance. Just one small question, I passed by this question where one of the comments said the following:

> "Very beginner user here, so consider all I write with rightful suspicion.  
> The `-inf` in the evaluation suggests you have some strange parametrization going on, but I honestly could not find anything wrong with your model – but wait for more expert user to chime in.  
> Something you could try is to get rid of the sigmas parameter completely. Just fix the sigma of `y_obs` to `1` and see if you still have an error – since the `mu` parameter is not constrained it should not be the one causing the error.  
> However, you should be able to tell the sampler where to start. You may rewrite your sampling line as:
> 
> ```auto
> trace = pm.sample(2000, tune=1000, start={'alpha': np.array([0.]), 'tau': np.array([0.]), 'sigma_c': np.array([0.]), 'sigma_t': np.array([0.])})
> 
> ```
> 
> Naturally, you are free to change the starting values as you please – withing the boundaries of acceptability for each parameter.

Could this work for my situation? (Link to question:[Error with model](https://discourse.pymc.io/t/error-with-model-initial-evaluation-of-model-at-starting-point-failed/7160))

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [February 18, 2022, 6:01pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/8 "2022-02-18T18:01:19Z")

</div>

You can certainly try that. Just set the sigma to something reasonable (a scalar, e.g., `1.0` rather than a pymc random variable) and see how it goes.

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [February 18, 2022, 6:02pm UTC](https://discourse.pymc.io/t/setting-boundaries-for-prior-distributions/8823/9 "2022-02-18T18:02:30Z")

</div>

will try. Thank you again
