Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:type mu : 1D :class:`numpy.ndarray`
:param sigma: The standard deviation of each component.
:type sigma : 1D :class:`numpy.ndarray`
"""
# Make sure everything is a numpy array
pi = np.array(pi)
mu = np.array(mu)
sigma = np.array(sigma)
# The number of components in the mixture
n = pi.shape[0]
# pymc.normal_like requires the precision not the variance:
tau = np.sqrt(1. / sigma ** 2)
# The following looks a little bit awkward because of the need for
# numerical stability:
p = np.log(pi)
p += np.array([pymc.normal_like(value, mu[i], tau[i])
for i in range(n)])
p = math.fsum(np.exp(p))
# logp should never be negative, but it can be zero...
if p <= 0.:
return -np.inf
return gamma * math.log(p)
def data_obs(data_expected=data_expected, value=data):
return mc.normal_like(value[:,1],
data_expected,
value[:,2]**-2)
def p_obs(value=p, pi=pi, sigma=sigma, s=s):
return mc.normal_like(value[~i_inf], pi[~i_inf], 1./(sigma**2. + s[~i_inf]**2.))
def y_i(value=y, mu=y_hat, tau=tau_y):
return pymc.normal_like(value,mu,tau)
def y_i(value=y, mu=y_hat, tau=tau_y):
return pymc.normal_like(value,mu,tau)
def hier_potential(r1=vars[stoch_key]['rate_stoch'], r2=world_rate,
c1=vars[stoch_key]['conf'], c2=world_confidence):
return mc.normal_like(np.diff(r1) - np.diff(r2), 0., c1 + c2)
vars[stoch_key]['h_potential'] = hier_potential
@mc.potential(name='deriv_sign_{%d,%d,%d,%d}^%s' % (deriv, sign, age_start, age_end, str(rate)))
def deriv_sign_rate(f=rate,
age_indices=age_indices,
tau=1.e14,
deriv=deriv, sign=sign):
df = pl.diff(f[age_indices], deriv)
return mc.normal_like(pl.absolute(df) * (sign * df < 0), 0., tau)
return [deriv_sign_rate]
@pm.observed
@pm.stochastic
def y(value = 1, mu = x, tau = 100):
return pm.normal_like(value, numpy.sum(mu**2), tau)
def sensors(value=data, mu=model_output, tau=tau, gamma=1.):
"""The value of the response at the sensors."""
return gamma * pymc.normal_like(value, mu=mu, tau=tau)
return locals()