Beispiel #1
0
print('Using data from ' + start_calibration + ' until ' + end_calibration +
      '\n')
print('1) Particle swarm optimization\n')

# define dataset
data = [df_sciensano['H_in'][start_calibration:end_calibration]]
states = ["H_in"]
weights = [1]
# set PSO optimisation settings
pars = ['warmup', 'beta', 'l', 'effectivity']
bounds = ((20, 40), (0.01, 0.09), (0.1, 20), (0.03, 0.97))
# run PSO optimisation
theta = pso.fit_pso(model,
                    data,
                    pars,
                    states,
                    bounds,
                    maxiter=maxiter,
                    popsize=popsize,
                    start_date=start_calibration)
theta = np.array([37.45480627, 0.04796753, 11, 0.14])  #-75918.16606140955
# Assign estimate
warmup, model.parameters = assign_PSO(model.parameters, pars, theta)
# Perform simulation
out = model.sim(end_calibration, start_date=start_calibration, warmup=warmup)
# Visualize fit
ax = plot_PSO(out, theta, pars, data, states, start_calibration,
              end_calibration)
#plt.show()
#plt.close()

# run MCMC sampler
    weights = [1]

    # -----------
    # Perform PSO
    # -----------

    # set optimisation settings
    pars = ['warmup', 'beta', 'da']
    bounds = ((10, 80), (0.020, 0.06), (3.0, 9.0))
    # run optimisation
    theta = pso.fit_pso(model,
                        data,
                        pars,
                        states,
                        bounds,
                        weights=weights,
                        maxiter=maxiter,
                        popsize=popsize,
                        dist='poisson',
                        poisson_offset=poisson_offset,
                        start_date=start_calibration,
                        processes=processes)
    # Assign estimate
    warmup, model.parameters = assign_PSO(model.parameters, pars, theta)
    # Perform simulation
    out = model.sim(end_calibration,
                    start_date=start_calibration,
                    warmup=warmup)
    # Visualize fit
    ax = plot_PSO(out, theta, pars, data, states, start_calibration,
                  end_calibration)
    plt.show()