本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.getVertex方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.getVertex方法的具体用法?Python SparseGraph.getVertex怎么用?Python SparseGraph.getVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.getVertex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testAdvanceGraph2
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import getVertex [as 别名]
def testAdvanceGraph2(self):
#Create a simple graph and deterministic classifier
numExamples = 10
numFeatures = 3
#Here, the first element is gender (say) with female = 0, male = 1
vList = VertexList(numExamples, numFeatures)
vList.setVertex(0, numpy.array([0,0,1]))
vList.setVertex(1, numpy.array([1,0,0]))
vList.setVertex(2, numpy.array([1,0,0]))
vList.setVertex(3, numpy.array([1,0,0]))
vList.setVertex(4, numpy.array([0,0,1]))
vList.setVertex(5, numpy.array([0,0,1]))
vList.setVertex(6, numpy.array([0,0,0]))
vList.setVertex(7, numpy.array([1,0,0]))
vList.setVertex(8, numpy.array([0,0,1]))
vList.setVertex(9, numpy.array([1,0,0]))
sGraph = SparseGraph(vList)
sGraph.addEdge(0, 1, 1)
sGraph.addEdge(0, 2, 1)
sGraph.addEdge(0, 3, 1)
sGraph.addEdge(4, 5, 1)
sGraph.addEdge(4, 6, 1)
sGraph.addEdge(6, 7, 1)
sGraph.addEdge(6, 8, 1)
sGraph.addEdge(6, 9, 1)
simulator = EgoSimulator(sGraph, self.dc)
simulator.advanceGraph()
self.assertEquals(simulator.getNumIterations(), 1)
self.assertEquals(sGraph.getVertex(0)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(1)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(2)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(3)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(4)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(5)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(6)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(7)[numFeatures-1], 0)
self.assertEquals(sGraph.getVertex(8)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(9)[numFeatures-1], 0)
#Advance again and all egos have information
simulator.advanceGraph()
self.assertEquals(simulator.getNumIterations(), 2)
self.assertEquals(sGraph.getVertex(0)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(1)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(2)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(3)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(4)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(5)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(6)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(7)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(8)[numFeatures-1], 1)
self.assertEquals(sGraph.getVertex(9)[numFeatures-1], 1)
#Should be no change
simulator.advanceGraph()
self.assertEquals(simulator.getNumIterations(), 3)
#Check the correct alters are added at each step
self.assertTrue((simulator.getAlters(0) == numpy.array([1,2,3,6])).all())
self.assertTrue((simulator.getAlters(1) == numpy.array([7,9])).all())
self.assertTrue((simulator.getAlters(2) == numpy.array([])).all())
#Check that the transmission graph is okay
transGraph = simulator.getTransmissionGraph()
self.assertEquals(transGraph.getNumVertices(), 9)
self.assertEquals(transGraph.getNumEdges(), 7)
self.assertEquals(transGraph.getAllVertexIds(), [0, 1, 2, 3, 4, 6, 7, 8, 9])
for i in transGraph.getAllVertexIds():
self.assertTrue((transGraph.getVertex(i) == sGraph.getVertex(i)).all())