def run_opt(city, budget, start_date, important_dates, infectratio_range=None, dummy_range=None, unob_flow_num=None, repeat_time=1, init_samples=None, training_end_date=None, json_name='data_run.json', seed=3, loss_ord=0.0, touch_range=None,iso_range=None): assert infectratio_range is not None and dummy_range is not None days_predict = 0 # load data real_data = pd.read_csv(get_data_path(True)) history_real = prepareData(real_data) flow_out_data = None # initialize models infectratio = InfectRatio(1, [infectratio_range], [True]) if touch_range is None: touchratio = TouchRatio(1, [[0.999, 1.0000]], [True]) else: touchratio = TouchRatio(1, [touch_range], [True]) touchratiointra = TouchRatio(1, [[0, 1]], [True]) obs = ObservationRatio(1, [[0.0, 0.3]], [True]) dead = DeadRatio(1, [[0., 0.01]], [True]) if iso_range is None: isoratio = IsolationRatio(1, [[0.03, 0.12]], [True]) else: isoratio = IsolationRatio(1, [iso_range], [True]) dummy = DummyModel(1, [dummy_range], [True, True]) cure_ratio = InfectRatio(1, [[0., 0.15]], [True]) simulator = Simulator(city, infectratio, touchratio, obs, dead, dummy, isoratio, touchratiointra, cure_ratio, important_dates, unob_flow_num=unob_flow_num, flow_out_data=flow_out_data, training_date_end=training_end_date) test_date = datetime.strptime(history_real['date'].max(), '%Y-%m-%d').date() - timedelta(days_predict) history_real = history_real[history_real['adcode'] == city] history_real = history_real[history_real['date'] >= str(start_date)] history_train = history_real[history_real['date'] <= str(test_date)] x, y = simulator.fit(history_train, budget=budget, server_num=get_core_num(), repeat=repeat_time, seed=seed, intermediate_freq=10000, init_samples=init_samples, loss_ord=loss_ord) print('best_solution: x = ', x, 'y = ', y) simulator.set_param(x) run_simulation(x, city, 60, 60, start_date, get_important_date(city), unob_flow_num=unob_flow_num, json_name=json_name) return x
def run_opt(city, budget, start_date, important_dates, infectratio_range=None, dummy_range=None, unob_flow_num=None, repeat_time=1, init_samples=None, training_date_end=None, json_name='data_run.json', seed=1, loss_ord=0.0, unob_period=None, obs_period=None, iso_period=None, cure_period=None, isoratio_it=None): if city == 420000: infectratio_range = [0., 0.05] dummy_range = [0.0000, 400.00001] else: assert infectratio_range is not None and dummy_range is not None days_predict = 0 # load data real_data = pd.read_csv(get_data_path()) history_real = prepareData(real_data) flow_out_data = flowOutData() # initialize models infectratio = InfectRatio(1, [infectratio_range], [True]) touchratio = TouchRatio(1, [[0.0, 0.6]], [True]) touchratiointra = TouchRatio(1, [[0, 1]], [True]) obs = ObservationRatio(1, [[0.0, 0.3]], [True]) dead = DeadRatio(1, [[0., 0.01]], [True]) if isoratio_it is None: isoratio = IsolationRatio(1, [[0.2, 0.5]], [True]) else: isoratio = IsolationRatio(1, [isoratio_it], [True]) dummy = DummyModel(1, [dummy_range], [True, True]) cure_ratio = InfectRatio(1, [[0., 0.1]], [True]) # set the time of applying touchratio simulator = Simulator(city, infectratio, touchratio, obs, dead, dummy, isoratio, touchratiointra, cure_ratio, important_dates, unob_flow_num=unob_flow_num, flow_out_data=flow_out_data, training_date_end=training_date_end) # set period here simulator.set_period() test_date = datetime.strptime(history_real['date'].max(), '%Y-%m-%d').date() - timedelta(days_predict) history_real = history_real[history_real['adcode'] == city] history_real = history_real[history_real['date'] >= str(start_date)] history_train = history_real[history_real['date'] <= str(test_date)] x, y = simulator.fit(history_train, budget=budget, server_num=get_core_num(), repeat=repeat_time, seed=seed, intermediate_freq=10000, init_samples=init_samples, loss_ord=loss_ord) print('best_solution: x = ', x, 'y = ', y) simulator.set_param(x) run_simulation(x, city, 60, 60, start_date, get_important_date(city), unob_flow_num=unob_flow_num, json_name=json_name) duration = len(real_data["date"].unique()) - 1 sim_res, _ = simulator.simulate(str(start_date), duration) print('RMSE: ', get_newly_loss(sim_res, history_real)) return x, sim_res