''' Fit model with best parameters ''' # fit model, get predictions 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 # 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))
''' Fit model with best parameters ''' # fit model, get predictions 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(ihme_loc_id, region_name, 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 (len(test_mort) > 0): all_err = [] # set up holder for holdout results all_est = [] # set up holder for predictions for amp2x in amp2x_list: # loop through amp for scale in scale_list: print('amp2x %f and scale %f' % (amp2x, scale)) ## fit model if (len(train_year) == 0): # no data model [M,C] = gpr.gpmodel_all(prior_mort, prior_year, scale, mse*amp2x) d = gpr.gpmodel_all_pred(M, C, 100, predictionyears) else: # data model [gpmort, allobs, allyear, allvar, bias_vr, bias_sibs] = gpr.gpmodel(prior_mort, prior_year, train_mort, train_year, train_stderr, train_category, scale, mse*amp2x, cc) d = gpr.gpmodel_pred(gpmort, allyear, allvar, allobs, bias_vr, bias_sibs, 500, 300, 2, predictionyears) log_est = gpr.results(d) if (transform == 'log10'): unlog_est = gpr.results(10**d) # log base 10 space #print('1') elif (transform == 'ln'): unlog_est = gpr.results(math.e**d) # natural log space #print('2') elif (transform == 'logit'): unlog_est = gpr.results((math.e**d)/(1+(math.e**d))) # logit space #print('3') elif (transform == 'logit10'): unlog_est = gpr.results((10**d)/(1+(10**d))) # logit10 space #print('4')
# best_amp2 = 2 ''' Test all parameter combinations ''' # fit model, get predictions if (len(data_year) == 0): # no data model [M, C] = gpr.gpmodel_all(prior_mort, prior_year, best_scale, best_amp2) d = gpr.gpmodel_all_pred(M, C, dr, predictionyears) else: # data model if (dr == int(10)): [gpmort, allobs, allyear, allvar, bias_vr, bias_sibs] = gpr.gpmodel(prior_mort, prior_year, data_mort, data_year, data_stderr, data_category, best_scale, best_amp2, cc) d = gpr.gpmodel_pred(gpmort, allyear, allvar, allobs, bias_vr, bias_sibs, 5000, 3000, 2, predictionyears) else: [gpmort, allobs, allyear, allvar, bias_vr, bias_sibs] = gpr.gpmodel(prior_mort, prior_year, data_mort, data_year, data_stderr, data_category, best_scale, best_amp2, cc) d = gpr.gpmodel_pred(gpmort, allyear, allvar, allobs, bias_vr, bias_sibs, 5000, 3000, 2, predictionyears) if (transform == 'log10'): unlog_est = gpr.results(10**d) # log base 10 space elif (transform == 'ln'):
for amp2x in amp2x_list: # loop through amp for scale in scale_list: print('amp2x %f and scale %f' % (amp2x, scale)) ## fit model if (len(train_year) == 0): # no data model [M, C] = gpr.gpmodel_nodata(pyear=prior_year, pmort=prior_mort, scale=scale, predictionyears=predictionyears, sim=100, amp2x=amp2x, mse=mse) else: # data model [M, C] = gpr.gpmodel(cc, rr, train_year, train_mort, train_var, train_category, prior_year, prior_mort, mse, scale, amp2x, predictionyears) ## find mean and standard error, drawing from M and C draws = 1000 #not setting seed here because the holdouts are random anyway mort_draws = np.zeros((draws, len(predictionyears))) for draw in range(draws): 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)) ## save the predictions