-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpca_plot.py
More file actions
47 lines (41 loc) · 1.58 KB
/
pca_plot.py
File metadata and controls
47 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy, matplotlib.pyplot, btfutil, cPickle
import pyqtgraph, pyqtgraph.opengl
app = pyqtgraph.Qt.QtGui.QApplication([])
# mw = pyqtgraph.Qt.QtGui.QMainWindow()
# view = pyqtgraph.GraphicsLayoutWidget()
# mw.setCentralWidget(view)
# mw.show()
# w1 = view.addPlot()
w = pyqtgraph.opengl.GLViewWidget()
w.resize(1800,900)
w.show()
print "Loading segments"
res = cPickle.load(open('../../fish_data/pickles/simsigma_0.15_pvel.p'))
print "Stacking data"
fnames = ['rbfsepvec', 'rbforivec','rbfcohvec', 'rbfwallvec','pvel']
feats_and_outs = map(lambda r: btfutil.btf2data(r,fnames,False),res)
all_data = numpy.row_stack([thing[0] for thing in feats_and_outs])
all_outs = numpy.row_stack([thing[1] for thing in feats_and_outs])
all_data_centered = all_data - all_data.mean(axis=0)
all_data_normalized = all_data_centered/all_data_centered.std(axis=0)
# all_data_normalized = numpy.random.rand(100,11)
print "Doing SVD"
u,s,v = numpy.linalg.svd(all_data_normalized,full_matrices=False)
#u,s,v = numpy.linalg.svd(all_data_centered,full_matrices=False)
b = v[:,:2]
down_cast = numpy.column_stack([all_data_normalized.dot(b),all_outs[:,0]])
#down_cast = all_data_centered.dot(b)
print "Plotting"
# 2D
# spi = pyqtgraph.ScatterPlotItem()
# 3D
spi = pyqtgraph.opengl.GLScatterPlotItem()
spi.setData(pos=down_cast,size=1,pxMode=True)
# w1.addItem(spi)
w.addItem(spi)
w.addItem(pyqtgraph.opengl.GLAxisItem())
# pyqtgraph.plot(x=down_cast[:,0],y=down_cast[:,1],symbol='o')
# matplotlib.pyplot.scatter(x=down_cast[:,0],y=down_cast[:,1])
# matplotlib.pyplot.show()
pyqtgraph.Qt.QtGui.QApplication.instance().exec_()
print "Done"