Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@mc.deterministic
def mu_age_p(logit_C0=logit_C0,
i=rate['i']['mu_age'],
r=rate['r']['mu_age'],
f=rate['f']['mu_age']):
# for acute conditions, it is silly to use ODE solver to
# derive prevalence, and it can be approximated with a simple
# transformation of incidence
if r.min() > 5.99:
return i / (r + m_all + f)
C0 = mc.invlogit(logit_C0)
x = pl.hstack((i, r, f, 1-C0, C0))
y = fun.forward(0, x)
@mc.deterministic
def mu_age_m_with(m=rate['m']['mu_age'], f=rate['f']['mu_age']):
return m+f
m_with = age_specific_rate(model, 'm_with',
@pymc.deterministic
def gamma(log_gamma=log_gamma):
return np.exp(log_gamma)
@mc.deterministic
def data_predicted(param_predicted=param_predicted, tau=tau):
return mc.rnormal(param_predicted, tau)
predicted = data_predicted
@mc.deterministic
def pred(pi=pi):
return mc.rbinomial(n, pi)
@mc.deterministic(name='dispersion_%s' % key)
def sigma(log_sigma=log_sigma):
return np.exp(log_sigma)
# TODO: replace this potential in the generate_prior_potentials function if confidence is set
@pm.deterministic
def obs_V(obs_V=obs_V, obs_mesh = obs_mesh):
return np.resize(obs_V, obs_mesh.shape[0])
@mc.deterministic(name='%s_w_bounds'%rate_vars['rate_stoch'].__name__)
def mu_bounded(mu=rate_vars['rate_stoch'], bounds_func=rate_vars['bounds_func']):
return bounds_func(mu, pl.arange(101)) # FIXME: don't hardcode age range
rate_vars['unbounded_rate'] = rate_vars['rate_stoch']
@mc.deterministic(name='p_pred_%s'%name)
def p_pred(pi=pi, n=n_nonzero):
return mc.rbinomial(n, pi+1.e-9) / (1.*n)
@mc.deterministic(name=key % 'bins')
def SCpm(SC_0=SC_0, i=i, r=r, f=f, m_all_cause=m_all_cause, age_mesh=dm.get_param_age_mesh()):
SC = pl.zeros([2, len(age_mesh)])
p = pl.zeros(len(age_mesh))
m = pl.zeros(len(age_mesh))
SC[:,0] = SC_0
p[0] = SC_0[1] / (SC_0[0] + SC_0[1])
m[0] = dismod3.utils.trim(m_all_cause[age_mesh[0]] - f[age_mesh[0]] * p[0],
.1*m_all_cause[age_mesh[0]],
1-dismod3.settings.NEARLY_ZERO) # trim m[0] to avoid numerical instability
for ii, a in enumerate(age_mesh[:-1]):
A = pl.array([[-i[a]-m[ii], r[a] ],
[ i[a] , -r[a]-m[ii]-f[a]]]) * (age_mesh[ii+1] - age_mesh[ii])
SC[:,ii+1] = pl.dot(scipy.linalg.expm(A), SC[:,ii])