def run_calibration(n_rounds, current_period=0, verbose=0): if not os.path.isdir('../calibrations'): os.makedirs('../calibrations') map = Map() best_score = None for i in range(n_rounds): if i % 10 == 0: print(f'round {i}...') evaluations = [] array_params, pdict = build_parameters(current_period, verbose) map.from_arrays(**array_params) for _ in range(N_PERIODS): for _ in range(pdict['n_moves_per_period']): map.make_move() map.forward_all_cells() state_ids, state_numbers = map.get_states_numbers() evaluations.append((state_ids, state_numbers)) score = evaluate(evaluations, DAY, N_PERIODS) if best_score is None or ( score['hosp']['err'] <= best_score['hosp']['err'] and score['icu']['err'] <= best_score['icu']['err']): fpath = os.path.join(CALIBRATION_DIR, f'{i}.npy') to_save = { 'score': score, 'params': array_params, 'rt': map.get_r_factors(), 'pdict': pdict } print(f'New best score found: {score}, saved under {fpath}') print(f"corresponding pdict:\n{pdict}") best_score = score np.save(fpath, to_save) map.save(os.path.join('maps', 'week1'))
def run_calibration(n_rounds, current_period=0, verbose=0): if not os.path.isdir('../calibrations'): os.makedirs('../calibrations') memory_error = False map = Map() best_score = None for i in range(n_rounds): if i%10 == 0: print(f'round {i}...') evaluations = [] array_params, pdict = build_parameters(current_period, verbose) try: map.from_arrays(**array_params) except: print('Memory error') memory_error = True pass if memory_error: memory_error = False continue for prd in range(N_PERIODS): for _ in range(pdict['n_moves_per_period']): map.make_move(prop_cont_factor=pdict['prop_cont_factor']) map.forward_all_cells() state_ids, state_numbers = map.get_states_numbers() # Check if we are already in the good range at mid time evaluation = (state_ids, state_numbers) if prd == 6: ind_asymptomatic = np.where(evaluation[0] == 1)[0][0].astype(np.uint32) n_asymptomatic = evaluation[1][ind_asymptomatic] evaluations.append(evaluation) score, progressions = evaluate_move(evaluations) if best_score is None or score < best_score: fpath = os.path.join(CALIBRATION_DIR, f'move_3e_{i}.npy') to_save = {'score': score, 'params': array_params, 'pdict': pdict} print(f'New best score found: {score}, saved under {fpath}') print(f'Corresponding progressions: {progressions}') print(f'corresponding params:') pprint(pdict) best_score = score np.save(fpath, to_save)