# This prior is not exactly the same as the true parameter prior_dict = {'c': dists.Normal(loc=8e-11,scale=2e-11), 'm': dists.Normal(loc = 1.5, scale = 1e-1), 'a0':dists.Gamma(1/2, 2), # Chi squared with k=1 "v":dists.Gamma(1/2,2)} # This is chi squared with k=1 # # This prior is significantly different from the true parameters # prior_dict = {'c': dists.Normal(loc=8e-11,scale=1e-11), # 'm': dists.Normal(loc = 1.5, scale = 5e-1), # 'a0':dists.Gamma(1/2, 2), # Chi squared with k=1 # "v":dists.Gamma(1/2,2)} # This is chi squared with k=1 my_prior = dists.StructDist(prior_dict) # Run the smc2 inference fk_smc2 = ssp.SMC2(ssm_cls=ParisLaw, data=data, prior=my_prior, init_Nx=8000)#, ar_to_increase_Nx=0.1) alg_smc2 = particles.SMC(fk=fk_smc2, N=10000, store_history=True, verbose=True) alg_smc2.run() alg_smc2.true_model = true_model # Save the true model so it can be used in post processing alg_smc2.true_states = true_states # Save the true states so RUL's can be calculated # Save the result with open('run_20201010a.pkl', 'wb') as f: dill.dump(alg_smc2, f) # Load the previously computed data with open('run_20201010a.pkl', 'rb') as f: alg_smc2 = dill.load(f)
# algorithms N = 10**3 # re-run with N= 10^4 for the second CDF plots fks = {} fk_opts = { 'ssm_cls': state_space_models.StochVolLeverage, 'prior': prior, 'data': data, 'init_Nx': 100, 'smc_options': { 'qmc': False }, 'ar_to_increase_Nx': 0.1, 'wastefree': False, 'len_chain': 6 } fks['smc2'] = ssp.SMC2(**fk_opts) fk_opts['smc_options']['qmc'] = True fks['smc2_qmc'] = ssp.SMC2(**fk_opts) fk_opts['ssm_cls'] = state_space_models.StochVol fks['smc2_sv'] = ssp.SMC2(**fk_opts) # runs runs = particles.multiSMC(fk=fks, N=N, collect=[Moments(mom_func=qtiles)], verbose=True, nprocs=0, nruns=25) # plots #######
data=data, prior=my_prior, Nx=200, niter=1000) pg.run() # may take several seconds... plt.plot(pg.chain.theta['mu']) plt.xlabel('iter') plt.ylabel('mu') plt.figure() plt.hist(pg.chain.theta['mu'][20:], 50) plt.xlabel('mu') import particles from particles import smc_samplers as ssp fk_smc2 = ssp.SMC2(ssm_cls=StochVol, data=data, prior=my_prior, init_Nx=50, ar_to_increase_Nx=0.1) alg_smc2 = particles.SMC(fk=fk_smc2, N=500) alg_smc2.run() plt.figure() plt.scatter(alg_smc2.X.theta['mu'], alg_smc2.X.theta['rho']) plt.xlabel('mu') plt.ylabel('rho') plt.show()