Hello,
I’m following a time series tutorial from Hierarchical Time Series With Prophet and PyMC3 by Matthijs Brouns - YouTube and keep getting an error with the Laplace distribution.
The error is below:
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
/tmp/ipykernel_2309/1529980733.py in <module>
5 delta = pm.Laplace('delta', 0, 0.01, shape = n_changepoints)
6
----> 7 growth = k + at.dot(A, delta)
8 offset = m + at.dog(A, -s * delta)
9 trend = growth * t + offset
/opt/conda/lib/python3.7/site-packages/aesara/tensor/math.py in dot(l, r)
2024
2025 if not isinstance(r, Variable):
-> 2026 r = as_tensor_variable(r)
2027
2028 try:
/opt/conda/lib/python3.7/site-packages/aesara/tensor/__init__.py in as_tensor_variable(x, name, ndim, **kwargs)
40
41 """
---> 42 return _as_tensor_variable(x, name, ndim, **kwargs)
43
44
/opt/conda/lib/python3.7/functools.py in wrapper(*args, **kw)
838 '1 positional argument')
839
--> 840 return dispatch(args[0].__class__)(*args, **kw)
841
842 funcname = getattr(func, '__name__', 'singledispatch function')
/opt/conda/lib/python3.7/site-packages/aesara/tensor/__init__.py in _as_tensor_variable(x, name, ndim, **kwargs)
47 x, name: Optional[str], ndim: Optional[int], **kwargs
48 ) -> "TensorVariable":
---> 49 raise NotImplementedError(f"Cannot convert {x} to a tensor variable.")
50
51
NotImplementedError: Cannot convert delta ~ Laplace to a tensor variable.
I’m not sure if this is an issue with my code or aesara
.
Here is the model:
import pymc3 as pm
import aesara
from aesara import tensor as at
import arviz
#define hyper-parameters
#potential number of changes in trends over time
n_changepoints = 5
#make the t
t = np.arange(len(experimental))/len(experimental)
#make the changepoints
s = np.linspace(0, max(t), n_changepoints + 2)[1: -1]
#indicator matrix
A = (t[:, None]>s) * 1
with pm.Model() as model:
k = pm.Normal('k', 0, 1)
m = pm.Normal('m', 0, 5)
delta = pm.Laplace('delta', 0, 0.01, shape = n_changepoints)
growth = k + at.dot(A, delta)
offset = m + at.dot(A, -s * delta)
trend = growth * t + offset
error = pm.HalfCauchy('sigma', 0.5)
mu_ = trend + error
pm.Poisson("predicted_sales", mu = mu_, observed = experimental['eaches'])
trace = pm.sampling_jax.sample_numpyro_nuts(tune=1000, cores=4, chains = 4)
Is there anything glaringly wrong with the code?