-
-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Labels
Description
Hello,
Attempting to compute the model evaluation metrics compute_log_likelihood and r2_score for the fish example zero-inflated poisson resulted in the following errors:
TypeError Traceback (most recent call last)
Cell In[12], line 1
----> 1 zip_model.compute_log_likelihood(idata=zip_idata)
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/bambi/models.py:935, in Model.compute_log_likelihood(self, idata, data, inplace)
930 idata = self._compute_likelihood_params(
931 idata, data, include_group_specific, sample_new_groups
932 )
934 required_kwargs = {"model": self, "posterior": idata.posterior, "data": data}
--> 935 log_likelihood = self.family.log_likelihood(**required_kwargs)
936 log_likelihood = log_likelihood.to_dataset(name=response_aliased_name)
938 if "log_likelihood" in idata:
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/bambi/families/family.py:217, in Family.log_likelihood(self, model, posterior, data, **kwargs)
213 output_array = pm.logp(
214 pm.Truncated.dist(response_dist.dist(**kwargs), lower=lower, upper=upper), y_values
215 ).eval()
216 else:
--> 217 output_array = pm.logp(response_dist.dist(**kwargs), y_values).eval()
219 return xr.DataArray(output_array, coords=coords)
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pymc/logprob/basic.py:207, in logp(rv, value, warn_rvs, **kwargs)
205 value = pt.as_tensor_variable(value, dtype=rv.dtype)
206 try:
--> 207 return _logprob_helper(rv, value, **kwargs)
208 except NotImplementedError:
209 fgraph = construct_ir_fgraph({rv: value})
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pymc/logprob/abstract.py:81, in _logprob_helper(rv, *values, **kwargs)
79 def _logprob_helper(rv, *values, **kwargs):
80 """Help call `_logprob` dispatcher."""
---> 81 logprob = _logprob(rv.owner.op, values, *rv.owner.inputs, **kwargs)
83 name = rv.name
84 if (not name) and (len(values) == 1):
File ~/.pyenv/versions/3.10.14/lib/python3.10/functools.py:889, in singledispatch.<locals>.wrapper(*args, **kw)
885 if not args:
886 raise TypeError(f'{funcname} requires at least '
887 '1 positional argument')
--> 889 return dispatch(args[0].__class__)(*args, **kw)
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pymc/distributions/mixture.py:349, in marginal_mixture_logprob(op, values, rng, weights, *components, **kwargs)
347 components_logp = logp(components[0], pt.expand_dims(value, mix_axis))
348 else:
--> 349 components_logp = pt.stack(
350 [logp(component, value) for component in components],
351 axis=-1,
352 )
354 mix_logp = pt.logsumexp(pt.log(weights) + components_logp, axis=-1)
356 mix_logp = check_parameters(
357 mix_logp,
358 0 <= weights,
(...)
361 msg="0 <= weights <= 1, sum(weights) == 1",
362 )
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pytensor/tensor/basic.py:2955, in stack(tensors, axis)
2953 dtype = ps.upcast(*[i.dtype for i in tensors])
2954 return MakeVector(dtype)(*tensors)
-> 2955 return join(axis, *[shape_padaxis(t, axis) for t in tensors])
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pytensor/tensor/basic.py:2795, in join(axis, *tensors_list)
2793 return tensors_list[0]
2794 else:
-> 2795 return _join(axis, *tensors_list)
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pytensor/graph/op.py:293, in Op.__call__(self, name, return_list, *inputs, **kwargs)
249 def __call__(
250 self, *inputs: Any, name=None, return_list=False, **kwargs
251 ) -> Variable | list[Variable]:
252 r"""Construct an `Apply` node using :meth:`Op.make_node` and return its outputs.
253
254 This method is just a wrapper around :meth:`Op.make_node`.
(...)
291
292 """
--> 293 node = self.make_node(*inputs, **kwargs)
294 if name is not None:
295 if len(node.outputs) == 1:
File ~/.pyenv/versions/3.10.14/envs/baseline_3.10.14/lib/python3.10/site-packages/pytensor/tensor/basic.py:2488, in Join.make_node(self, axis, *tensors)
2485 ndim = tensors[0].type.ndim
2487 if not builtins.all(x.ndim == ndim for x in tensors):
-> 2488 raise TypeError(
2489 "Only tensors with the same number of dimensions can be joined. "
2490 f"Input ndims were: {[x.ndim for x in tensors]}"
2491 )
2493 try:
2494 static_axis = int(get_scalar_constant_value(axis))
TypeError: Only tensors with the same number of dimensions can be joined. Input ndims were: [2, 4]
AttributeError Traceback (most recent call last)
Cell In[26], line 1
----> 1 zip_model.r2_score(idata=zip_idata)
AttributeError: 'Model' object has no attribute 'r2_score'
Would it be possible to have these functionalities implemented?
Thank you!
Best regards,
Æ