Setting boundaries for prior distributions

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” 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”.

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

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?

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

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

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.

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

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.

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:

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)

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.

will try. Thank you again