Hi,
I’m having a AssertionError issue when using the logcdf method for a Beta, but strangely not for a Normal or a Uniform. From what I understand from other posts on AssertionErrors, this error appears when the incoming object in my deterministic distribution is of the wrong format. But I’m surprised it happens only for Betas. Here is my Code:
# Initialize random number generator
np.random.seed(123)
# True parameter values
alpha, sigma = 1, 1
beta = [1, 2.5]
# Size of dataset
size = 100
# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2
# Simulate outcome variable
data = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma
>
basic_model = pm.Model()
with basic_model:
a = pm.Normal('a', mu=2, sd=2)
b = pm.Normal('b', mu=2, sd=2)
s = pm.HalfNormal('sigma', sd=0.01)
m1 = np.exp(pm.Beta.dist(alpha=a, beta=b).logcdf(0.1))
Y_obs = pm.Normal('Y_obs1', mu=m1, sd=s, observed=data)
map_estimate = pm.find_MAP(model=basic_model)
print map_estimate
with basic_model:
# Sample from the posterior
trace = pm.sample(draws=1000, chains=2, tune=500, discard_tuned_samples=True)
pm.plot_posterior(trace)
and here is my error log :
Traceback (most recent call last):
File “/Users/Colo/Google Drive/Projects/greghec/learning pymc2.py”, line 47, in
trace = pm.sample(tune=500)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 395, in sample
progressbar=progressbar, **args)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 1515, in init_nuts
step = pm.NUTS(potential=potential, model=model, **kwargs)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step_methods/hmc/nuts.py”, line 154, in init
super(NUTS, self).init(vars, **kwargs)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step_methods/hmc/base_hmc.py”, line 75, in init
vars, blocked=blocked, model=model, dtype=dtype, **theano_kwargs
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step_methods/arraystep.py”, line 228, in init
vars, dtype=dtype, **theano_kwargs)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 710, in logp_dlogp_function
return ValueGradFunction(self.logpt, grad_vars, extra_vars, **kwargs)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 443, in init
grad = tt.grad(self._cost_joined, self._vars_joined)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 605, in grad
grad_dict, wrt, cost_name)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1371, in _populate_grad_dict
rval = [access_grad_cache(elem) for elem in wrt]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access_grad_cache
term = access_term_cache(node)[idx]
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1162, in access_term_cache
new_output_grads)
File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/scan_module/scan_op.py”, line 2222, in L_op
assert (x[::-1][:-1].tag.test_value.shape[0] == n)
AssertionError
Any ideas why this happens ? Thanks !