Last active
August 29, 2015 14:12
-
-
Save dbamman/e7da85f8ee7d7b76061f to your computer and use it in GitHub Desktop.
PCA on random walk data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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