Thank you, but I do not understand R,
I tried halfnormal or halfcachyin in my model, the result is similar with the uniform. And my model can converge without the containment data model.
My code is like this:
start = trace_2[0]
start['zij'] = start['zij'].astype(int)
stds = approx.bij.rmap(approx.std.eval())
cov = model_2.dict_to_array(stds) ** 2
with pm.Model() as model_2b:
b = 2
alpha = pm.HalfNormal('alpha', 0.2)
mu_4 = pm.Normal('mu_4', mu=0, sd=100)
sd_4 = pm.HalfNormal('sd_4', b)
mu_3 = pm.Normal('mu_3', mu=0, sd=100)
sd_3 = pm.HalfNormal('sd_3', b)
mu_2 = pm.Normal('mu_2', mu=0, sd=100)
sd_2 = pm.HalfNormal('sd_2', b)
mu_1 = pm.Normal('mu_1', mu=0, sd=100)
sd_1 = pm.HalfNormal('sd_1', b)
mu_0 = pm.Normal('mu_0', mu=0, sd=100)
sd_0 = pm.HalfNormal('sd_0', b)
beta4 = pm.Normal('beta4', mu_4, sd_4, shape=companiesABC)
beta3 = pm.Normal('beta3', mu_3, sd_3, shape=companiesABC)
beta2 = pm.Normal('beta2', mu_2, sd_2, shape=companiesABC)
beta1 = pm.Normal('beta1', mu_1, sd_1, shape=companiesABC)
beta = pm.Normal('beta', mu_0, sd_0, shape=companiesABC)
liner = pm.Deterministic('liner', tt.exp(beta[ip] + \
(beta1[Num_shared] * xs_year + beta2[Num_shared] * xs_char1 +\
beta3[Num_shared] * xs_char2 + beta4[Num_shared] * xs_year * xs_year)))
pi_ij = pm.Uniform('pi_ij', lower=0, upper=1, shape=len(Num_shared.get_value()))
# latent model for contamination
sigma_p = pm.HalfNormal('sigma_p', b)
mu_p = pm.Normal('mu_p', mu=0, tau=.001)
probitphi = pm.Normal('probitphi', mu=mu_p, sd=sigma_p, shape=companiesABC, testval=np.ones(companiesABC))
phii = pm.Deterministic('phii', Phi(probitphi))
zij = pm.Bernoulli('zij', p=phii[Num_shared], shape=len(Num_shared.get_value()))
beta_mu = pm.Deterministic('beta_mu', tt.switch(tt.eq(zij, 0), liner, pi_ij))
Observed = pm.Weibull("Observed", alpha=alpha, beta=beta_mu, observed=ys_faults) # 观测值
step = pm.NUTS(scaling=cov, is_cov=True)
trace_2b = pm.sample(3000, step=[step], start=start, turn =500)
And if I use uniform to replace phii , than the containment data model doesn’t work at all, the result is the same as I do not use containment data model. Is there any ways?
This is the results: