예제 #1
0
 def testCentreArray(self):
     numExamples = 10 
     numFeatures = 3 
     
     preprocessor = Standardiser()
     
     #Test an everyday matrix 
     X = numpy.random.rand(numExamples, numFeatures)
     Xc = preprocessor.centreArray(X)
     centreV = preprocessor.getCentreVector()
     self.assertAlmostEquals(numpy.sum(Xc), 0, places=3)
     self.assertTrue((X-centreV == Xc).all())
     
     #Now take out 3 rows of X, normalise and compare to normalised X 
     Xs = X[0:3, :]
     Xsc = preprocessor.centreArray(Xs)
     self.assertTrue((Xsc == Xc[0:3, :]).all())
예제 #2
0
edgeTypeIndex1 = 0
edgeTypeIndex2 = 1
sGraphContact = graph.getSparseGraph(edgeTypeIndex1)
sGraphInfect = graph.getSparseGraph(edgeTypeIndex2)

numpy.set_printoptions(precision=3, suppress=True)

logging.info("Statistics over Verticies ")
logging.info("===============================")
#Other measures :  infection period of tree, infection types
#PCA to find variance of data, correlation matrix, center matrix
X = graph.getVertexList().copy().getVertices(list(range(0, graph.getNumVertices())))

standardiser = Standardiser()
X = standardiser.standardiseArray(X)
centerArray = standardiser.getCentreVector()

C = numpy.dot(X.T, X)

print((Latex.array2DToRows(numpy.reshape(centerArray, (5, 8)))))

C2 = numpy.abs(C - numpy.eye(X.shape[1]))
C2[numpy.tril_indices(C.shape[0])] = 0

inds = numpy.flipud(numpy.argsort(C2, None))
numEls = 10

for i in range(numEls):
    corr = "%.3f" % C[numpy.unravel_index(inds[i], C2.shape)]
    print((str(numpy.unravel_index(inds[i], C2.shape)) + " & " + corr + "\\\\"))