Hi everyone! I’m very new to both pymc3 and Bayesian inference in general so please be gentle with me…
I am trying to model the following time series:
phi_i ~ Normal(phi_(i-1), rw_step)
x_i ~ Bernoulli(p_i)
where p_i = sin(period * tau * i +phi_i)
I observe the values of x and want to obtain an estimate and posterior distribution for period. For simplicity assume that tau and rw_step are known, and that rw_step is small.
my code looks like this:
n = len(data)
i=np.arange(n)
basic_model = pm.Model()
with basic_model:
period = pm.Normal('period', mu=110., sd=500.0)
phase = pm.GaussianRandomWalk('phase',mu=0,sd=rw_step, shape=n)
probs = pm.math.sin(tau*i+phase)** 2
x = pm.Bernoulli('x', p=probs, shape=n, observed=data)
I am running into trouble when I try to use find_MAP:
Warning: Desired error not necessarily achieved due to precision loss.
Current function value: 10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104.000000
Iterations: 0
Function evaluations: 113
Gradient evaluations: 101
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-70-f85b0c7dfa75> in <module>()
----> 1 map_estimate = pm.find_MAP(model=basic_model )
2
3 print(map_estimate)
C:\ProgramData\Anaconda3\lib\site-packages\pymc3\tuning\starting.py in find_MAP(start, vars, fmin, return_raw, model, *args, **kwargs)
151 "density. 2) your distribution logp's are " +
152 "properly specified. Specific issues: \n" +
--> 153 specific_errors)
154 mx = {v.name: mx[v.name].astype(v.dtype) for v in model.vars}
155
ValueError: Optimization error: max, logp or dlogp at max have non-finite values. Some values may be outside of distribution support. max: {'period': array(110.0), 'phase': array([ 0., 0., 0., ..., 0., 0., 0.])} logp: array(-inf) dlogp: array([-0. , 0. , -0.12582933, ..., 0.3815204 ,
0.25265876, 0.12582933])Check that 1) you don't have hierarchical parameters, these will lead to points with infinite density. 2) your distribution logp's are properly specified. Specific issues:
Sampling the distribution did not produce useful results as well.
What am I doing wrong?
Note: general tips about this kind of model would be very welcome.