How to access i-th RV of a multivariate Normal with shape >1


#1

Hello,
I have defined N random variables that are multivariate Gaussian of dimension 3.

import pymc3 as pm
N=10
with pm.Model() as model:
    cov = np.array([[1., 0.5,0.5], [0.5, 2,0.5], [0.5,0.5,3]])
    mu = np.zeros(3)
    theta=pm.MvNormal('Theta', mu=mu,cov=cov, shape=N)

What is the correct way to access the i-th RV?
Either:
theta[i,:]

Or:
theta[:,i]

I am not very good in debugging with PyMC3 so I do not know how to check this.

Thanks for your help and best regards!


#2

What i usually do is to check theta.tag.test_value.shape.


#3

Ok thanks!
In fact, I did not run my example code, and I found that the way I used the shape argument in the Mv gaussian was not correct.
It seems that in order that it works, shape must take into account the size of a single RV (here 3) and the number of RV.
Hence, the correct code is:

N=10
with pm.Model() as model:
    cov = np.array([[1., 0.5,0.5], [0.5, 2,0.5], [0.5,0.5,3]])
    mu = np.zeros(3)
    theta=pm.MvNormal('Theta', mu=mu,cov=cov, shape=(N,3))

which answers also my question: the correct way to access the i-th RV is to call theta[i,:] or theta[i].
Thanks also for the command that you gave me that will be usefull to debug my code!