I am trying to implement a code created originally here.
What I have is this model:
with pm.Model() as model:
sigma = pm.HalfNormal('sigma', 1, testval=.1)
mu = pm.Normal('mu', 0, sigma, testval=.1)
nu = pm.Exponential('nu', 1./10)
logs = pm.GaussianRandomWalk('logs', sigma**-2, shape=n)
#lam uses variance in pymc3, not sd like in scipy
r = pm.StudentT('r', nu, mu=mu, lam=1/pm.math.exp(-2*logs), observed=returns.values[train])
import scipy as sp
with model:
start = pm.find_MAP(vars=[logs])
with model:
step = pm.NUTS(vars=[logs, mu, nu,sigma],scaling=start, gamma=.25)
start2 = pm.sample(100, step, start=start)[-1]
# Start next run at the last sampled position.
step = pm.NUTS(vars=[logs, mu, nu,sigma],scaling=start2, gamma=.55)
trace = pm.sample(2000, step, start=start2)
However, I am getting the following error:
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'sigma_log__': array(-2.30258509), 'mu': array(0.1), 'nu_log__': array(2.30258509), 'logs': array([ 0., 100., 200., 300., 400., 500., ... 44700.,
44800., 44900.])}
Initial evaluation results:
{'sigma': -2.53, 'mu': 0.88, 'nu': -1.0, 'logs': -418.13, 'r': -inf}
I am not sure what is going on. How do I fix this? I am using pymc rather than pymc3