Vectorization for multi-dimensional hyper-prior

Hello, Have a question when to have a multi-dimensional hyper prior.

Let’s say \mu \in \mathbb{R}^{K \times C}
and \mu_{k,c} \sim N(0,1) for k=1...K and c=1...C.

\beta_{k,c,w}\sim N(\mu_{k,c},1) for w =1,...,W.

In this case, I can do

model2=pm.Model()
with model2:
mu=pm.Normal('mu',mu=0,sigma=1,shape=(n_K,n_C))
beta_probs=[]
for w in range(n_W):
_beta=pm.Normal("beta_%i" %w,mu=mu,sigma=1,shape=(n_K,n_C))
beta_probs.append(_beta)
beta=pm.Deterministic("beta",tt.stack(beta_probs,axis=2))


But, is there any way to vectorize it? such as… (below is not working)

model1=pm.Model()
with model1:
mu=pm.Normal('mu',mu=0,sigma=1,shape=(n_K,n_C))
beta=pm.Normal('beta',mu=mu,sigma=1,shape=(n_K,n_C,n_W))


Thanks a lot for the help…

You can either do:

with model1:
mu=pm.Normal('mu',mu=0,sigma=1,shape=(n_K,n_C))
beta=pm.Normal('beta',mu=mu,sigma=1,shape=(n_W,n_K,n_C))


or

with model1:
mu=pm.Normal('mu',mu=0,sigma=1,shape=(n_K,n_C))
beta=pm.Normal('beta',mu=mu[..., None],sigma=1,shape=(n_K,n_C,n_W))

2 Likes