fun=model_covid_predictions, y0=x_0_cases, t_span=[ t_predictions[0], t_predictions[-1] ], t_eval=t_predictions, args=tuple(optimal_params), ).y return x_sol_best x_sol_final = solve_best_params_and_predict( best_params) data_creator = DELPHIDataCreator( x_sol_final=x_sol_final, date_day_since100=date_day_since100, best_params=best_params, continent=continent, country=country, province=province, ) # Creating the parameters dataset for this (Continent, Country, Province) mape_data = ( mape(fitcasesnd, x_sol_final[15, :len(fitcasesnd)]) + mape(fitcasesd, x_sol_final[14, :len(fitcasesd)])) / 2 try: mape_data_2 = ( mape( fitcasesnd[-15:], x_sol_final[15, len(fitcasesnd) -
x_0_cases = get_initial_conditions( params_fitted=optimal_params, global_params_fixed=GLOBAL_PARAMS_FIXED ) x_sol_best = solve_ivp( fun=model_covid, y0=x_0_cases, t_span=[t_predictions[0], t_predictions[-1]], t_eval=t_predictions, args=tuple(optimal_params), ).y return x_sol_best x_sol_final = solve_best_params_and_predict(best_params) data_creator = DELPHIDataCreator( x_sol_final=x_sol_final, date_day_since100=date_day_since100, best_params=best_params, continent=continent, country=country, province=province, testing_data_included=False ) # Creating the parameters dataset for this (Continent, Country, Province) # mape_data = ( # mape(fitcasesnd, x_sol_final[15, :len(fitcasesnd)]) + # mape(fitcasesd, x_sol_final[14, :len(fitcasesd)]) # ) / 2 if len(fitcasesnd)> 15: mape_data_2 = ( mape(fitcasesnd[-15:], x_sol_final[15, len(fitcasesnd)-15:len(fitcasesnd)]) + mape(fitcasesd[-15:], x_sol_final[14, len(fitcasesnd)-15:len(fitcasesd)]) ) / 2 print(mape_data_2) df_parameters_cont_country_prov = data_creator.create_dataset_parameters(mape_data_2) list_df_global_parameters.append(df_parameters_cont_country_prov) # Creating the datasets for predictions of this (Continent, Country, Province)
params_fitted=optimal_params, global_params_fixed=GLOBAL_PARAMS_FIXED) x_sol_best = solve_ivp( fun=model_covid_predictions, y0=x_0_cases, t_span=[t_predictions[0], t_predictions[-1]], t_eval=t_predictions, args=tuple(optimal_params), ).y return x_sol_best x_sol_final = solve_best_params_and_predict(best_params) data_creator = DELPHIDataCreator( x_sol_final=x_sol_final, date_day_since100=date_day_since100, best_params=best_params, continent=continent, country=country, province=province, ) # Creating the parameters dataset for this (Continent, Country, Province) mape_data = ( mape(fitcasesnd, x_sol_final[15, :len(fitcasesnd)]) + mape(fitcasesd, x_sol_final[14, :len(fitcasesd)])) / 2 mape_data_2 = (mape( fitcasesnd[-15:], x_sol_final[ 15, len(fitcasesnd) - 15:len(fitcasesnd)]) + mape( fitcasesd[-15:], x_sol_final[ 14, len(fitcasesnd) - 15:len(fitcasesd)])) / 2 print("Policy: ", future_policy, "\t Enacting Time: ", future_time, "\t Total MAPE=", mape_data,
params_fitted=optimal_params, global_params_fixed=GLOBAL_PARAMS_FIXED) x_sol_best = solve_ivp( fun=model_covid, y0=x_0_cases, t_span=[t_cases_all[0], t_cases_all[-1]], t_eval=t_cases_all, args=tuple(optimal_params), ).y return x_sol_best x_sol_final = solve_best_params_and_predict(best_params) data_creator = DELPHIDataCreator( x_sol_final=x_sol_final, date_day_since100=date_day_since100, best_params=best_params, continent=continent, country=country, province=province, ) df_backtest_performance_tuple = data_creator.create_df_backtest_performance_tuple( fitcasesnd=fitcasesnd, fitcasesd=fitcasesd, testcasesnd=testcasesnd, testcasesd=testcasesd, n_days_fitting=n_days_fitting, n_days_test=n_days_test, ) # Appending the dataset for backtest performance of this (Continent, Country, Province) list_df_backtest_performance.append(df_backtest_performance_tuple) print( f"Finished backtesting for Continent={continent}, Country={country}, Province={province}"