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


Python HIVGraph.subgraph方法代码示例

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


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

示例1: HIVGraphMetricsProfile

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import subgraph [as 别名]
class HIVGraphMetricsProfile():
    def __init__(self):
        #Total number of people in population
        self.M = 1000
        numInitialInfected = 5

        #The graph is one in which edges represent a contact
        undirected = True
        self.graph = HIVGraph(self.M, undirected)

        for i in range(self.M):
            vertex = self.graph.getVertex(i)

            #Set the infection time of a number of individuals to 0
            if i < numInitialInfected:
                vertex[HIVVertices.stateIndex] = HIVVertices.infected
            

        p = 0.01
        generator = ErdosRenyiGenerator(p)
        self.graph = generator.generate(self.graph)
        
        perm1 = numpy.random.permutation(self.M)
        perm2 = numpy.random.permutation(self.M)        
        
        sizes = [200, 300, 500, 1000]
        self.summary1 = [] 
        self.summary2 = [] 

        for size in sizes: 
            self.summary1.append(self.graph.subgraph(perm1[0:size]))
            self.summary2.append(self.graph.subgraph(perm2[0:int(size/10)]))
        
        print(self.graph)

    def profileDistance(self): 
        times = numpy.arange(len(self.summary1))
        #metrics = HIVGraphMetrics2(times, GraphMatch("RANK"))
        metrics = HIVGraphMetrics2(times, GraphMatch("U"))
        
        #Can try RANK and Umeyama algorithm - Umeyama is faster      
        self.summary2 = self.summary2[0:2]
        
        ProfileUtils.profile('metrics.distance(self.summary1, self.summary2)', globals(), locals())
开发者ID:charanpald,项目名称:wallhack,代码行数:46,代码来源:HIVGraphMetricProfile.py

示例2: testAddGraph

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import subgraph [as 别名]
 def testAddGraph(self): 
     epsilon = 0.12
     metrics = HIVGraphMetrics2(self.graph, epsilon)
     
     metrics.addGraph(self.graph)
   
     self.assertEquals(metrics.dists[0], 0.0)
     self.assertEquals(metrics.meanDistance(), 0.0)
     
     #Start a new graph 
     #Compute distances directly 
     matcher = GraphMatch("U")
     graph =  HIVGraph(self.graph.size)
     dists = [] 
     metrics = HIVGraphMetrics2(self.graph, epsilon)
     
     graph.vlist.setInfected(1, 0.0)
     graph.vlist.setDetected(1, 0.1, 0)
     metrics.addGraph(graph)
     
     t = graph.endTime()
     subgraph1 = graph.subgraph(graph.removedIndsAt(t))
     subgraph2 = self.graph.subgraph(graph.removedIndsAt(t)) 
     permutation, distance, time = matcher.match(subgraph1, subgraph2)
     lastDist = matcher.distance(subgraph1, subgraph2, permutation, True, True) 
     self.assertEquals(metrics.dists[-1], lastDist)
     self.assertTrue(metrics.shouldBreak())
     
     graph.vlist.setInfected(2, 2.0)
     graph.vlist.setDetected(2, 2.0, 0)
     metrics.addGraph(graph)
     
     t = graph.endTime()
     subgraph1 = graph.subgraph(graph.removedIndsAt(t))
     subgraph2 = self.graph.subgraph(graph.removedIndsAt(t)) 
     permutation, distance, time = matcher.match(subgraph1, subgraph2)
     lastDist = matcher.distance(subgraph1, subgraph2, permutation, True, True) 
     self.assertEquals(metrics.dists[-1], lastDist)   
     self.assertTrue(metrics.shouldBreak())
     
     graph.vlist.setInfected(7, 3.0)
     graph.vlist.setDetected(7, 3.0, 0)
     metrics.addGraph(graph)
     
     t = graph.endTime()
     subgraph1 = graph.subgraph(graph.removedIndsAt(t))
     subgraph2 = self.graph.subgraph(graph.removedIndsAt(t)) 
     permutation, distance, time = matcher.match(subgraph1, subgraph2)
     lastDist = matcher.distance(subgraph1, subgraph2, permutation, True, True) 
     self.assertEquals(metrics.dists[-1], lastDist) 
     self.assertFalse(metrics.shouldBreak())
     
     #Test case where one graph has zero size 
     graph1 = HIVGraph(10)
     graph2 = HIVGraph(10)
     
     graph1.vlist[:, HIVVertices.stateIndex] = HIVVertices.removed
     metrics = HIVGraphMetrics2(graph2, epsilon)
     metrics.addGraph(graph1)
     
     #Problem is that distance is 1 when one graph is zero
     self.assertEquals(len(metrics.dists), 0) 
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:64,代码来源:HIVGraphMetrics2Test.py


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