Closed
Description
When I use custom coords for a model, resetting data in a shared variable fails.
Please provide a minimal, self-contained, and reproducible example.
import pymc as pm
import numpy as np
coords = {"category":["A","B","C"],"data_point":list(range(1,101))}
x = np.random.normal([13,14,12],[2,1,3],size=(100,3))
x_new = x = np.random.normal([14,15,11],[2,1,3],size=(100,3))
with pm.Model(coords=coords) as model:
x = pm.MutableData("x",x,dims=["data_point","country"])
mu = pm.Normal("mu",mu=[12,12,12],sigma=2)
sigma = pm.Exponential("sigma",lam=[1,1,1])
obs = pm.Normal("obs",mu=mu,sigma=sigma,observed=x)
with model:
pm.set_data({"x":x_new},coords=coords)
Please provide the full traceback.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/tim/Master/prototyping/TutorialsAndArchive/test_stuff.ipynb Cell 1' in <cell line: 13>()
[12](vscode-notebook-cell:/home/tim/Master/prototyping/TutorialsAndArchive/test_stuff.ipynb#ch0000000?line=11) obs = pm.Normal("obs",mu=mu,sigma=sigma,observed=x)
[13](vscode-notebook-cell:/home/tim/Master/prototyping/TutorialsAndArchive/test_stuff.ipynb#ch0000000?line=12) with model:
---> [14](vscode-notebook-cell:/home/tim/Master/prototyping/TutorialsAndArchive/test_stuff.ipynb#ch0000000?line=13) pm.set_data({"x":x_new},coords=coords)
File ~/Master/prototyping/repos/pymc/pymc/model.py:1770, in set_data(new_data, model, coords)
[1767](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1766) model = modelcontext(model)
[1769](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1768) for variable_name, new_value in new_data.items():
-> [1770](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1769) model.set_data(variable_name, new_value, coords=coords)
File ~/Master/prototyping/repos/pymc/pymc/model.py:1182, in Model.set_data(self, name, values, coords)
[1177](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1176) length_changed = new_length != old_length
[1179](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1178) # Reject resizing if we already know that it would create shape problems.
[1180](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1179) # NOTE: If there are multiple pm.MutableData containers sharing this dim, but the user only
[1181](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1180) # changes the values for one of them, they will run into shape problems nonetheless.
-> [1182](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1181) length_belongs_to = length_tensor.owner.inputs[0].owner.inputs[0]
[1183](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1182) if not isinstance(length_belongs_to, SharedVariable) and length_changed:
[1184](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1183) raise ShapeError(
[1185](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1184) f"Resizing dimension '{dname}' with values of length {new_length} would lead to incompatibilities, "
[1186](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1185) f"because the dimension was initialized from '{length_belongs_to}' which is not a shared variable. "
(...)
[1190](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1189) expected=old_length,
[1191](file:///home/tim/Master/prototyping/repos/pymc/pymc/model.py?line=1190) )
AttributeError: 'NoneType' object has no attribute 'inputs'
Please provide any additional information below.
I made a little fix for me and will publish it in a PR.
Versions and main components
- PyMC/PyMC3 Version: 4.0.0b6 (ab593b)
- Aesara/Theano Version: 2.6.6
- Python Version: 3.10
- Operating system: Ubuntu 20.04
- How did you install PyMC/PyMC3: (conda/pip) pip -e
Metadata
Metadata
Assignees
Labels
No labels