Пример #1
0
def test_baseline_run():
    from pandemic.models.SEIRDS import SEIRDS, states, params, s_params, ns, t_duration_bounds, t_initial_bounds
    # test baseline model
    p, phase0, traj = generate_phase(SEIRDS,
                                     ns,
                                     states,
                                     params,
                                     s_params,
                                     t_initial_bounds,
                                     t_duration_bounds,
                                     fix_initial=True)

    p.driver = om.pyOptSparseDriver()
    p.driver.options['optimizer'] = 'IPOPT'
    p.driver.options['print_results'] = False

    p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
    # p.driver.opt_settings['mu_init'] = 1.0E-2
    p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'
    p.driver.opt_settings['print_level'] = 5
    p.driver.opt_settings['linear_solver'] = 'mumps'
    p.driver.opt_settings['max_iter'] = 500

    phase0.add_boundary_constraint('I', loc='final', upper=0.01, scaler=1.0)

    phase0.add_objective('time', loc='final', scaler=1.0)

    phase0.add_timeseries_output('theta')

    setup_and_run_phase(states, p, phase0, traj, t_duration_bounds[0])

    max_I = np.max(states['I']['result'])
    final_R = states['R']['result'][-1]
    final_S = states['S']['result'][-1]
    final_D = states['D']['result'][-1]

    print("max_I", max_I)
    print("final_R", final_R)
    print("final_S", final_S)
    print("final_D", final_D)

    mI_actual = 0.26364939220443845
    fR_actual = 0.66815968
    fS_actual = 0.26927833
    fD_actual = 0.05378587

    tol = 1e-2

    assert (abs(max_I - mI_actual) / mI_actual) < tol
    assert (abs(final_R - fR_actual) / fR_actual) < tol
    assert (abs(final_S - fS_actual) / fS_actual) < tol
    assert (abs(final_D - fD_actual) / fD_actual) < tol

    return states, params
Пример #2
0
def test_baseline_run():
    ns = 35
    t_initial_bounds = [0.0, 1.0]
    t_duration_bounds = [200.0, 301.00]
    from pandemic.models.SIR import SIR, states, params, s_params

    p, phase0, traj = generate_phase(SIR,
                                     ns,
                                     states,
                                     params,
                                     s_params,
                                     t_initial_bounds,
                                     t_duration_bounds,
                                     fix_initial=True)

    p.driver = om.pyOptSparseDriver()
    p.driver.options['optimizer'] = 'IPOPT'
    p.driver.options['print_results'] = False
    p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
    # p.driver.opt_settings['mu_init'] = 1.0E-2
    p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'
    p.driver.opt_settings['print_level'] = 5
    p.driver.opt_settings['linear_solver'] = 'mumps'
    p.driver.opt_settings['max_iter'] = 500

    phase0.add_boundary_constraint('I', loc='final', upper=0.05, scaler=1.0)

    phase0.add_objective('time', loc='final', scaler=1.0)

    phase0.add_timeseries_output('theta')

    setup_and_run_phase(states, p, phase0, traj, t_duration_bounds[0])

    max_I = np.max(states['I']['result'])
    final_S = states['S']['result'][-1]

    print("max_I", max_I)
    print("final_S", final_S)
    err = abs(max_I - 0.3592) / 0.3592
    assert (err < 1e4)

    return states, params
Пример #3
0
p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
# p.driver.opt_settings['mu_init'] = 1.0E-2
p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'
p.driver.opt_settings['print_level'] = 5
p.driver.opt_settings['linear_solver'] = 'mumps'
p.driver.opt_settings['max_iter'] = 500

phase0.add_boundary_constraint('I', loc='final', upper=0.01, scaler=1.0)

#phase0.add_control('sigma', targets=['sigma'], lower=0.0, upper=beta, ref=beta)
#phase0.add_objective('max_I', scaler=1000.0)

phase0.add_objective('time', loc='final', scaler=1.0)

phase0.add_timeseries_output('theta')

setup_and_run_phase(states, p, phase0, traj, 200.0)

# plot all states
fig = make_plots(states, params)

max_I = np.max(states['I']['result'])

fig.suptitle('peak infection = %2.2f, no mitigation' % max_I)
plt.savefig("images/Figure_1.png")

plt.show()


Пример #4
0
# p.driver.options['optimizer'] = 'SNOPT'
# p.driver.opt_settings['iSumm'] = 6

# put a limit on max_I of 0.15
phase0.add_path_constraint('I', upper=0.15)

# contact rate mitigation between t_on and t_off
phase0.add_control('sigma', targets=['sigma'], lower=0.0, upper=beta, ref=beta)

# minimize infection curve
phase0.add_objective('int_sigma', scaler=1.0)

# record effective contact rate
phase0.add_timeseries_output('theta')

setup_and_run_phase(states, p, phase0, traj, t_duration)

# plot all states
fig = make_plots(states, params)

max_I = np.max(states['I']['result'])

fig.suptitle(
    'peak infection = %2.2f by mitigation through $\\sigma^2$ minimization' %
    max_I)

plt.savefig("images/Figure_2.png")

plt.show()
Пример #5
0
                                     ns,
                                     states,
                                     params,
                                     s_params,
                                     t_initial_bounds,
                                     t_duration_bounds,
                                     fix_initial=True)

    p.driver = om.pyOptSparseDriver()
    p.driver.options['optimizer'] = 'IPOPT'
    p.driver.options['print_results'] = False

    p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
    # p.driver.opt_settings['mu_init'] = 1.0E-2
    p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'
    p.driver.opt_settings['print_level'] = 5
    p.driver.opt_settings['linear_solver'] = 'mumps'
    p.driver.opt_settings['max_iter'] = 500

    phase0.add_boundary_constraint('I', loc='final', upper=0.01, scaler=1.0)

    phase0.add_objective('time', loc='final', scaler=1.0)

    phase0.add_timeseries_output('theta')

    setup_and_run_phase(states, p, phase0, traj, t_duration_bounds[0])

    make_plots(states, params)

    plt.show()