# Kalman filter
t0 = timer()
flt, prd, lhood = model.kalman_filter(observ)
filter_time = timer()-t0
print("Filtering took {}s.".format(filter_time))

# Kalman smoother
t0 = timer()
smt = model.rts_smoother(flt, prd)
smoother_time = timer()-t0
print("Smoothing took {}s.".format(smoother_time))

fig = plt.figure()
for dd in range(ds):
    ax = fig.add_subplot(ds,1,dd+1)
    ax.plot(flt.mn[:,dd], 'g-')
    ax.plot(flt.mn[:,dd]+2*np.sqrt(flt.vr[:,dd,dd]), 'g:')
    ax.plot(flt.mn[:,dd]-2*np.sqrt(flt.vr[:,dd,dd]), 'g:')

fig = plt.figure()
for dd in range(ds):
    ax = fig.add_subplot(ds,1,dd+1)
    ax.plot(smt.mn[:,dd], 'g-')
    ax.plot(smt.mn[:,dd]+2*np.sqrt(smt.vr[:,dd,dd]), 'g:')
    ax.plot(smt.mn[:,dd]-2*np.sqrt(smt.vr[:,dd,dd]), 'g:')

np.random.seed(0)
state, observ = model.simulate_data(K)
smp = model.sample_posterior(observ)