Dear all,
I want to use mcmc to fit a very small number of data points to some function.
The basic relation in the background is a power law that relates some quantity E to another quantity I.
However, the signals measured/observed are integrals of I:
the measuring probability follows a Poisson distribution.
My code now:
import numpy as np
import pymc3 as pm
print('Running on PyMC3 v{}'.format(pm.__version__))
# only three data points!
E = np.array([146.0, 148.0, 150.0])
i_s = np.array([ 4000. 3009. 2616.])
dE = 3
plt.plot(E, i_s)
plt.show()
basic_model = pm.Model()
with basic_model:
r = pm.Uniform('r', lower=1, upper=4)
a = pm.Uniform('a', lower=100000, upper=1e8)
I_expect = a / (1 - r) * ((E + dE / 2.0) ** (1 - r) - (E - dE / 2.0) ** (1 - r ))
I_obs = pm.Poisson('I_obs', mu=I_expect, observed=i_s)
# Use the No-U-Turn Sampler
step = pm.NUTS()
# Calculate the trace
trace = pm.sample(10000,
tune=10000,
discard_tuned_samples=True,
cores=2, step=step)
pm.traceplot(trace)
print(pm.summary(trace).round(2))
I tried, uniform and exponential PDFs for a and r and even used only two data points which should yield a solution for a and r in any case. But this does not happen. The solutions found are far away, even if a use a set of 10 or more points for which I set the observed values to that retrieved from ground truth, i.e. started from a given a and r and calculated the observation value using above integral.
I have no clue, whether I ill posed the problem, nor am I very much experienced in using pymc3, nor …
You see, help is very much appreciated.
Thank you very much in advance!
Markus