当前位置: 首页>>代码示例>>Python>>正文


Python SparseGraph.setVertex方法代码示例

本文整理汇总了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)
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:28,代码来源:SparseGraphTest.py

示例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 
开发者ID:charanpald,项目名称:wallhack,代码行数:26,代码来源:EgoUtils.py

示例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())
开发者ID:,项目名称:,代码行数:23,代码来源:

示例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])
开发者ID:showa-yojyo,项目名称:notebook,代码行数:29,代码来源:graphbasic.py


注:本文中的apgl.graph.SparseGraph.SparseGraph.setVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。