Lets say I have some time series data which I generated like this:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from numpy.random import uniform

# Length of time series

# Gaussian random numbers as an excitation signal
ex = np.random.randn(N)

# Second order AR Process with coefficients slowly changing in time
a0 = np.array([1.2, -0.4])
A = np.zeros((N,2))
omega, alpha = N/2, 0.1

for n in range(N):
    A[n,0] = a0[0] + alpha * np.cos(2*np.pi*n/N)
    A[n,1] = a0[1] + alpha * np.sin(np.pi*n/N)

S = ex.copy()
for n in range(2,N):
    x = np.array([S[n-1], S[n-2]])
    S[n] = np.dot(x, A[n,:]) + ex[n]

fig,ax = plt.subplots(nrows=2, ncols=2, figsize=(9,4))
ax[1,0].plot(range(N), A[:,0])
ax[1,0].set_title("Coefficient a0", color='m')
ax[1,1].plot(range(N), A[:,1], color='m')
ax[1,1].set_title("Coefficient a1", color='m')
ax[0,0].plot(range(N), ex)
ax[0,0].set_title("Random Excitation Signal")
ax[0,1].plot(range(N), S, color='m')
ax[0,1].set_title("Time Varying Autoregressive Process")

How do I implement a Sequential Importance Sampling Particle Filter on this data? I understand all the theory and the maths behind it and even saw some examples of implementation on different problems but none of them work with similar data. For example, https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/blob/master/12-Particle-Filters.ipynb deals with robot movements and landmarks and I just want to apply the algorithm to a simple time series data...Can anyone help me with the implementation? I'm especially confused as to how to do the sampling part...


1 Answer 1


Particle filter is a Bayesian filter. Any Bayesian filter requires process and measurement models so you also need to define them.

If you will use bootstrap particle filter, you just create initial samples with initial parameters from Gaussian distribution. Then, you propagate the particles using process model. This is your so called "prediction" step.

After obtaining your measurements for each time step, you calculate the weights. Using those weights you perform resampling.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.