def logG(self, t, xp, x): ESSmin = self.ESSrmin * x.N f = lambda e: rs.essl(e * x.llik) - ESSmin epn = x.exponents[-1] if f(1. - epn) > 0: # we're done (last iteration) delta = 1. - epn new_epn = 1. # put 1. manually so that we can safely test == 1. else: delta = optimize.brentq(f, 1.e-12, 1. - epn) # secant search # left endpoint is >0, since f(0.) = nan if any likelihood = -inf new_epn = epn + delta x.exponents.append(new_epn) return self.logG_tempering(x, delta)
sigmas = sigma0 + np.linspace(-.199, .2, 401) thetas = [[mu0, rho0, sig] for sig in sigmas] # range of T's Ts = [10, 100, 1000] colors = {10: 'lightgray', 100: 'gray', 1000: 'black'} plt.style.use('ggplot') plt.figure() for T in Ts: print('FFBS for T=%i' % T) alg = particles.SMC(fk=fkmod(theta0, T), N=100, store_history=True) alg.run() trajs = alg.hist.backward_sampling(M=100) ll0 = log_joint_density(theta0, trajs) ess_ls = [] for theta in thetas: ll = log_joint_density(theta, trajs) ess = rs.essl(ll - ll0) ess_ls.append(ess) plt.plot(sigmas, ess_ls, label='T=%i' % T, color=colors[T]) plt.xlabel('sigma') plt.ylabel('ESS') plt.legend(loc=2) savefigs = True # False if you don't want to save plots as pdfs if savefigs: plt.savefig('hurzeler_kunsch.pdf') plt.show()