本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.normalisedLaplacianSym方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.normalisedLaplacianSym方法的具体用法?Python SparseGraph.normalisedLaplacianSym怎么用?Python SparseGraph.normalisedLaplacianSym使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.normalisedLaplacianSym方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNormalisedLaplacianSym
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import normalisedLaplacianSym [as 别名]
def testNormalisedLaplacianSym(self):
numVertices = 10
numFeatures = 0
vList = VertexList(numVertices, numFeatures)
graph = SparseGraph(vList)
ell = 2
m = 2
generator = BarabasiAlbertGenerator(ell, m)
graph = generator.generate(graph)
k = 10
W = graph.getSparseWeightMatrix()
L = GraphUtils.shiftLaplacian(W)
L2 = graph.normalisedLaplacianSym()
tol = 10**-6
self.assertTrue(numpy.linalg.norm(L + L2 - 2*numpy.eye(numVertices)) < tol)
#Test zero rows/cols
W = scipy.sparse.csr_matrix((5, 5))
W[1, 0] = 1
W[0, 1] = 1
L = GraphUtils.normalisedLaplacianSym(W)
for i in range(2, 5):
self.assertEquals(L[i, i], 0)
示例2: testShiftLaplacian
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import normalisedLaplacianSym [as 别名]
def testShiftLaplacian(self):
numVertices = 10
numFeatures = 0
vList = VertexList(numVertices, numFeatures)
graph = SparseGraph(vList)
ell = 2
m = 2
generator = BarabasiAlbertGenerator(ell, m)
graph = generator.generate(graph)
k = 10
W = graph.getSparseWeightMatrix()
L = GraphUtils.shiftLaplacian(W)
L2 = 2*numpy.eye(numVertices) - graph.normalisedLaplacianSym()
tol = 10**-6
self.assertTrue(numpy.linalg.norm(L - L2) < tol)
示例3: SparseGraph
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import normalisedLaplacianSym [as 别名]
cluster1 = numpy.array([[0,1], [0,2], [1,3], [2,3], [3,4], [4,5]])
graph1.addEdges(cluster1)
cluster2 = numpy.array([[5,7], [5,8], [7,9], [8,9], [6,7]])
graph1.addEdges(cluster2)
cluster3 = numpy.array([[6,10], [10,11], [10,12], [11,12], [11,13], [12,14]])
graph1.addEdges(cluster3)
graph2 = SparseGraph(GeneralVertexList(numVertices))
cluster1 = numpy.array([[0,1], [0,2], [1,3], [2,3], [3,4], [0,3],[4,5]])
graph2.addEdges(cluster1)
cluster2 = numpy.array([[5,7], [5,8], [7,9], [8,9], [6,7]])
graph2.addEdges(cluster2)
cluster3 = numpy.array([[6,10], [10,11], [10,12], [11,12], [11,13], [12,14]])
graph2.addEdges(cluster3)
L1 = graph1.normalisedLaplacianSym()
L2 = graph2.normalisedLaplacianSym()
l1, U = numpy.linalg.eig(L1)
inds = numpy.argsort(l1)[0:k]
U = U[:, inds]
U = Standardiser().normaliseArray(U.T).T
l2, V = numpy.linalg.eig(L2)
inds = numpy.argsort(l2)[0:k]
V = V[:, inds]
V = Standardiser().normaliseArray(V.T).T
kmeans = KMeans(k)
kmeans.fit(U)
C = FeatureGenerator().categoricalToIndicator(numpy.array([kmeans.labels_]).T, numpy.array([0]))
示例4: ErdosRenyiGenerator
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import normalisedLaplacianSym [as 别名]
from apgl.graph.SparseGraph import SparseGraph
from apgl.graph.GeneralVertexList import GeneralVertexList
numpy.set_printoptions(suppress=True, precision=4, linewidth=100)
numpy.random.seed(21)
p = 0.001
numVertices = 10000
generator = ErdosRenyiGenerator(p)
graph = SparseGraph(GeneralVertexList(numVertices))
graph = generator.generate(graph)
print("Num vertices = " + str(graph.getNumVertices()))
print("Num edges = " + str(graph.getNumEdges()))
L = graph.normalisedLaplacianSym(sparse=True)
# L = csr_matrix(L)
print("Created Laplacian")
# ml = smoothed_aggregation_solver(L)
# M = ml.aspreconditioner()
start = time.clock()
w, V = scipy.sparse.linalg.eigsh(L, k=20)
totalTime = time.clock() - start
print(totalTime)
# print(w)
# Eigsh is quite fast