I’m using pymc3 to process some experimental data.I need to define a likelihood by myself to remove background signal.But I don’t know how.For example ,I define a normal likelihood,but it dose’t work well .Compared to pm.Normal, it creates larger standard deviation and less accuracy.When it works, a userwarning come out : The effect of Potentials on other parameters is ignored during prior predictive sampling. This is likely to lead to invalid or biased predictive samples.
I don’t know how to write a likelihood which works the same an pm.normal?
there are my codes:
def likelihood(observed,sigma,mu):
return pm.math.exp(-0.5 * ((observed - mu) / sigma) ** 2) / (pm.math.sqrt(2 * np.pi) * sigma)
with pm.Model() as ballabio_model:
amp1 = pm.Normal("amp1", mu=np.sum(data/Ascale), sigma=0.2*np.sum(data/Ascale))
Tion1 = pm.Uniform('Tion1',lower=0.5,upper=10.0)
const1 = pm.Uniform('constant1', 0, 10)
sigma=noise_total1
output = pm.Deterministic('output',amp1*ballabio(E_mid,Tion1) + const1)
likelihood = pm.Potential('likelihood',likelihood(data,sigma,output))
prior = pm.sample_prior_predictive()
posterior2 = pm.sample(draws = Samples, target_accept = 0.9,chains=4,cores=1)
posterior_without_background = pm.sample_posterior_predictive(posterior1)
az.plot_trace(posterior2, var_names = ['amp1','Tion1','constant1'])
result_no_background2=az.summary(posterior2, var_names = ['amp1','Tion1','constant1'])
and results: