本文整理汇总了Python中apgl.graph.DictGraph.DictGraph类的典型用法代码示例。如果您正苦于以下问题:Python DictGraph类的具体用法?Python DictGraph怎么用?Python DictGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DictGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSetItem
def testSetItem(self):
graph = DictGraph()
graph.addEdge(1, 1, 0.1)
graph.addEdge(1, 3, 0.5)
self.assertEquals(graph[1,3], 0.5)
graph[1, 3] = 2
self.assertEquals(graph[1,3], 2)
示例2: testDegreeSequence
def testDegreeSequence(self):
graph = DictGraph()
graph.setVertex("a", 10)
graph["b", "c"] = 1
graph["b", "d"] = 1
graph["d", "e"] = 1
graph["e", "e"] = 1
nptst.assert_array_equal(graph.degreeSequence(), [0, 1, 2, 3, 2])
示例3: setUp
def setUp(self):
#Let's set up a very simple graph
numVertices = 5
numFeatures = 1
edges = []
vList = VertexList(numVertices, numFeatures)
#An undirected dense graph
self.dGraph1 = DenseGraph(vList, True)
self.dGraph1.addEdge(0, 1, 1)
self.dGraph1.addEdge(0, 2, 1)
self.dGraph1.addEdge(2, 4, 1)
self.dGraph1.addEdge(2, 3, 1)
self.dGraph1.addEdge(3, 4, 1)
#A directed sparse graph
self.dGraph2 = DenseGraph(vList, False)
self.dGraph2.addEdge(0, 1, 1)
self.dGraph2.addEdge(0, 2, 1)
self.dGraph2.addEdge(2, 4, 1)
self.dGraph2.addEdge(2, 3, 1)
self.dGraph2.addEdge(3, 4, 1)
#Now try sparse graphs
vList = VertexList(numVertices, numFeatures)
self.sGraph1 = SparseGraph(vList, True)
self.sGraph1.addEdge(0, 1, 1)
self.sGraph1.addEdge(0, 2, 1)
self.sGraph1.addEdge(2, 4, 1)
self.sGraph1.addEdge(2, 3, 1)
self.sGraph1.addEdge(3, 4, 1)
self.sGraph2 = SparseGraph(vList, False)
self.sGraph2.addEdge(0, 1, 1)
self.sGraph2.addEdge(0, 2, 1)
self.sGraph2.addEdge(2, 4, 1)
self.sGraph2.addEdge(2, 3, 1)
self.sGraph2.addEdge(3, 4, 1)
#Finally, try DictGraphs
self.dctGraph1 = DictGraph(True)
self.dctGraph1.addEdge(0, 1, 1)
self.dctGraph1.addEdge(0, 2, 2)
self.dctGraph1.addEdge(2, 4, 8)
self.dctGraph1.addEdge(2, 3, 1)
self.dctGraph1.addEdge(12, 4, 1)
self.dctGraph2 = DictGraph(False)
self.dctGraph2.addEdge(0, 1, 1)
self.dctGraph2.addEdge(0, 2, 1)
self.dctGraph2.addEdge(2, 4, 1)
self.dctGraph2.addEdge(2, 3, 1)
self.dctGraph2.addEdge(12, 4, 1)
示例4: toDictGraph
def toDictGraph(self):
"""
Convert to a DictGraph object. Currently ignores vertex labels.
:return graph: A DictGraph object.
"""
edges = self.getAllEdges()
values = self.getEdgeValues(edges)
graph = DictGraph(self.undirected)
graph.addEdges(edges, values)
return graph
示例5: testSetVertices
def testSetVertices(self):
graph = DictGraph()
vertexIndices = [1, 2, 3]
vertices = ["a", "b", "c"]
graph.setVertices(vertexIndices, vertices)
vertexIndices2 = graph.getAllVertexIds()
vertices2 = graph.getVertices(vertexIndices2)
self.assertEquals(vertexIndices, vertexIndices2)
self.assertEquals(vertices, vertices2)
示例6: testDepthFirstSearch
def testDepthFirstSearch(self):
graph = DictGraph()
graph.addEdge(0, 1)
graph.addEdge(1, 2)
graph.addEdge(1, 3)
graph.addEdge(2, 6)
graph.addEdge(4, 5)
self.assertEquals(graph.depthFirstSearch(0), [0,1,2,6,3])
self.assertEquals(graph.depthFirstSearch(1), [1,0,2,6,3])
self.assertEquals(graph.depthFirstSearch(6), [6,2,1,0,3])
self.assertEquals(graph.depthFirstSearch(4), [4, 5])
self.assertEquals(graph.depthFirstSearch(5), [5, 4])
示例7: testVertexExists
def testVertexExists(self):
graph = DictGraph(False)
graph.addEdge(0, 1)
graph.addEdge(0, 2)
graph.addEdge(0, 3)
graph.addEdge(1, 2)
graph.addEdge(2, 3)
self.assertTrue(graph.vertexExists(0))
self.assertTrue(graph.vertexExists(1))
self.assertTrue(graph.vertexExists(2))
self.assertTrue(graph.vertexExists(3))
self.assertFalse(graph.vertexExists(4))
示例8: testDegreeSequence
def testDegreeSequence(self):
graph = DictGraph()
graph.setVertex("a", 10)
graph["b", "c"] = 1
graph["b", "d"] = 1
graph["d", "e"] = 1
graph["e", "e"] = 1
degreeDict = {}
degreeDict2 = {"a": 0, "b": 2, "c": 1, "d": 2, "e": 3}
for i, id in enumerate(graph.getAllVertexIds()):
degreeDict[id] = graph.degreeSequence()[i]
self.assertEquals(degreeDict, degreeDict2)
示例9: testWriteToFile
def testWriteToFile(self):
graph = DictGraph()
numVertices = 5
numFeatures = 3
V = numpy.random.rand(numVertices, numFeatures)
for i in range(0, numVertices):
graph.setVertex(i, V[i, :])
fileName = PathDefaults.getOutputDir() + "test/vertices"
verterWriter = CsvVertexWriter()
verterWriter.writeToFile(fileName, graph)
logging.debug(V)
示例10: __init__
def __init__(self, purchasesByWeek, nb_purchases_per_it=None):
"""
The background graph is a bi-partite graph of purchases. Purchases are
grouped by date (week by week), and we consider the graph of purchases
between first week and $i$-th week.
The returned graph considers only users and counts the number of common
purchases between two users.
Purchases are given in a list of [user, prod, week, year] with increasing
date.
nb_purchases_per_it is the maximum number of purchases to put in each
week (if there is more, randomly split the week). None corresponds to
no-limit case.
"""
# args
self.group_by_iterator = DatedPurchasesGroupByIterator(purchasesByWeek, nb_purchases_per_it)
# init variables
self.dictUser = MyDictionary()
self.dictProd = MyDictionary()
for user, prod, week, year in purchasesByWeek:
self.dictUser.index(user)
self.dictProd.index(prod)
self.backgroundGraph = DictGraph(False) # directed
self.W = scipy.sparse.csr_matrix((len(self.dictUser), len(self.dictUser)), dtype='int16')
self.usefullEdges = numpy.array([])
示例11: testAdjacencyList
def testAdjacencyList(self):
graph = DictGraph()
graph.addEdge("a", "b", 1)
graph.addEdge("b", "c", 1)
graph.addEdge("b", "d", 1)
graph.addEdge("c", "e", 1)
graph.setVertex("f", 1)
neighbourIndices, neighbourWeights = graph.adjacencyList()
vertexIds = graph.getAllVertexIds()
for i in range(len(neighbourIndices)):
for k, j in enumerate(neighbourIndices[i]):
self.assertTrue(graph.edgeExists(vertexIds[i], vertexIds[j]))
self.assertEquals(graph[vertexIds[i], vertexIds[j]], neighbourWeights[i][k])
示例12: testToIGraph
def testToIGraph(self):
try:
import igraph
except ImportError as error:
logging.debug(error)
return
graph = DictGraph()
graph["a", "b"] = 1
graph["b", "c"] = 2
ig = graph.toIGraph()
self.assertEquals(len(ig.vs), 3)
self.assertEquals(ig[0, 2], 1)
self.assertEquals(ig[1, 2], 1)
示例13: testGetEdge
def testGetEdge(self):
dictGraph = DictGraph(True)
dictGraph.addEdge(1, 2, 12)
self.assertEquals(dictGraph.getEdge(1, 2), 12)
self.assertEquals(dictGraph.getEdge(2, 1), 12)
self.assertEquals(dictGraph.getEdge(2, 2), None)
self.assertRaises(ValueError, dictGraph.getEdge, 5, 8)
dictGraph = DictGraph(False)
dictGraph.addEdge(1, 2, 12)
self.assertEquals(dictGraph.getEdge(1, 2), 12)
self.assertEquals(dictGraph.getEdge(2, 1), None)
示例14: setUp
def setUp(self):
self.graph = DictGraph()
self.graph.addEdge(0, 1, 1)
self.graph.addEdge(1, 3, 1)
self.graph.addEdge(0, 2, 2)
self.graph.addEdge(2, 3, 5)
self.graph.addEdge(0, 4, 1)
self.graph.addEdge(3, 4, 1)
self.graph.setVertex(5, None)
self.graph2 = DictGraph(False)
self.graph2.addEdge(0, 1, 1)
self.graph2.addEdge(1, 3, 1)
self.graph2.addEdge(0, 2, 2)
self.graph2.addEdge(2, 3, 5)
self.graph2.addEdge(0, 4, 1)
self.graph2.addEdge(3, 4, 1)
self.graph2.setVertex(5, 1)
示例15: __init__
def __init__(self, graph, egoPairClassifier, preprocessor=None):
self.graph = graph
self.egoPairClassifier = egoPairClassifier
self.preprocessor = preprocessor
self.iteration = 0
self.allTransmissionEdges = []
self.transmissionGraph = DictGraph(False)
self.numVertexFeatures = self.graph.getVertexList().getNumFeatures()
self.numPersonFeatures = self.numVertexFeatures-1
self.infoIndex = self.numVertexFeatures-1
self.edges = self.graph.getAllEdges()