I am implementing Mixed membsership stochastic block model with pymc3. I have managed to define the model. There is no compilation error. But after sampling when I plot it it gives blank and weird plots.
Can someone please help .
import numpy as np
import pymc3 as pm
import theano.tensor as tt
user_data = np.array([[1,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0],
[1,0,1,0,0,1,0,0,1,1,1,0,0,0,0,0,1,0,1,0],
[0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0],
[0,1,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,1,0],
[1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1],
[0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0],
[1,1,0,0,0,1,0,1,1,1,0,1,1,1,0,0,1,1,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0],
[0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0],
[1,0,1,0,0,0,1,1,0,0,0,1,0,0,1,0,0,0,0,0],
[0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0],
[1,0,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0],
[0,1,1,0,0,1,0,0,0,1,0,0,1,0,0,1,1,0,0,0],
[0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,1,0,1,1],
[1,1,0,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,1,0],
[1,0,0,1,1,1,0,0,0,0,0,0,1,1,0,1,0,0,0,1]])
(people,val) = user_data.shape
user_data_vector = user_data.reshape(people*people,1).T
K = 3 #Number of communities
alpha = np.ones((K))
model = pm.Model()
B = tt.ones((K,K))*0.8 #np.eye(K)*0.8 #interaction between different communities
with model:
pi_list = pm.Dirichlet('userx_pi', a=alpha, shape = (people, K))
z_aTb = pm.Categorical('a_' ,p = pi_list, shape =(people*K,people))
z_aTb_re = tt.reshape(z_aTb,(people,people,K))
bernoulli_params = tt.tensordot(tt.tensordot(z_aTb_re,B,axes = 1),z_aTb_re.T, axes = 2)
bernoulli_params = tt.reshape(bernoulli_params,(1,people*people))
with model:
y = pm.Bernoulli('y', p=bernoulli_params , observed = user_data_vector)
with model:
step1 = pm.Metropolis()
tr = pm.sample(1000, step =step1,chains =1)
with model:
pm.plots.traceplot(tr,['userx_pi']);