Vector hyperparameter for multivariate normal

Hi, how can i make an multidimensional deterministic parameter. I want to have my mu end up being a 2d parameter for a bivariate gaussian likelihood. I still learning PYMC and have been searching through docs for answer. Any guidance or help is much appreciated

import arviz as az
import numpy as np
import pymc as pm

def q_mu(P,vi,n=1,m=1):
    q = np.dot(P,vi)
    return q

N = 100
# True parameter values
p_actual = np.array([[1,.25],[.255,1]])
v = np.array([1.4,1.4])
qmu_actual=q_mu(p_actual,v_actual)
sigma=np.array([[1.1,.4],[.4,1.2]])

# Size of dataset
size = 5

# Predictor variable
V1 = np.random.normal(1.4, .01, size)
V2 = np.random.normal(1.4, .01, size)

# Simulate outcome variable
x = rng.multivariate_normal(q_mu(p_actual,v),sigma, size=N)

coords = {"axis": ["x1", "x2"], "obs_id": np.arange(N)}
with pm.Model(coords=coords) as model:
    c11 = pm.Normal("c11", mu=1, sigma=10)
    c12 = pm.Normal("c12", mu=1*.255, sigma=10)
    c21 = pm.Normal("c21", mu=1*.255, sigma=10)
    c22 = pm.Normal("c22", mu=1, sigma=10)

with model:
    p = np.array([[c11, c12], [c21, c22]])
    v=np.array([1.4,1.4])
    mu=pm.math.dot(p,v)
    # mu=q_mu(p,v)
    # mu = pm.math.dot(p,v_actual)
    # mu = pm.Deterministic(name="mu",var=pm.math.dot(p,v),dims="axis")
    # mu = pm.Deterministic(name="mu",var=q_mu(p,v),dims="axis")
    obs = pm.MvNormal("obs", mu=mu, cov=sigma, observed=x, dims=("obs_id", "axis"))

I either get

TypeError: Unsupported dtype for TensorType

or

ValueError: order must be one of 'C', 'F', 'A', or 'K' (got 'mu')

Im sure its something dumb im doing, but I cant figure it out

Hi,

You should use operations defined in pytensor.tensor to construct matrices of tensors. So the incorrect line is

p = np.array([[c11, c12], [c21, c22]])

Instead you can do

import pytensor.tensor as pt

p = pt.reshape(pt.stack([c11,c12,c21,c22]),(2,2))