Beispiel #1
0
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
print('\n2) Markov-Chain Monte-Carlo sampling\n')


# Define prior
def prior_uniform(x, bounds):
    prob = 1 / (bounds[1] - bounds[0])
Beispiel #2
0
        theta = pso.fit_pso(model,
                            data,
                            pars,
                            states,
                            bounds,
                            weights=weights,
                            maxiter=maxiter,
                            popsize=popsize,
                            dist='poisson',
                            poisson_offset=poisson_offset,
                            agg=agg,
                            start_date=start_calibration,
                            processes=processes)
        #         theta = np.array([48, 0.01896, 0.02153, 0.02599])
        # Assign estimate.
        warmup, pars_PSO = assign_PSO(model.parameters, pars, theta)
        model.parameters = pars_PSO

        # Perform simulation with best-fit results
        out = model.sim(end_calibration,
                        start_date=start_calibration,
                        warmup=warmup)

        # Print statement to stdout once
        print(f'\nPSO RESULTS:')
        print(f'------------')
        print(f'warmup: {warmup}')
        print(f'infectivities {pars[1:]}: {theta[1:]}.')
        sys.stdout.flush()

        # Visualize fit and save in order to check the validity of the first step