c_params = L_MLE_c, k_MLE_c, x_MLE_c, np.min(c_list) ages = np.linspace(0, 99, 100) #Transition graphs util.plot_data_transition_exp_estimates(a_params, b_params, c_params, start, end, ages, smooth, datatype='mortality') util.plot_data_transition(mort_data, start, end, ages, smooth, datatype='mortality') util.overlay_estimates_mort(mort_data, a_params, b_params, c_params, start, end, ages, smooth, datatype='mortality') #Graph comparison between 2014 and 2100 util.plot_2100_mort(a_params, b_params,
fert_alt, mort_alt, imm_alt = prep_demog_alternate(fert_data, mort_data, imm_data) datatype = 'population_forecasts' start = 1971 end = 2017 ages = np.linspace(0, 99, 100).astype(int) birth_ages = np.linspace(14, 50, 37) years = np.linspace(start, end, end - start + 1).astype(int) # Plot true data transition util.plot_data_transition(pop_data, ages, 1970, 2014, smooth=0, datatype='population') # Start forecasts prev_pop = pop_data[start - 1] for year in years: pred_fert = util.forecast(fert_params, year - 1, birth_ages, datatype='fertility', options=False) pred_mort = util.forecast(mort_params, year - 1,
c_0 = -0.5 a_MLE, b_MLE, c_MLE = util.exponential_est(imm_yr, year, a_0, b_0, c_0, imm_yr.index, smooth, datatype='immigration', param='imm_fourth_' + str(year)) imm_fourth_as.append(a_MLE) imm_fourth_bs.append(b_MLE) imm_fourth_cs.append(c_MLE) ######################################### #Fit imm_fourth_a, imm_fourth_b, and imm_fourth_c to mean imm_fourth_a_params = np.mean(imm_fourth_as[:25]), np.mean(imm_fourth_as[25:]) imm_fourth_b_params = np.mean(imm_fourth_bs) imm_fourth_c_params = np.mean(imm_fourth_cs) plt.plot(range(start, end + 1), imm_fourth_as) a_vals = [imm_fourth_a_params[0]] * 25 + [imm_fourth_a_params[1]] * (len(imm_fourth_as) - 25) plt.plot(range(start, end + 1), a_vals) plt.savefig('graphs/' + datatype + '/smooth_' + str(smooth) + '/_imm_fourth_as_predicted') plt.close() plt.plot(range(start, end + 1), imm_fourth_bs) plt.plot(range(start, end + 1), [imm_fourth_b_params] * len(imm_fourth_bs)) plt.savefig('graphs/' + datatype + '/smooth_' + str(smooth) + '/_imm_fourth_bs_predicted') plt.close() plt.plot(range(start, end + 1), imm_fourth_cs) plt.plot(range(start, end + 1), [imm_fourth_c_params] * len(imm_fourth_cs)) plt.savefig('graphs/' + datatype + '/smooth_' + str(smooth) + '/_imm_fourth_cs_predicted') plt.close() util.plot_data_transition(imm_rate, start, end, ages, smooth, datatype='immigration')
k_0 = 1.5 x_0 = 1995 L_MLE_alpha, k_MLE_alpha, x_MLE_alpha = util.logistic_est(alphas, L_0, k_0, x_0, years, smooth, datatype='population', param='Alpha') alpha_params = L_MLE_alpha, k_MLE_alpha, x_MLE_alpha, np.min(alphas) ######################################### #Fit ms to logistic function L_0 = 5#max(ms) k_0 = 0.2#1e-50 x_0 = 1995 L_MLE_m, k_MLE_m, x_MLE_m = util.logistic_est(ms, L_0, k_0, x_0, years, smooth, datatype='population', param='M') m_params = L_MLE_m, k_MLE_m, x_MLE_m, np.min(ms) ######################################### #Fit scales to log function a_0 = 2e6 b_0 = np.min(years) - 1 c_0 = 1.9 d_0 = np.min(scales) e_0 = 1 a_MLE_scale, b_MLE_scale, c_MLE_scale, d_MLE_scale, e_MLE_scale = util.poly_est(scales, a_0, b_0, c_0, d_0, e_0, years, smooth, datatype='population', param='Scale', print_params=True) scale_params = a_MLE_scale, b_MLE_scale, c_MLE_scale, d_MLE_scale, e_MLE_scale #Transition graphs util.plot_data_transition_gen_gamma_estimates(beta_params, alpha_params, m_params, scale_params, start, end, ages, smooth, datatype='population') util.plot_data_transition(pop_data, start, end, ages, smooth, datatype='population') util.plot_data_transition_gen_gamma_overlay_estimates(pop_data, beta_params, alpha_params, m_params, scale_params, start, end, ages, smooth, datatype='population') #Graph comparison between 2014 and 2100 util.plot_2100(beta_params, alpha_params, m_params, scale_params, ages, smooth, datatype='population')
p_params = L_MLE_p, k_MLE_p, x_MLE_p, np.min(p_list) ######################################### #Fit q_list to logistic function L_0 = 0.55 k_0 = 0.31 x_0 = 1995 L_MLE_q, k_MLE_q, x_MLE_q = util.logistic_est(q_list, L_0, k_0, x_0, years, smooth, datatype='mortality', param='q', flip=True) q_params = L_MLE_q, k_MLE_q, x_MLE_q, np.min(q_list) ######################################### #Fit scales to logistic function L_0 = max(scales) k_0 = 1.5 x_0 = 1995 L_MLE_scale, k_MLE_scale, x_MLE_scale = util.logistic_est(scales, L_0, k_0, x_0, years, smooth, datatype='mortality', param='Scale') scale_params = L_MLE_scale, k_MLE_scale, x_MLE_scale, np.min(scales) non_infant_params = a_params, b_params, p_params, q_params, scale_params ages = np.linspace(0, 99, 100) #Transition graphs util.plot_forecast_transition( (non_infant_params, infant_params), ages, start, end, smooth, datatype='mortality') util.plot_data_transition(non_infant_mort, ages, start, end, smooth, datatype='mortality') util.overlay_estimates(non_infant_mort, (non_infant_params, infant_params), ages, start, end, smooth, datatype='mortality') #Graph comparison between 2014 and 2100 util.plot_2100( (non_infant_params, infant_params), ages, smooth, datatype='mortality') pickle.dump( (non_infant_params, infant_params), open('data/demographic/parameters/mort.p', 'wb') )