While running the example code for pm.MatrixNormal
from the PyMC documentation. link
Pymc version : 5.18.2
Here is the example code:
# Setup data
true_colcov = np.array([[1.0, 0.5, 0.1],
[0.5, 1.0, 0.2],
[0.1, 0.2, 1.0]])
m = 3
n = true_colcov.shape[0]
true_scale = 3
true_rowcov = np.diag([true_scale**(2*i) for i in range(m)])
mu = np.zeros((m, n))
true_kron = np.kron(true_rowcov, true_colcov)
data = np.random.multivariate_normal(mu.flatten(), true_kron)
data = data.reshape(m, n)
with pm.Model() as model:
# Setup right cholesky matrix
sd_dist = pm.HalfCauchy.dist(beta=2.5, shape=3)
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,
sd_dist=sd_dist)
colchol = pm.expand_packed_triangular(3, colchol_packed)
# Setup left covariance matrix
scale = pm.LogNormal('scale', mu=np.log(true_scale), sigma=0.5)
rowcov = pt.diag([scale**(2*i) for i in range(m)])
vals = pm.MatrixNormal('vals', mu=mu, colchol=colchol, rowcov=rowcov,
observed=data)
I have encountered the following error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-6754c6fb0466> in <cell line: 14>()
17 colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,
18 sd_dist=sd_dist)
---> 19 colchol = pm.expand_packed_triangular(3, colchol_packed)
20
21 # Setup left covariance matrix
/usr/local/lib/python3.10/dist-packages/pymc/math.py in expand_packed_triangular(n, packed, lower, diagonal_only)
434 If true, return only the diagonal of the matrix.
435 """
--> 436 if packed.ndim != 1:
437 raise ValueError("Packed triangular is not one dimensional.")
438 if not isinstance(n, int):
AttributeError: 'tuple' object has no attribute 'ndim'