""" from __future__ import division, print_function from collections import OrderedDict from matplotlib import pyplot as plt import numpy as np import seaborn as sb import particles from particles import kalman from particles import state_space_models as ssms # Define ssm, simulate data T = 100 my_ssm = kalman.LinearGauss(sigmaX=1., sigmaY=.2, rho=.9) true_states, data = my_ssm.simulate(T) # FK models models = OrderedDict() models['bootstrap'] = ssms.Bootstrap(ssm=my_ssm, data=data) models['guided'] = ssms.GuidedPF(ssm=my_ssm, data=data) models['APF'] = ssms.AuxiliaryPF(ssm=my_ssm, data=data) # Uncomment line below if you want to include the "Boostrap APF" # (APF with proposal set to dist. of X_t|X_{t-1}) in the comparison #models['bootAPF'] = ssm.AuxiliaryBootstrap(ssm=my_ssm, data=data) # Compute "truth" kf = kalman.Kalman(ssm=my_ssm, data=data) kf.filter() true_loglik = np.cumsum(kf.logpyt)
from matplotlib import pyplot as plt import numpy as np import particles from particles import kalman from particles import state_space_models # parameter values sigmaX = 1. sigmaY = .2 rho = 0.9 T = 1000 N = 200 # define ss model, simulate data ssm = kalman.LinearGauss(sigmaX=sigmaX, sigmaY=sigmaY, rho=rho) true_states, data = ssm.simulate(T) # computes true log-likelihood kf = kalman.Kalman(ssm=ssm, data=data) kf.filter() true_loglik = np.sum(kf.logpyt) # FK model fk_model = state_space_models.GuidedPF(ssm=ssm, data=data) # Run SMC algorithm for different values of ESS_min alphas = list(np.linspace(0., .1, 11)) + list(np.linspace(0.15, 1., 18)) results = particles.multiSMC(fk=fk_model, N=N, ESSrmin=alphas,
from particles import kalman # Multivariate model T = 15 dx, dy = 3, 2 F = np.eye(dx) + 0.01 * random.randn(dx, dx) G = np.eye(dy, dx) + 0.02 * random.randn(dy, dx) covX = np.eye(dx) + 0.2 * np.ones((dx, dx)) covY = 0.3 * np.eye(dy) mu0 = np.ones(dx) cov0 = 2. * covX mv_ssm = kalman.MVLinearGauss(F=F, G=G, covX=covX, covY=covY, cov0=cov0, mu0=mu0) # Univariate model rho, sigX, sigY, sig0 = 0.9, 1., 0.2, 3. uni_ssm = kalman.LinearGauss(rho=rho, sigmaX=sigX, sigmaY=sigY, sigma0=sig0) univariate = False # test univariate or multivariate model? if univariate: ssm = uni_ssm F, G, mu0 = rho, 1., 0. covX, covY, cov0 = sigX**2, sigY**2, sig0**2 else: ssm = mv_ssm # data x, y = ssm.simulate(T) # Our Kalman filter mykf = kalman.Kalman(ssm=ssm, data=y) mykf.smoother() # this does both filtering and smoothing