I’m have multiple time series of the same length with the same AR parameters. I’m struggling to figure out the shapes/dims situation in v4.
Here is a toy example:
import pandas as pd
import pymc as pm
import numpy as np
import arviz as az
def create_ar_series(length, rho, sigma):
res = []
lastval = 0
for i in np.arange(length):
nextval = lastval * rho + np.random.normal(loc=0, scale=sigma)
lastval = nextval
res.append(lastval)
return res
# multiple series, same AR params
df = pd.DataFrame({'res1': create_ar_series(10000, .3, .1),
'res2': create_ar_series(10000, .3, .1), })
with pm.Model(coords={"time": df.index.values, "series": [0, 1]}) as m:
rho = pm.Normal("rho", shape=1)
init = pm.Normal.dist(0, shape=1)
sigma = pm.HalfNormal('sigma', size=1)
ar1 = pm.AR("ar1", rho=rho, sigma=sigma, init_dist=init,
constant=False, observed=df[['res1', 'res2']].values, dims=("time", "series",))
with m:
trace = pm.sample()
… results in this error:
~/.virtualenvs/m6_v3/lib/python3.9/site-packages/aesara/tensor/type.py in filter_variable(self, other, allow_convert)
261 return other2
262
--> 263 raise TypeError(
264 f"Cannot convert Type {other.type} "
265 f"(of Variable {other}) into Type {self}. "
TypeError: Cannot convert Type TensorType(float64, (10000, 2)) (of Variable ar1{[[-0.08402..06180672]]}) into Type TensorType(float64, (1, None)). You can try to manually convert ar1{[[-0.08402..06180672]]} into a TensorType(float64, (1, None)).
I’ve read the dimensionality docs but still couldn’t solve this.