SamplingError: Initial evaluation failed at starting point

Hey guys, I’m stuck at a problem where the error is

pymc3.exceptions.SamplingError: Initial evaluation of model at starting point failed!`
Initial evaluation results:
a_              -19.33
b__log__          1.02
mu_c_            -1.35
c_               -1.35
A               -23.89
sigma_y_log__   -33.98`
Y_obs             -inf`
Name: Log-probability of test_point, dtype: float64

I have already tried several combinations of hyper-parameters for the prior (or hyper-prior) distributions, but all in vain. I did not face such errors when I used numpy arrays for the same problem.

Could you please have a look at the code below and, may be, suggest what could have gone wrong with this model?

    with pm.Model() as model:

        X1 = theano.shared(x1, broadcastable=(True,False))
        X2= theano.shared(x2, broadcastable=(True,False))
        
        # Observed data shape = (26,26)
        training_data = theano.shared(y_train_)

        numG = 6

        def sumGaussians(a,b,c,f):
            sum = tt.zeros (shape=(1,26))
            for g in range(numG):
                sum = sum + a[g] * pm.math.exp(-1.0 * pm.math.sqr((f - b[g])/c[g]))
            return sum

        # Height of the Gaussians
        a_ = pm.Normal("a_", mu=50, sigma=10, shape=(numG, 1))

        # Centres of the Gaussians
        mu_b_ = 3.0
        sigma_b_ = 1.0
        alpha_b_ = mu_b_ ** 2.0 / sigma_b_
        beta_b_ = mu_b_ / sigma_b_
        b_ = pm.Gamma("b_", alpha=alpha_b_, beta=beta_b_, shape=(numG, 1))

        # Width of the Gaussians
        mu_c_ = pm.Normal("mu_c_", mu=3, sigma=0.5, shape=(numG, 1))
        c_ = pm.Normal("c_", mu=mu_c_, sigma=0.5, shape=(numG, 1))

        A = pm.Normal("A", mu=10, sigma=1, shape=(1,26))

        # The mean of the likelihood is assumed to be a combination of `X1` and `X2`
        temp1 = tt.mul(A ,tt.log(tt.power(X1, 6.0) / 0.001)) # shape = (1,26)
        temp2 = sumGaussians(a_,b_,c_,X2) # shape = (1,26)
        temp3 = tt.stack([temp1, temp2], axis=0) # shape = (2,1,26)
        
        # shape = (1,26)
        mu_y = pm.Deterministic("mu_y", tt.mean(temp3, axis=0))

        # Noise in the data
        sigma_y = pm.InverseGamma("sigma_y",1,1, shape=(1,26))

        # Likelihood
        Y_obs = pm.Normal('Y_obs', mu_y, sigma_y, observed=training_data)

        trace = pm.sample(
            draws=1000,
            tune=1000,
            init="adapt_diag",
            chains=2,
            cores=2,
            target_accept=0.95
        )

Thanks a lot! :slight_smile:

Can you print the test point?

with pm.Model() as model:
    # model code here
    # ...
    print(model.test_point)

Hey @cluhmann, here it is

{‘a_’: array([[50.],
[50.],
[50.],
[50.],
[50.],
[50.]]), ‘b__log__’: array([[1.09861229],
[1.09861229],
[1.09861229],
[1.09861229],
[1.09861229],
[1.09861229]]), ‘mu_c_’: array([[3.],
[3.],
[3.],
[3.],
[3.],
[3.]]), ‘c_’: array([[3.],
[3.],
[3.],
[3.],
[3.],
[3.]]), ‘A’: array([[10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.,
10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.]]), ‘sigma_y_log__’: array([[-0.69314718, -0.69314718, -0.69314718, -0.69314718, -0.69314718,
-0.69314718, -0.69314718, -0.69314718, -0.69314718, -0.69314718,
-0.69314718, -0.69314718, -0.69314718, -0.69314718, -0.69314718,
-0.69314718, -0.69314718, -0.69314718, -0.69314718, -0.69314718,
-0.69314718, -0.69314718, -0.69314718, -0.69314718, -0.69314718,
-0.69314718]])}