pymc-devs / pymc-devs/pymc-examples
nb: case studies, spline (error)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 398
- Forks
- 325
- Avg merge
- 9d 15m
- Merged PRs (30d)
- 1
Description
Notebook title: Splines
Notebook url: https://www.pymc.io/projects/examples/en/latest/case_studies/spline.html
Issue description
Code:
COORDS = {"splines": np.arange(B.shape[1])}
with pm.Model(coords=COORDS) as spline_model:
a = pm.Normal("a", 100, 5)
w = pm.Normal("w", mu=0, sigma=3, size=B.shape[1], dims="splines")
mu = pm.Deterministic("mu", a + pm.math.dot(np.asarray(B, order="F"), w.T))
sigma = pm.Exponential("sigma", 1)
D = pm.Normal("D", mu=mu, sigma=sigma, observed=blossom_data.doy, dims="obs")
Error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[13], line 7
5 mu = pm.Deterministic("mu", a + pm.math.dot(np.asarray(B, order="F"), w.T))
6 sigma = pm.Exponential("sigma", 1)
----> 7 D = pm.Normal("D", mu=mu, sigma=sigma, observed=blossom_data.doy, dims="obs")
File ~/miniforge3/envs/pymc-dev/lib/python3.11/site-packages/pymc/distributions/distribution.py:304, in Distribution.__new__(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
302 if kwargs.get("size") is None and kwargs.get("shape") is None:
303 if dims is not None:
--> 304 kwargs["shape"] = shape_from_dims(dims, model)
305 elif observed is not None:
306 kwargs["shape"] = tuple(observed.shape)
File ~/miniforge3/envs/pymc-dev/lib/python3.11/site-packages/pymc/distributions/shape_utils.py:507, in shape_from_dims(dims, model)
505 unknowndim_dims = set(dims) - set(model.dim_lengths)
506 if unknowndim_dims:
--> 507 raise KeyError(
508 f"Dimensions {unknowndim_dims} are unknown to the model and cannot be used to specify a `shape`."
509 )
511 return tuple(model.dim_lengths[dname] for dname in dims)
KeyError: "Dimensions {'obs'} are unknown to the model and cannot be used to specify a `shape`."
Note that this issue tracker is about the contents in the notebooks, if
the notebook is instead triggering a bug or error in pymc, please
report to https://github.com/pymc-devs/pymc/issues instead
Expected output
If applicable, describe what should happen instead.
Proposed solution
If applicable, explain possible solutions and workarounds.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the Splines notebook from the linked case-study URL and inspect the model cell defining COORDS and the observed D variable. Run the notebook to reproduce the unknown obs dimension error, then verify the notebook executes that cell successfully without the KeyError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, numpy, python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100