-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
AR and AR1 models fail with default sampling (and NUTS/Hamiltonian in general), raising a value error
ValueError: Mass matrix contains zeros on the diagonal. The derivative of RV beta.ravel()[0] is zero.
Metropolis sampling seems to work for these models. Not sure if this is a bug or unsuitable sampling, but I've seen a few examples of AR models fit with default sampling, so this may just be the result of changes in default sampling.
Examples below...
# AR1 model with NUTS
beta_true = 0.8
y_true = np.zeros(100)
for i in range(1,len(y_true)):
y_true[i] = beta_true * y_true[i-1] + np.random.normal(0,1)
with pymc3.Model() as AR1_model:
beta = pymc3.Normal("beta",mu=0, sd=2)
obs = pymc3.AR1("obs", k=beta, tau_e=1,observed=y_true)
trace = pymc3.sample()
# AR model with NUTS
alpha_true = 0.2
beta1_true = 0.7
beta2_true = 0.05
y_true = np.zeros(100)
for i in range(2,len(y_true)):
y_true[i] = alpha_true + beta1_true * y_true[i-1] + beta2_true * y_true[i-2] + np.random.normal(0,1)
y_true = np.array(y_true[1:])
with pymc3.Model() as AR_model:
beta = pymc3.Uniform("beta",lower=0, upper=1, shape=2)
obs = pymc3.AR("obs", rho=beta, sd=0.01, constant=True, observed=y_true)
trace = pymc3.sample()
pymc3 version: '3.4.1'
theano version: '1.0.2'
EDIT:
Initializing with ADVI allows sampling to complete, but results in an acceptance rate of 1, and incorrect estimates.
The acceptance probability does not match the target. It is 1.0, but should be close to 0.8. Try to increase the number of tuning steps.