MCMC SamplingError: Initial evaluation of model at starting point failed!

I receive an error when i apply mcmc by pymc.
Code:

with pm.Model(coords={“test_event_dim”: range(len(used_data)), “test_support_dim”: range(2)}) as model:
w = pm.Dirichlet(‘w’, a=np.ones(n_components))
p1 = pm.HalfNormal(“p1”,sigma=3, dims=(“test_support_dim”,)).exp()
p2 = pm.HalfNormal(“p2”,sigma=3, dims=(“test_support_dim”,)).exp()
p3 = pm.HalfNormal(“p3”,sigma=3, dims=(“test_support_dim”,)).exp()
p4 = pm.HalfNormal(“p4”,sigma=3, dims=(“test_support_dim”,)).exp()
y = DirichletMixture(‘y’, w=w, p=[p1, p2, p3, p4], observed=np.array(used_data), comp_shape=(n_components, 2))
# model.debug(verbose=True)
# if method == ‘mcmc’:
step = pm.Metropolis()
trace = pm.sample(10000, cores=2, step=step)
dataframe = az.summary(trace)

Then, the error message is:
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{‘w_simplex__’: array([0., 0., 0.]), ‘p1_log__’: array([1.09861229, 1.09861229]), ‘p2_log__’: array([1.09861229, 1.09861229]), ‘p3_log__’: array([1.09861229, 1.09861229]), ‘p4_log__’: array([1.09861229, 1.09861229])}

Logp initial evaluation results:
{‘w’: -2.37, ‘p1’: -1.45, ‘p2’: -1.45, ‘p3’: -1.45, ‘p4’: -1.45, ‘y’: -inf}
You can call model.debug() for more details.

class DirichletMixture:

def __new__(cls, name, w, p=None, comp_shape=(), **kwargs):
    
    return pm.Mixture(name, w, pm.Dirichlet.dist(a=p, shape=comp_shape), **kwargs)

@classmethod
def dist(cls, w, p=None, comp_shape=(), **kwargs):

    return pm.Mixture.dist(w, pm.Dirichlet.dist(a=p, shape=comp_shape), **kwargs)

Did you try calling model.debug()?

As I mentioned in the other thread, you might want to give a sample of what is in used_data because that is where the likelihood is currently blowing up.

I have tried it, but it seem no problem.

@cluhmann Hi, my data is:

used_data = np.array([[0.12434521704531136, 0.8409478514060823,  0.03470693154860615],
                      [0.14087321851772333, 0.8099331304465183,  0.04919365103575825],
                      [0.33276683720824074, 0.46031957218021335, 0.2069135906115458],
                      [0.19049621493873276, 0.7783005248224008,  0.031203260238866506],
                      [0.34756555221998486, 0.4233214371769956,  0.2291130106030196],
                      [0.03715272701322371, 0.9628472729867762,  0.0], 
                      [0.4722701223961425,  0.07582290586453501, 0.4519069717393224],
                      [0.2718473867539151,  0.643169721560681,   0.08498289168540392],
                      [0.4670691623341588,  0.09939074852349031, 0.4335400891423509],
                      [0.4231063174687478,  0.2496011286687712,  0.32729255386248096],
                      [0.12421377771025059, 0.8757862222897494,  0.0],
                      [0.09940081994686124, 0.9005991800531387,  0.0],
                      [0.5482803967059677,  0.4517196032940324,  0.0],
                      [0.17420382444522717, 0.8257961755547729,  0.0],
                      [0.3702855749430544,  0.6297144250569455,  0.0],
                      [0.2538912073494831,  0.7153229872752275,  0.030785805375289594],
                      [0.3001927951635424,  0.43629775637214735, 0.2635094484643102],
                      [0.3234181055541806,  0.4254396851275911,  0.25114220931822834],
                      [0.3721739558732628,  0.40090114439795715, 0.22692489972878013],
                      [0.3886990641711753,  0.35533636296854487, 0.25596457286027985], 
                      [0.4421497737161783,  0.369701515725939,   0.18814871055788257],
                      [0.03874460027214254, 0.9612553997278575,  0.0],
                      [0.4719261319907762,  0.07743241326028573, 0.4506414547489381], 
                      [0.2734093223212312,  0.49153172983558485, 0.23505894784318387], 
                      [0.25477468197333153, 0.6126175526935701,  0.13260776533309837], 
                      [0.46718698422714905, 0.1137051164171458,  0.4191078993557051],
                      [0.4022530092258085,  0.2250194063203247,  0.3727275844538668],
                      [0.44765454042943936, 0.17013790639245488, 0.38220755317810573],
                      [0.4282983816609959,  0.24050960006428906, 0.3311920182747151],
                      [0.4212897238444111,  0.2590316066281641,  0.3196786695274248],
                      [0.4608570020860768,  0.2590818660278223,  0.28006113188610104], 
                      [0.11452798406880986, 0.81431747644306,    0.07115453948813016],
                      [0.1437154674954657,  0.8562845325045343,  0.0], 
                      [0.250682955567576,   0.749317044432424,   0.0], 
                      [0.29807125546043667, 0.7019287445395633,  0.0], 
                      [0.272586433644628,   0.7274135663553719,  0.0],
                      [0.3936959659671146,  0.6063040340328855,  0.0], 
                      [0.4444565515057098,  0.55554344849429,    0.0],
                      [0.44680022476411063, 0.5531997752358894,  0.0], 
                      [0.04530000574413036, 0.9546999942558696,  0.0],
                      [0.4685300237768752,  0.08329256943172378, 0.44817740679140106],
                      [0.4751522495300505,  0.09677151935081495, 0.42807623111913456], 
                      [0.4746893344471804,  0.2360290647982002,  0.28928160075461934], 
                      [0.46684721109490723, 0.15323473552392303, 0.3799180533811698], 
                      [0.39143276423808104, 0.32318141560206787, 0.2853858201598511], 
                      [0.42575666208385987, 0.177740425240091,   0.3965029126760491],
                      [0.3665033253587313,  0.4543070103011052,  0.17918966434016356], 
                      [0.1824022741930387,  0.66785800539114,    0.14973972041582123],
                      [0.4717963984052041,  0.1313820867787412,  0.3968215148160547],
                      [0.346640854231222,   0.4015428749777591,  0.251816270791019]])

I can’t even get this to sample. I am getting shape errors. The observed data is shape (50, 3), but the likelihood has shape (n_components, 2)?