Skip to content

Instantly share code, notes, and snippets.

@breuderink
Created March 12, 2015 18:45
Show Gist options
  • Save breuderink/c91de35cdbeb7ed50eff to your computer and use it in GitHub Desktop.
Save breuderink/c91de35cdbeb7ed50eff to your computer and use it in GitHub Desktop.
Visualize simple state space model
import pylab as plt
import numpy as np
def gen(x, evolve, project, n=1000, sigma=.1):
y = []
for i in xrange(int(n)):
y.append(np.dot(project, x))
x = np.dot(evolve, x)
x = np.clip(x, -100, 100)
x += np.random.randn(*x.shape) * sigma
return np.asarray(y)
if __name__ == '__main__':
r = 2
E = np.eye(r) + .01 * (np.random.rand(r, r) - .5)
P = (np.eye(r) + .01 * np.random.randn(r, r))[:2]
print E, P, E.shape, P.shape
for i in range(50):
Y = gen(10 * np.random.randn(r), E, P, sigma=0.1, n=1e4)
plt.ion()
Y = Y[::20]
plt.plot(Y[:,0], Y[:,1], c='k')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment