I’m working on building a framework to fit custom densities to data in PyMC3.
This is my starting set-up, where I try to do it with a simple Normal. What am I missing ? Does the custom density logp_norm need to be expressed in Theano ? Is there a simple way to use the @as_op decorator ?
## LOG DENSITY FOR NORMAL DISTRIBUTION
def logp_norm(x, μ, σ):
"""Normal distribtuion."""
return -0.5*np.log(2*np.pi) - np.log(σ) - (x-μ)**2/(2*σ**2)
## PYMC3 PARAMETER ESTIMATION
with pm.Model() as LogoNormo:
σ = pm.HalfNormal('μ',sd=1)
μ = pm.Normal('σ', mu = 0, sd=1)
"Custom Density"
# Note that by calling the observed here, you declare the likelihood
custom_pdf = pm.DensityDist('custom_pdf', logp_norm(obs_y,μ, σ), observed = obs_y)
trace = pm.sample(2000, chains=3)
pm.traceplot(trace, ['μ', 'σ']);
Would appreciate some clues.
Thank you!