Bivariate model with Cov matrix

I have 3 variables: S, T and P. My model is (S, P) ~ ((T, P), (T, 0)) + Sigma, where Sigma is the cov matrix.

The length of the data is n=100.

Y = (S, P) of shape (100, 2)

I am not quite sure how to create the square B matrix that has one zero element. mu also needs to be shape (100, 2).

I guess there must be a clever way to do mu = X.dot(B)

with pm.Model() as model:
  a = pm.Normal('a', 0, 2, shape=2)
  b = pm.Normal('b', 0, 2, shape=3)
  sd = pm.Exponential.dist(1.0, shape=2)
  chol, corr, stds = pm.LKJCholeskyCov('chol', n=2, eta=2, sd_dist=sd, compute_corr=True)
  # B = [[b0, b1], [b2, 0]]
  mu = np.zeros((n, 2))
  mu[:, 0] = a[0] + b[0] * t + b[1] * p
  mu[:, 1] = a[1] + b[2] * t
  pred = pm.MvNormal('pred', mu, chol, observed=Y)

One way you can try is to construct a 2x2 tensor B, and update the value with b using Basic Tensor Functionality — Aesara 2.3.1+29.g5a2fb70b4.dirty documentation

1 Like