Rotation matrix with the angle as a random variable in Theano

theano

#1

I wish to declare a rotation matrix -

cos(w) -sin(w ) 0 0
sin(w) cos(w ) 0 0
0 0 1 0
0 0 0 1

It’s a rotation matrix where the angle is a random variable. Something like -

with pm.Model() as model:
w = pm.Normal(‘w’, mu = 0 , tau = 1)
A = pm.Deterministic(‘A’ , ([[np.cos(w), -np.sin(w), 0, 0],[np.sin(w), -np.cos(w), 0, 0],[0, 0, 1, 0],[0, 0, 0, 0]]) )
Y = pm.Normal(‘y’, mu = T.dot(A , X), tau = 1 , observed = X)

Can anyone suggest how to do this?


#2

Something like this should work:

idx = ([0, 0, 1, 1], [0, 1, 0, 1])
with pm.Model() as model:
    w = pm.Normal('w', mu=0, sd=1.)
    A = tt.eye(4)
    A = tt.set_subtensor(A[idx], [tt.cos(w), -tt.sin(w), tt.sin(w), tt.cos(w)])

#3

Thanks…