本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.setVertex方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.setVertex方法的具体用法?Python SparseGraph.setVertex怎么用?Python SparseGraph.setVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.setVertex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testConcat
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setVertex [as 别名]
def testConcat(self):
numVertices = 5
graph = SparseGraph(GeneralVertexList(numVertices))
graph.addEdge(1, 1, 0.1)
graph.addEdge(1, 3, 0.5)
graph.addEdge(2, 4, 1)
graph.addEdge(2, 3, 2)
graph.setVertex(0, "abc")
graph2 = SparseGraph(GeneralVertexList(numVertices))
graph2.addEdge(1, 1)
graph2.addEdge(1, 4)
graph2.setVertex(1, "def")
graph3 = graph.concat(graph2)
self.assertTrue(graph3.getNumVertices, 10)
self.assertEquals(graph3.getVertex(0), "abc")
self.assertEquals(graph3.getVertex(6), "def")
self.assertEquals(graph3.getEdge(1, 1), 0.1)
self.assertEquals(graph3.getEdge(1, 3), 0.5)
self.assertEquals(graph3.getEdge(2, 4), 1)
self.assertEquals(graph3.getEdge(2, 3), 2)
self.assertEquals(graph3.getEdge(6, 6), 1)
self.assertEquals(graph3.getEdge(6, 9), 1)
示例2: graphFromMatFile
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setVertex [as 别名]
def graphFromMatFile(matFileName):
"""
Generate a sparse graph from a Matlab file of ego and alters and their transmissions. This is a mostly
disconnected graph made up of pairs of connected vertices, i.e each vertex has degree 1.
"""
examplesList = ExamplesList.readFromMatFile(matFileName)
numExamples = examplesList.getNumExamples()
numFeatures = examplesList.getDataFieldSize("X", 1)
numVertexFeatures = numFeatures/2+1
vList = VertexList(numExamples*2, int(numVertexFeatures))
sGraph = SparseGraph(vList)
for i in range(0, examplesList.getNumExamples()):
v1Index = i*2
v2Index = i*2+1
example = examplesList.getSubDataField("X", numpy.array([i])).ravel()
vertex1 = numpy.r_[example[0:numFeatures/2], numpy.array([1])]
vertex2 = numpy.r_[example[numFeatures/2:numFeatures], numpy.array([0])]
sGraph.setVertex(v1Index, vertex1)
sGraph.setVertex(v2Index, vertex2)
sGraph.addEdge(v1Index, v2Index)
return sGraph
示例3: GeneralVertexList
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setVertex [as 别名]
# -*- coding: utf-8 -*-
import scipy.sparse as sps
from apgl.graph.GeneralVertexList import GeneralVertexList
from apgl.graph.SparseGraph import SparseGraph
numVertices = 10
vList = GeneralVertexList(numVertices)
Wght = sps.lil_matrix((numVertices, numVertices))
graph = SparseGraph(vList, W=Wght, undirected=False)
# Add some edges to the graph.
# Vertices are indexed starting from 0.
graph[0, 1] = 1
graph[0, 2] = 1
# Set the label of the 0th vertex to [2, 3].
graph.setVertex(0, "abc")
graph.setVertex(1, 123)
print(graph.inDegreeDistribution())
示例4: SparseGraph
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setVertex [as 别名]
#!/usr/bin/env python
import numpy as np
from apgl.graph.VertexList import VertexList
from apgl.graph.SparseGraph import SparseGraph
numVertices = 5
numFeatures = 2
graph = SparseGraph(VertexList(numVertices, numFeatures))
# Add some edges to the graph.
# Vertices are indexed starting from 0.
graph[0, 1] = 0.1
graph[1, 2] = 1.0
# Set the label of the 0th vertex to [2, 3].
graph.setVertex(0, np.array([2, 3]))
# Display edge weights.
print(graph[1, 2]) # 1.0
print(graph[1, 3]) # 0.0 (default)
# Add some edges to the graph.
edges = np.array([[0, 1], [1, 2]], np.int)
edgeValues = np.array([0.1, 1.0])
graph.addEdges(edges, edgeValues)
# Display the edge weight between v1 and v2.
print(graph[1, 2])