python - How do I add an attribute name to an array? -
i wondering how add attribute array.
when
errors1 = pm.uniform('errors', 0, 100, size = 7)
the name 'errors' added.
but when do
errors2 = [errors1[1], errors1[3], errors1[6]]
i have no idea how add name, , because didn't add it, when try create model errors2, error, saying doesn't have attribute name.
here's full code:
import pymc pm matplotlib import pyplot plt pymc.matplot import plot mcplot import numpy np matplotlib import rc first_res = [-27.020,3.570,8.191,9.898,9.603,9.945,10.056] second_res = [18.752, 12.450, 11.832] v1 = pm.uniform('v1', -30, 15) v2 = pm.uniform('v2', 0, 20) errors1 = pm.uniform('errors', 0, 100, size = 7) errors2 = [errors1[1], errors1[3], errors1[6]] # doesn't have attribute name taus1 = 1/(errors1 ** 2) taus2 = [taus1[1], taus1[3], taus1[6]] first_dist = pm.normal('first_dist', mu = v1, tau = taus1, value = first_res, observed = true) second_dist= pm.normal('second_dist', mu = v2, tau = taus2, value = second_res, observed = true) model=pm.model([first_dist, second_dist, errors1, taus1, v1, v2]) mcmc=pm.mcmc(model) mcmc.sample(20000,10000) mcplot(mcmc.trace("errors")) plt.figure() model2=pm.model([second_dist, errors2, taus2, v2]) # since errors2 doesn't have attribute name, error mcmc2=pm.mcmc(model2) mcmc2.sample(20000,10000) mcplot(mcmc2.trace('second_dist'))
pymc2
has magic lets operate on nodes errors1
if numpy arrays, doesn't work might expect. in cases this, can define deterministic node explicitly pm.lambda
, e.g.
errors2 = pm.lambda('errors2', lambda errors1=errors1: [errors1[1], errors1[3], errors1[6]])
Comments
Post a Comment