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


Python SparseGraph.removeAllEdges方法代码示例

本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.removeAllEdges方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.removeAllEdges方法的具体用法?Python SparseGraph.removeAllEdges怎么用?Python SparseGraph.removeAllEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apgl.graph.SparseGraph.SparseGraph的用法示例。


在下文中一共展示了SparseGraph.removeAllEdges方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testWriteToFile3

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
    def testWriteToFile3(self):
        """
        We will test out writing out some random graphs to Pajek
        """
        numVertices = 20
        numFeatures = 0 
        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        p = 0.1
        generator = ErdosRenyiGenerator(p)
        graph = generator.generate(graph)

        pw = PajekWriter()
        directory = PathDefaults.getOutputDir() + "test/"
        pw.writeToFile(directory + "erdosRenyi20", graph)

        #Now write a small world graph
        p = 0.2
        k = 3

        graph.removeAllEdges()
        generator = SmallWorldGenerator(p, k)
        graph = generator.generate(graph)

        pw.writeToFile(directory + "smallWorld20", graph)
开发者ID:charanpald,项目名称:APGL,代码行数:28,代码来源:PajekWriterTest.py

示例2: testGenerate

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
    def testGenerate(self):
        numFeatures = 1
        numVertices = 20

        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        ell = 2
        m = 0
        generator = BarabasiAlbertGenerator(ell, m)

        graph = generator.generate(graph)
        self.assertEquals(graph.getNumEdges(), 0)

        ell = 5
        graph.removeAllEdges()
        generator.setEll(ell)
        graph = generator.generate(graph)
        self.assertEquals(graph.getNumEdges(), 0)

        #Now test case where we m != 0
        ell = 2
        m = 1
        graph.removeAllEdges()
        generator.setEll(ell)
        generator.setM(m)
        graph = generator.generate(graph)
        self.assertEquals(graph.getNumEdges(), (numVertices-ell)*m)

        m = 2
        graph.removeAllEdges()
        generator.setM(m)
        graph = generator.generate(graph)
        self.assertEquals(graph.getNumEdges(), (numVertices-ell)*m)
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:36,代码来源:BarabasiAlbertGeneratorTest.py

示例3: testLearnModel

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
    def testLearnModel(self):
        numVertices = 100
        numFeatures = 1

        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        p = 0.2
        generator = ErdosRenyiGenerator(p)
        graph = generator.generate(graph)

        vertexIndices = list(range(0, numVertices))

        k = 2
        learner = GrowthLearner(k)

        tol = 10**-1

        #Lets test the values of alpha on a series of Erdos-Renyi graphs 
        for i in range(1, 6):
            p = float(i)/10
            graph.removeAllEdges()
            graph = generator.generate(graph)

            alpha = learner.learnModel(graph, vertexIndices)
            logging.debug((numpy.linalg.norm(alpha - numpy.array([p, 0]))))
            #self.assertTrue(numpy.linalg.norm(alpha - numpy.array([p, 0])) < tol)


        #Now test the learning on some preferencial attachment graphs
        ell = 10
        m = 8

        vertexIndices = list(range(ell, numVertices))
        graph.removeAllEdges()
        generator = BarabasiAlbertGenerator(ell, m)
        graph = generator.generate(graph)

        alpha = learner.learnModel(graph, vertexIndices)
        logging.debug(alpha)
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:42,代码来源:GrowthLearnerTest.py

