This problem has been discussed in the forum. See similar question. But I do not get any solution. I really hope that I can solve it just running an easy API, like pm.sample()
, without knowing too much details. Anyway, I like any suggestion.
Error:
Traceback (most recent call last):
File “/Users/william/BIMSA/statistical-learning/codes/mixed-linear-pymc.py”, line 54, in
trace = pm.sample(cores=1, progressbar=False, start=start)
File “/usr/local/lib/python3.8/site-packages/pymc3/sampling.py”, line 435, in sample
check_start_vals(start, model)
File “/usr/local/lib/python3.8/site-packages/pymc3/util.py”, line 237, in check_start_vals
raise SamplingError(
pymc3.exceptions.SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{‘weights’: array([0., 0., 0.]), ‘random-effect’: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]), ‘sigma2’: 0}Initial evaluation results:
weights 0.00
random-effect -41.88
sigma2 -0.92
y_pred -inf
Name: Log-probability of test_point, dtype: float64
This is the code. The mode here is a mixed linear regression: y = X beta + U xi + epsilon
X = ...
y = ...
U = ...
L = 13
with pm.Model() as model:
# params
weights = pm.Flat('weights', shape=(3,))
random_effect = pm.Normal('random-effect', mu=0, sd=10, shape=(L,))
sigma_square = pm.Normal('sigma2', mu=0, sd=1)
# sigma_square = pm.HalfCauchy('sigma2', mu=0, sigma=1)
# model/likelihood function
y_pred = pm.Normal('y_pred', mu=tt.dot(X.values, weights)+tt.dot(U.values, random_effect), sd=sigma_square, observed=y)
trace = pm.sample(1000, cores=1, progressbar=False)
summary = pm.summary(trace)
print(summary)
PS: latest version of pymc3, and python3.8