Hello,
I have a model fit, using PyMC and when I tried to sample the ppc, I got the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/aesara/compile/function/types.py in __call__(self, *args, **kwargs)
975 self.vm()
--> 976 if output_subset is None
977 else self.vm(output_subset=output_subset)
/opt/conda/lib/python3.7/site-packages/aesara/graph/op.py in rval(p, i, o, n, params)
523 ):
--> 524 r = p(n, [x[0] for x in i], o)
525 for o in node.outputs:
/opt/conda/lib/python3.7/site-packages/aesara/tensor/random/op.py in perform(self, node, inputs, outputs)
367
--> 368 smpl_val = self.rng_fn(rng, *(args + [size]))
369
/opt/conda/lib/python3.7/site-packages/aesara/tensor/random/op.py in rng_fn(self, rng, *args, **kwargs)
165 """Sample a numeric random variate."""
--> 166 return getattr(rng, self.name)(*args, **kwargs)
167
_generator.pyx in numpy.random._generator.Generator.poisson()
_common.pyx in numpy.random._common.disc()
_common.pyx in numpy.random._common.discrete_broadcast_d()
_common.pyx in numpy.random._common.check_array_constraint()
ValueError: lam < 0 or lam contains NaNs
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/tmp/ipykernel_40221/3499126023.py in <module>
1 with model:
----> 2 ppc = pm.sample_posterior_predictive(trace)
3 trace.extend(ppc)
/opt/conda/lib/python3.7/site-packages/pymc/sampling.py in sample_posterior_predictive(trace, samples, model, var_names, keep_size, random_seed, progressbar, return_inferencedata, extend_inferencedata, predictions, idata_kwargs, compile_kwargs)
1955 param = _trace[idx % len_trace]
1956
-> 1957 values = sampler_fn(**param)
1958
1959 for k, v in zip(vars_, values):
/opt/conda/lib/python3.7/site-packages/pymc/util.py in wrapped(**kwargs)
361 def wrapped(**kwargs):
362 input_point = {k: v for k, v in kwargs.items() if k in ins}
--> 363 return core_function(**input_point)
364
365 return wrapped
/opt/conda/lib/python3.7/site-packages/aesara/compile/function/types.py in __call__(self, *args, **kwargs)
990 node=self.vm.nodes[self.vm.position_of_error],
991 thunk=thunk,
--> 992 storage_map=getattr(self.vm, "storage_map", None),
993 )
994 else:
/opt/conda/lib/python3.7/site-packages/aesara/link/utils.py in raise_with_op(fgraph, node, thunk, exc_info, storage_map)
532 # Some exception need extra parameter in inputs. So forget the
533 # extra long error message in that case.
--> 534 raise exc_value.with_traceback(exc_trace)
535
536
/opt/conda/lib/python3.7/site-packages/aesara/compile/function/types.py in __call__(self, *args, **kwargs)
974 outputs = (
975 self.vm()
--> 976 if output_subset is None
977 else self.vm(output_subset=output_subset)
978 )
/opt/conda/lib/python3.7/site-packages/aesara/graph/op.py in rval(p, i, o, n, params)
522 p=p, i=node_input_storage, o=node_output_storage, n=node, params=None
523 ):
--> 524 r = p(n, [x[0] for x in i], o)
525 for o in node.outputs:
526 compute_map[o][0] = True
/opt/conda/lib/python3.7/site-packages/aesara/tensor/random/op.py in perform(self, node, inputs, outputs)
366 rng_var_out[0] = rng
367
--> 368 smpl_val = self.rng_fn(rng, *(args + [size]))
369
370 if (
/opt/conda/lib/python3.7/site-packages/aesara/tensor/random/op.py in rng_fn(self, rng, *args, **kwargs)
164 def rng_fn(self, rng, *args, **kwargs):
165 """Sample a numeric random variate."""
--> 166 return getattr(rng, self.name)(*args, **kwargs)
167
168 def __str__(self):
_generator.pyx in numpy.random._generator.Generator.poisson()
_common.pyx in numpy.random._common.disc()
_common.pyx in numpy.random._common.discrete_broadcast_d()
_common.pyx in numpy.random._common.check_array_constraint()
ValueError: lam < 0 or lam contains NaNs
Apply node that caused the error: poisson_rv{0, (0,), int64, False}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7F7CBE6E15F0>), TensorConstant{[]}, TensorConstant{4}, Elemwise{Composite{(i0 + (i1 * i2))}}[(0, 0)].0)
Toposort index: 6
Inputs types: [RandomGeneratorType, TensorType(int64, (0,)), TensorType(int64, ()), TensorType(float64, (None,))]
Inputs shapes: ['No shapes', (0,), (), (493628,)]
Inputs strides: ['No strides', (8,), (), (8,)]
Inputs values: [Generator(PCG64) at 0x7F7CBE6E15F0, array([], dtype=int64), array(4), 'not shown']
Outputs clients: [['output'], []]
Backtrace when the node is created (use Aesara flag traceback__limit=N to make it longer):
File "/opt/conda/lib/python3.7/site-packages/IPython/core/async_helpers.py", line 78, in _pseudo_sync_runner
coro.send(None)
File "/opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3257, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "/opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3472, in run_ast_nodes
if (await self.run_code(code, result, async_=asy)):
File "/opt/conda/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3552, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/tmp/ipykernel_40221/2033008534.py", line 21, in <module>
observed = y)
File "/opt/conda/lib/python3.7/site-packages/pymc/distributions/discrete.py", line 1484, in __new__
name=name, nonzero_p=psi, nonzero_dist=Poisson.dist(mu=mu), **kwargs
File "/opt/conda/lib/python3.7/site-packages/pymc/distributions/discrete.py", line 607, in dist
return super().dist([mu], *args, **kwargs)
File "/opt/conda/lib/python3.7/site-packages/pymc/distributions/distribution.py", line 351, in dist
rv_out = cls.rv_op(*dist_params, size=create_size, **kwargs)
HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
I’m not sure what this means and I tried to set aesara’s exception flag inside the sample, but apparently, that’s not where you set that.
Here is the model I fit:
items_idx, items = pd.factorize(df1['ITEM_ROOT'])
coords = {'ITEM_ROOT':items,
'obs_id':np.arange(len(items_idx))}
with pm.Model(coords=coords) as model:
item_idx = pm.Data('item_idx', items_idx, dims = "obs_id")
mu_a = pm.Normal("mu_a", mu=0, sigma = 100)
sigma_a = pm.HalfCauchy("sigma_a", 5)
coef_a = pm.Normal('coef_a', mu=0, sigma = 100)
sigma_coef = pm.HalfCauchy('sigma_coef', 5)
a = pm.Normal('base_sales', mu = mu_a, sigma = sigma_a, dims='ITEM_ROOT')
p = pm.Normal('promo_flag',0,1, dims='ITEM_ROOT')
error = pm.HalfCauchy('error', 1)
trend = a[item_idx] + (p[item_idx]*np.array(df1['promo_flag']))
mu_ = trend
likelihood = pm.ZeroInflatedPoisson('y_hat',
mu = mu_,
psi = .35,
observed = y)
trace = pymc.sampling_jax.sample_numpyro_nuts(tune=2000, draws = 1000)
with model:
ppc = pm.sample_posterior_predictive(trace)
trace.extend(ppc)
This sampled 4 chains in 44 seconds with data the size of (493628, 2)
. Lightening fast. Am I doing something wrong with