Skip to content

Instantly share code, notes, and snippets.

@dbamman
Last active August 29, 2015 14:12
Show Gist options
  • Save dbamman/e7da85f8ee7d7b76061f to your computer and use it in GitHub Desktop.
Save dbamman/e7da85f8ee7d7b76061f to your computer and use it in GitHub Desktop.
PCA on random walk data
# generate 100-dimensional random walk data so that each data point in a sequence is similar to the last data point
import numpy as np
last=np.random.normal(0, .1, 100)
for i in range(1000):
new=last+np.random.normal(0, .1, 100)
last=new
print ' '.join(str(x) for x in new)
# run PCA and plot 2D in R
library(stats)
A=read.table("data.gen", sep=" ")
res=princomp(A)
reduce=predict(res,A)
plot(reduce[,1], reduce[,2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment