import pymc as pm from numpy import * from age_pr_datasets import * N_pops = len(datasets) S_guess = exp(-a/20.) S_guess /= sum(S_guess) # Model for central tendency of age distribution. alph_pri = 10. scg = [] for i in xrange(len(a)): asg_now = pm.lam_dtrm('asg_%i'%i, lambda alpha=alph_pri, S=S_guess, i=i : alpha*S[i]) scg.append(pm.Gamma('scg_%i'%i, alpha=asg_now, beta=1., value=asg_now.value)) sc = pm.lam_dtrm('sc',lambda gams=scg: array(gams)/sum(gams)) # Model for age distributions of individual populations # alph = pm.Gamma('alph',2.,2./1000.) alph = pm.OneOverX('alph', value=50.) asc = pm.lam_dtrm('asc',lambda alph=alph,S=sc: alph*S) S = [] S_steps = [] data_list = [] for name in datasets.iterkeys(): this_dataset = datasets[name]
data_list = [] pred_data_list = [] deviance_list = [] pred_deviance_list = [] p_vec_list = [] P_prime_list = [] for name in datasets.iterkeys(): safe_name = name.replace('.','_') P_prime_now = pm.Beta('P_prime_%s'%safe_name,3.,3.) p_vec_now = pm.MvNormalChol('p_vec_%s'%safe_name, p_mean, cholfac) p_vec_list.append(p_vec_now) P_prime_list.append(P_prime_now) b = pm.lam_dtrm('b', lambda p_vec = p_vec_now: 1./exp(p_vec[0])) if methods[name] == 'Microscopy': # alpha, s and c depend on p_vec[1:4] c = pm.lam_dtrm('c', lambda p_vec = p_vec_now: 1./exp(p_vec[1])) alph = pm.lam_dtrm('alph', lambda p_vec = p_vec_now: exp(p_vec[2])) s = pm.lam_dtrm('s', lambda p_vec = p_vec_now: pm.invlogit(p_vec[3])) elif methods[name] == 'RDT': # alpha, s and c depend on p_vec[4:7] c = pm.lam_dtrm('c', lambda p_vec = p_vec_now: 1./exp(p_vec[4])) alph = pm.lam_dtrm('alph', lambda p_vec = p_vec_now: exp(p_vec[5])) s = pm.lam_dtrm('s', lambda p_vec = p_vec_now: pm.invlogit(p_vec[6]))