Exemplo n.º 1
0
if (len(data_year) == 0): # no data model
  [M,C] = gpr.gpmodel_nodata(pyear=prior_year,pmort=prior_mort,scale=best_scale,predictionyears=predictionyears,sim=1000,amp2x=best_amp2x,mse=mse)
else: # data model
  [M,C] = gpr.gpmodel(cc,rr,data_year,data_mort,data_var,data_category,prior_year,prior_mort,mse,best_scale,best_amp2x,predictionyears)


## find mean and standard error, drawing from M and C
draws = 1000
mort_draws = np.zeros((draws, len(predictionyears)))
gpr_seeds = [x+123456 for x in range(1,1001)]
for draw in range(draws):
  np.random.seed(gpr_seeds[draw])
mort_draws[draw,:] = Realization(M, C)(predictionyears)

# collapse across draws
logit_est = gpr.collapse_sims(mort_draws)
unlogit_est = gpr.collapse_sims(mort_draws)

# save the predictions
all_est = []
for i in range(len(predictionyears)):
  all_est.append((cc, predictionyears[i], unlogit_est['med'][i], unlogit_est['lower'][i], unlogit_est['upper'][i]))
labels = ['ihme_loc_id','year','med','lower','upper']
all_est_df = pd.DataFrame.from_records(all_est, columns=labels)
output_file = "{}/gpr_{}_{}_{}.txt".format(output_dir, cc, sex, age)
all_est_df.to_csv(output_file, index = False)

# save the sims
all_sim = []
for i in range(len(predictionyears)):
  for s in range(draws):
Exemplo n.º 2
0
else:  # data model
    [M, C] = gpr.gpmodel(cc, rr, data_year, data_mort, data_var, data_category,
                         prior_year, prior_mort, mse, best_scale, best_amp2x,
                         predictionyears)

## find mean and standard error, drawing from M and C
draws = 1000
mort_draws = np.zeros((draws, len(predictionyears)))
gpr_seeds = [x + 123456 for x in range(1, 1001)]
for draw in range(draws):
    np.random.seed(gpr_seeds[draw])
    mort_draws[draw, :] = Realization(M, C)(predictionyears)

# collapse across draws
# note: space transformations need to be performed at the draw level
logit_est = gpr.collapse_sims(mort_draws)
unlogit_est = gpr.collapse_sims(gpr.inv_logit(mort_draws))

if hivsims == 0:
    os.chdir('FILEPATH')
    all_est = []
    for i in range(len(predictionyears)):
        all_est.append((cc, predictionyears[i], unlogit_est['med'][i],
                        unlogit_est['lower'][i], unlogit_est['upper'][i]))
    all_est = pl.array(all_est, [('ihme_loc_id', '|S32'), ('year', '<f8'),
                                 ('med', '<f8'), ('lower', '<f8'),
                                 ('upper', '<f8')])
    pl.rec2csv(all_est, 'gpr_%s.txt' % cc)

# save the sims
all_sim = []
Exemplo n.º 3
0
	[M,C] = gpr.gpmodel(cc,rr,data_year,data_fert,data_var,data_category,prior_year,prior_fert,mse,best_scale,best_amp2x,predictionyears)

	

## find mean and standard error, drawing from M and C
draws = 1000
tfr_draws = np.zeros((draws, len(predictionyears)))
gpr_seeds = [x+123456 for x in range(1,1001)]
for draw in range(draws):
	np.random.seed(gpr_seeds[draw])
	tfr_draws[draw,:] = Realization(M, C)(predictionyears)


# collapse across draws
# note: space transformations need to be performed at the draw level
logit_est = gpr.collapse_sims(tfr_draws)
unlogit_est = gpr.collapse_sims(np.exp(tfr_draws)*tfr_bound/(1+np.exp(tfr_draws))) # get the inverse logit



os.chdir('FILEPATH')

all_est = []
for i in range(len(predictionyears)):
	all_est.append((cc, predictionyears[i], unlogit_est['med'][i], unlogit_est['lower'][i], unlogit_est['upper'][i]))
all_est = pl.array(all_est, [('ihme_loc_id', '|S32'), ('year', '<f8'), ('med', '<f8'), ('lower', '<f8'), ('upper', '<f8')])
pl.rec2csv(all_est, 'gpr_%s.txt' %(cc+'_'+ str(best_amp2x) + '_' + str(best_scale)))

# save the sims 
all_sim = []
for i in range(len(predictionyears)):