本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.getVertexList方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.getVertexList方法的具体用法?Python SparseGraph.getVertexList怎么用?Python SparseGraph.getVertexList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.getVertexList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PermutationGraphKernelTest
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import getVertexList [as 别名]
class PermutationGraphKernelTest(unittest.TestCase):
def setUp(self):
self.tol = 10**-4
self.numVertices = 5
self.numFeatures = 2
vertexList1 = VertexList(self.numVertices, self.numFeatures)
vertexList1.setVertex(0, numpy.array([1, 1]))
vertexList1.setVertex(1, numpy.array([1, 2]))
vertexList1.setVertex(2, numpy.array([3, 2]))
vertexList1.setVertex(3, numpy.array([4, 2]))
vertexList1.setVertex(4, numpy.array([2, 6]))
vertexList2 = VertexList(self.numVertices, self.numFeatures)
vertexList2.setVertex(0, numpy.array([1, 3]))
vertexList2.setVertex(1, numpy.array([7, 2]))
vertexList2.setVertex(2, numpy.array([3, 22]))
vertexList2.setVertex(3, numpy.array([54, 2]))
vertexList2.setVertex(4, numpy.array([2, 34]))
self.sGraph1 = SparseGraph(vertexList1)
self.sGraph1.addEdge(0, 1)
self.sGraph1.addEdge(0, 2)
self.sGraph1.addEdge(1, 2)
self.sGraph1.addEdge(2, 3)
self.sGraph2 = SparseGraph(vertexList2)
self.sGraph2.addEdge(0, 1)
self.sGraph2.addEdge(0, 2)
self.sGraph2.addEdge(1, 2)
self.sGraph2.addEdge(2, 3)
self.sGraph2.addEdge(3, 4)
self.sGraph3 = SparseGraph(vertexList2)
self.sGraph3.addEdge(4, 1)
self.sGraph3.addEdge(4, 2)
self.sGraph3.addEdge(1, 2)
self.sGraph3.addEdge(1, 0)
def testEvaluate(self):
tau = 1.0
linearKernel = LinearKernel()
graphKernel = PermutationGraphKernel(tau, linearKernel)
"""
First tests - if the graphs have identical edges then permutation is identity matrix
provided that tau = 1.
"""
(evaluation, f, P, SW1, SW2, SK1, SK2) = graphKernel.evaluate(self.sGraph1, self.sGraph1, True)
self.assertTrue(numpy.linalg.norm(P - numpy.eye(self.numVertices)) <= self.tol)
S1, U = numpy.linalg.eigh(self.sGraph1.getWeightMatrix())
S2, U = numpy.linalg.eigh(self.sGraph2.getWeightMatrix())
evaluation2 = numpy.dot(S1, S1)
self.assertTrue(numpy.linalg.norm(SW1 - S1) <= self.tol)
self.assertTrue(numpy.linalg.norm(SW2 - S1) <= self.tol)
self.assertTrue(abs(evaluation - evaluation2) <= self.tol)
(evaluation, f, P, SW1, SW2, SK1, SK2) = graphKernel.evaluate(self.sGraph2, self.sGraph2, True)
self.assertTrue(numpy.linalg.norm(P - numpy.eye(self.numVertices)) <= self.tol)
evaluation2 = numpy.dot(S2, S2)
self.assertTrue(numpy.linalg.norm(SW1 - S2) <= self.tol)
self.assertTrue(numpy.linalg.norm(SW2 - S2) <= self.tol)
self.assertTrue(abs(evaluation - evaluation2) <= self.tol)
#Test symmetry
self.assertEquals(graphKernel.evaluate(self.sGraph1, self.sGraph2), graphKernel.evaluate(self.sGraph2, self.sGraph1))
#Now we choose tau != 1
tau = 0.5
graphKernel = PermutationGraphKernel(tau, linearKernel)
(evaluation, f, P, SW1, SW2, SK1, SK2) = graphKernel.evaluate(self.sGraph1, self.sGraph1, True)
self.assertTrue(numpy.linalg.norm(P - numpy.eye(self.numVertices)) <= self.tol)
self.assertTrue(graphKernel.evaluate(self.sGraph1, self.sGraph1) >= 0)
self.assertTrue(graphKernel.evaluate(self.sGraph2, self.sGraph2) >= 0)
self.assertTrue((graphKernel.evaluate(self.sGraph1, self.sGraph2)- graphKernel.evaluate(self.sGraph2, self.sGraph1)) <= self.tol)
(evaluation, f, P, SW1, SW2, SK1, SK2) = graphKernel.evaluate(self.sGraph1, self.sGraph2, True)
self.assertTrue(numpy.linalg.norm(numpy.dot(P.T, P) - numpy.eye(self.numVertices)) <= self.tol)
#Choose tau=0
tau = 0.0
graphKernel = PermutationGraphKernel(tau, linearKernel)
(evaluation, f, P, SW1, SW2, SK1, SK2) = graphKernel.evaluate(self.sGraph1, self.sGraph1, True)
self.assertTrue(numpy.linalg.norm(P - numpy.eye(self.numVertices)) <= self.tol)
self.assertTrue(numpy.linalg.norm(numpy.dot(P.T, P) - numpy.eye(self.numVertices)) <= self.tol)
X1 = self.sGraph1.getVertexList().getVertices(list(range(0, (self.sGraph1.getNumVertices()))))
X2 = self.sGraph2.getVertexList().getVertices(list(range(0, (self.sGraph2.getNumVertices()))))
#.........这里部分代码省略.........