Fixing ValueError: Bad initial energy: inf. The model might be misspecified

Need help fixing this problem:

dir_model = pm.Model()
with dir_model:
    
    pi = pm.Dirichlet('pi_', a = np.ones(K), shape = K)

    #dri = pm.Uniform('dri', lower=0, upper=1, shape = (K, B))
    dri = pm.Dirichlet('dri_', a = np.ones((K, encoding_dim)), shape = (K, encoding_dim))
    #pm.Normal('means', mu=np.ones((K, encoding_dim)), sd=15, shape=k)
    
    cov = np.ones((encoding_dim,encoding_dim)) 
    #np.random.uniform(low=0.2, high=1.0, size=(encoding_dim,encoding_dim))
    
    category_U = pm.Categorical('category_u', p = pi, shape = encoded_bts.shape[0])
    vector_U = pm.MvNormal('vec_u_', mu = dri[category_U], cov = cov,  observed = encoded_bts)

vec_u_ -inf is the cause of the problem. How can I change my code to make sure this doesn’t happen?

Any Help much appreciated.

Thanks in advance!

Since you are using a diagonal matrix as cov here, did you try using a pm.Normal with sd=1 instead? Also, did you check that encoded_bts and dri[category_U] contain finite values?

Hi @junpenglao Thanks for the reply.

Yes encoded_bts and dri[category_U] has finite values.
encoded_bts is actually from an autoencoder and it has the reduced dimension for the input.
dri[category_U] as you can see from the model it is just the row indexed from dri. So this is also finite.