示例4: testGenerateGraph

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
    def testGenerateGraph(self):
        numFeatures = 0
        numVertices = 20

        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        alpha1 = 10.0
        alpha2 = 20.0
        p = 0.001
        dim = 2
        generator = GeometricRandomGenerator(graph)

        graph = generator.generateGraph(alpha1, p, dim)
        numEdges1 = graph.getNumEdges()

        #Check no self edges
        for i in range(numVertices):
            self.assertTrue(graph.getEdge(i, i) == None)

        graph.removeAllEdges()
        graph = generator.generateGraph(alpha2, p, dim)
        numEdges2 = graph.getNumEdges()

        #self.assertTrue(numEdges1 >= numEdges2)
        logging.debug(numEdges1)
        logging.debug(numEdges2)

        for i in range(numVertices):
            self.assertTrue(graph.getEdge(i, i) == None)

        #Test case with p=0 and alpha huge 
        p = 0.0
        alpha = 100.0
        graph.removeAllEdges()
        graph = generator.generateGraph(alpha, p, dim)

        self.assertEquals(graph.getNumEdges(),  0)

        #When alpha=0, should get max edges
        alpha = 0.0
        graph.removeAllEdges()
        graph = generator.generateGraph(alpha, p, dim)

        #self.assertEquals(graph.getNumEdges(), int(0.5*(numVertices + numVertices**2) - numVertices))

        #TODO: Test variations in dimension 

        """
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:51,代码来源:GeometricRandomGeneratorTest.py

示例5: ErdoRenyiGeneratorTest

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
class ErdoRenyiGeneratorTest(unittest.TestCase):
    def setUp(self):    
        numpy.set_printoptions(suppress=True, linewidth=200, precision=5)
        self.numVertices = 10; 
        self.numFeatures = 2; 
        
        self.vList = VertexList(self.numVertices, self.numFeatures)
        self.graph = SparseGraph(self.vList)
        self.p = 0.1 
        self.erg = ErdosRenyiGenerator(self.p)

        
    def testGenerate(self):
        #undirected = True 
        p = 0.0
             
        self.graph.removeAllEdges()
        self.erg.setP(p)
        graph = self.erg.generate(self.graph)
        self.assertEquals(graph.getNumEdges(), 0)
        
        undirected = False
        self.graph = SparseGraph(self.vList, undirected)
        self.graph.removeAllEdges()
        self.erg = ErdosRenyiGenerator(p)
        graph = self.erg.generate(self.graph)
        self.assertEquals(graph.getNumEdges(), 0)
        
        p = 1.0
        undirected = True
        self.graph = SparseGraph(self.vList, undirected)
        self.graph.removeAllEdges()
        self.erg = ErdosRenyiGenerator(p)
        graph = self.erg.generate(self.graph)
        self.assertEquals(graph.getNumEdges(), (self.numVertices*self.numVertices-self.numVertices)/2)
        
        p = 1.0
        undirected = False
        self.graph = SparseGraph(self.vList, undirected)
        self.graph.removeAllEdges()
        self.erg = ErdosRenyiGenerator(p)
        graph = self.erg.generate(self.graph)
        self.assertEquals(graph.getNumEdges(), self.numVertices*self.numVertices-self.numVertices)
        
        self.assertEquals(graph.getEdge(1, 2), 1)
        self.assertEquals(graph.getEdge(1, 1), None)

        p = 0.5
        numVertices = 1000
        numFeatures = 0

        vList = VertexList(numVertices, numFeatures)
        undirected = False
        self.graph = SparseGraph(vList, undirected)
        self.erg = ErdosRenyiGenerator(p)
        graph = self.erg.generate(self.graph)

        self.assertAlmostEquals(graph.getNumEdges()/float(numVertices**2 - numVertices), p, places=2)

        p = 0.1
        self.graph = SparseGraph(vList, undirected)
        self.erg = ErdosRenyiGenerator(p)
        graph = self.erg.generate(self.graph)

        self.assertAlmostEquals(graph.getNumEdges()/float(numVertices**2 - numVertices), p, places=2)

        #Test the case in which we have a graph with edges
        p = 0.5
        numVertices = 10 
        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList, undirected)
        graph.addEdge(0, 1, 5)
        graph.addEdge(0, 2)
        graph.addEdge(0, 5, 0.7)
        graph.addEdge(1, 8)
        graph.addEdge(2, 9)
        numEdges = graph.getNumEdges()

        graph = self.erg.generate(graph, False)
        self.assertTrue(graph.getNumEdges() > numEdges)


    @apgl.skip("")
    def testGraphDisplay(self):
        try:
            import networkx
            import matplotlib
        except ImportError as error:
            logging.debug(error)
            return 

        #Show
        numFeatures = 1
        numVertices = 20

        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        p = 0.2
        generator = ErdosRenyiGenerator(p)
#.........这里部分代码省略.........
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:103,代码来源:ErdoRenyiGeneratorTest.py

示例6: testGenerate

# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import removeAllEdges [as 别名]
    def testGenerate(self):
        degSequence = numpy.array([2, 1, 3, 0, 0, 0, 0, 0, 0, 1])
        generator = ConfigModelGenerator(degSequence)

        numVertices = 10
        graph = SparseGraph(GeneralVertexList(numVertices))
        graph = generator.generate(graph)

        tol = 3
        self.assertTrue(numpy.linalg.norm(degSequence - graph.degreeSequence()) < tol)

        degSequence = numpy.array([2, 1, 3, 0, 2, 1, 4, 0, 0, 1])
        generator.setOutDegSequence(degSequence)
        graph.removeAllEdges()
        graph = generator.generate(graph)

        self.assertTrue(numpy.linalg.norm(degSequence - graph.degreeSequence()) < tol)

        #Test using a non-empty graph
        degSequence = numpy.array([0, 0, 0, 2, 0, 0, 0, 1, 1, 0])
        generator.setOutDegSequence(degSequence)
        oldDegSequence = graph.degreeSequence()

        self.assertRaises(ValueError, generator.generate, graph, True)
        graph = generator.generate(graph, False)

        diffSequence = graph.degreeSequence() - oldDegSequence
        self.assertTrue(numpy.linalg.norm(degSequence - diffSequence) < tol)

        #Test the case where we also have an in-degree sequence
        degSequence = numpy.array([2, 1, 3, 0, 0, 0, 0, 0, 0, 1])
        inDegSequence = numpy.array([1, 1, 1, 1, 1, 1, 1, 0, 0, 0])
        generator = ConfigModelGenerator(degSequence, inDegSequence)

        graph = SparseGraph(GeneralVertexList(numVertices))
        self.assertRaises(ValueError, generator.generate, graph)

        graph = SparseGraph(GeneralVertexList(numVertices), False)
        graph = generator.generate(graph)

        self.assertTrue(numpy.linalg.norm(degSequence - graph.outDegreeSequence()) < tol)
        self.assertTrue(numpy.linalg.norm(inDegSequence - graph.inDegreeSequence()) < tol)

        outDegSequence = numpy.array([2, 1, 3, 0, 2, 1, 4, 0, 0, 1])
        inDegSequence = numpy.array([1, 2, 1, 1, 2, 1, 2, 1, 2, 1])
        generator.setOutDegSequence(outDegSequence)
        generator.setInDegSequence(inDegSequence)
        graph.removeAllEdges()
        graph = generator.generate(graph)

        self.assertTrue(numpy.linalg.norm(outDegSequence - graph.outDegreeSequence()) < tol)
        self.assertTrue(numpy.linalg.norm(inDegSequence - graph.inDegreeSequence()) < tol)

        #In the case that the in-degree sequence sum larger than that of the out-degree it is
        #not satisfied, but the out-degree should be. 
        inDegSequence = numpy.array([1, 2, 1, 1, 2, 1, 2, 1, 5, 6])
        generator.setInDegSequence(inDegSequence)
        graph.removeAllEdges()
        graph = generator.generate(graph)
        self.assertTrue(numpy.linalg.norm(outDegSequence - graph.outDegreeSequence()) < tol)

        #Now try the other way around
        generator.setOutDegSequence(inDegSequence)
        generator.setInDegSequence(outDegSequence)
        graph.removeAllEdges()
        graph = generator.generate(graph)
        self.assertTrue(numpy.linalg.norm(outDegSequence - graph.inDegreeSequence()) < tol)

        #Test growing graph
        outDegSequence = numpy.array([2, 1, 3, 0, 2, 1, 4, 0, 0, 1])
        inDegSequence = numpy.array([1, 2, 1, 1, 2, 1, 2, 1, 2, 1])

        generator.setOutDegSequence(outDegSequence)
        generator.setInDegSequence(inDegSequence)
        graph.removeAllEdges()
        graph = generator.generate(graph)

        newOutDegreeSequence = numpy.array([2, 1, 3, 5, 2, 1, 4, 0, 0, 1])
        newInDegreeSequence = numpy.array([2, 3, 2, 2, 3, 1, 2, 1, 2, 1])
        diffOutSequence = newOutDegreeSequence - graph.outDegreeSequence()
        diffInSequence = newInDegreeSequence - graph.inDegreeSequence()
        generator.setOutDegSequence(diffOutSequence)
        generator.setInDegSequence(diffInSequence)
        graph = generator.generate(graph, False)

        self.assertTrue(numpy.linalg.norm(newOutDegreeSequence - graph.outDegreeSequence()) < tol)
        self.assertTrue(numpy.linalg.norm(newInDegreeSequence - graph.inDegreeSequence()) < tol)
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:89,代码来源:ConfigModelGeneratorTest.py


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