1 year ago

#319392

test-img

Divyadeep harbola

pymc.Uniform giving ZeroProbability error: Stochastic alpha's value is outside its support, or it forbids its parents' current values

I am using a example given in web of pymc, when I try to run pymc.Uniform I am getting the following error

---------------------------------------------------------------------------
ZeroProbability                           Traceback (most recent call last)
<ipython-input-18-f29cedab2a0e> in <module>()
      1 import pymc
      2 # define the parameters with their associated priors
----> 3 alpha = pymc.Uniform('alpha', -100,100, value=median(z_obs))
      4 betax = pymc.Uniform('betax', -100,100, value=std(z_obs)/std(x_true))
      5 betay = pymc.Uniform('betay', -100,100, value=std(z_obs)/std(y_true))

/home/divyadeep/miniconda3/envs/detrital/lib/python2.7/site-packages/pymc/distributions.pyc in __init__(self, *args, **kwds)
    312                     logp_partial_gradients=logp_partial_gradients,
    313                     dtype=dtype,
--> 314                     **arg_dict_out)
    315 
    316     new_class.__name__ = name

/home/divyadeep/miniconda3/envs/detrital/lib/python2.7/site-packages/pymc/PyMCObjects.pyc in __init__(self, logp, doc, name, parents, random, trace, value, dtype, rseed, observed, cache_depth, plot, verbose, check_logp, logp_partial_gradients)
    766         if check_logp:
    767             # Check initial value
--> 768             if not isinstance(self.logp, float):
    769                 raise ValueError(
    770                     "Stochastic " +

/home/divyadeep/miniconda3/envs/detrital/lib/python2.7/site-packages/pymc/PyMCObjects.pyc in get_logp(self)
    924                     (self._value, self._parents.value))
    925             else:
--> 926                 raise ZeroProbability(self.errmsg)
    927 
    928         return logp

ZeroProbability: Stochastic alpha's value is outside its support,
 or it forbids its parents' current values.

I have tried the following code but giving the errors:

from numpy import *
Nobs = 20
x_true = random.uniform(0,10, size=Nobs)
y_true = random.uniform(-1,1, size=Nobs)
alpha_true = 0.5
beta_x_true = 1.0
beta_y_true = 10.0
eps_true = 0.5
z_true = alpha_true + beta_x_true*x_true + beta_y_true*y_true
z_obs = z_true + random.normal(0, eps_true, size=Nobs)

import pymc
# define the parameters with their associated priors
alpha = pymc.Uniform('alpha', -100,100, value=median(z_obs))
betax = pymc.Uniform('betax', -100,100, value=std(z_obs)/std(x_true))
betay = pymc.Uniform('betay', -100,100, value=std(z_obs)/std(y_true))
eps = pymc.Uniform('eps', 0, 100, value=0.01)

# Now define the model
@pymc.deterministic
def model(alpha=alpha, betax=betax, betay=betay, x=x_true, y=y_true):
    return alpha + betax*x + betay*y

# pymc parametrizes the width of the normal distribution by tau=1/sigma**2
@pymc.deterministic
def tau(eps=eps):
    return power(eps, -2)

# Lastly relate the model/parameters to the data
data = pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True)

I am expecting result as in the webpage: I am using pymc version 2.3 https://users.obs.carnegiescience.edu/cburns/ipynbs/PyMC.html

python-2.7

probability

scientific-computing

pymc

0 Answers

Your Answer

Accepted video resources