Beispiel #1
0
system.run(samples)
initalConfig, configChanges = system.run(samples)

system.toFile('main', initalConfig, configChanges)

obsList = system.fromFile("main_" + str(dimensionRoot) + '_' +
                          str(samples + 1) + ".npy")

X = np.zeros((dimensionRoot * dimensionRoot, samples))
for idx in range(samples):
    X[:, idx] = obsList.reshape(-1, dimensionRoot * dimensionRoot)[idx]

wantedDim = 3

pX, eigVec = pca.pca(X, 3, "cov", p=0.8, returnEigVec=True)

k = len(eigVec)
spinGrids = []

for i in range(k):
    spinGrids.append(eigVec[i].reshape((dimensionRoot, dimensionRoot)))

# define the grid over which the function should be plotted (xx and yy are matrices)

x = np.arange(0, dimensionRoot + 1, 1.)
xx, yy = np.meshgrid(x, x)

for i in range(k):
    # fill a matrix with the function values
    zz = spinGrids[i]
system.run(samples)
initalConfig, configChanges = system.run(samples)

system.toFile('main', initalConfig, configChanges)


obsList = system.fromFile("main_"+str(dimensionRoot)+'_'+str(samples+1)+".npy")

X = np.zeros((dimensionRoot * dimensionRoot, samples))
for idx in range(samples):
    X[:,idx] = obsList.reshape(-1, dimensionRoot * dimensionRoot)[idx]


wantedDim = 3

pX, eigVec = pca.pca(X, 3, "cov", p = 0.8, returnEigVec=True)

k = len(eigVec)
spinGrids = []

for i in range ( k ):
    spinGrids.append( eigVec[i].reshape( (dimensionRoot, dimensionRoot) ) )



# define the grid over which the function should be plotted (xx and yy are matrices)

x = np.arange(0, dimensionRoot + 1, 1.)
xx, yy = np.meshgrid(x,x)

for i in range( k ):
Beispiel #3
0
for idx in range(observations):
    X[:,idx] = obsList.reshape(-1, sqrtFeat * sqrtFeat)[idx]
    
print "Reshape Array:", time.time()-readTime

# Determine starting time
pcaStartTime = time.time()

# Given a MxN numpy-array with M features and N samples, this will return
# a numpy-array with k features and N samples, where every sample has been
# projected onto the first k features of greatest/largest variance.
if args.gpu: # Utilize gpu
    from pca import pcaGpu
    pX = pcaGpu.PCAGpu(X, args.k, args.m).pca()
elif args.plotEigVec:
    pX, eigVec = pca.pca(X, args.k, args.m, p=args.p, returnEigVec=True)
else:
    pX = pca.pca(X, args.k, args.m, p=args.p)

pcaTotalTime = time.time() - pcaStartTime
print "PCA ran:", pcaTotalTime

# Have a look
if args.plot3D:
    ax = plt.figure().add_subplot(111, projection="3d")
    c = cm.rainbow(np.linspace(0, 1, pX.shape[1]))
    ax.scatter(pX[0,:], pX[1,:], pX[2,:], ".", color=c)
    plt.draw()

if args.plotEigVec:
    k = len(eigVec)