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


Python HIVGraph.degreeDistribution方法代码示例

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


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

示例1: HIVRatesProfile

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import degreeDistribution [as 别名]
class HIVRatesProfile():
    def __init__(self):
        #Total number of people in population
        self.M = 10000
        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

        outputDirectory = PathDefaults.getOutputDir()
        directory = outputDirectory + "test/"
        self.profileFileName = directory + "profile.cprof"


    def profileContactRate(self):
        susceptibleList = list(range(1, self.graph.getNumVertices()))
        t = 10

        s = 3
        gen = scipy.stats.zipf(s)
        hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
        rates = HIVRates(self.graph, hiddenDegSeq)

        numContactEvents = 5000
        for i in range(numContactEvents):
            vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
            vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
            rates.contactEvent(vertexInd1, vertexInd2, 5)

        print((self.graph.getNumEdges()))

        infectedList = range(0, 100)
        contactList = range(100, self.M)
        t = 10

        def runContactRates():
            for i in range(100):
                rates.contactRates(infectedList, contactList, t)

        ProfileUtils.profile('runContactRates()', globals(), locals())


    def profileInfectionProbability(self):
        s = 3
        gen = scipy.stats.zipf(s)
        hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
        rates = HIVRates(self.graph, hiddenDegSeq)
        t = 5

        #Getting vertices and checking parameters takes the most time 
        def runInfectionProbs():
            for i in range(10000):
                vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
                vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
                rates.infectionProbability(vertexInd1, vertexInd2, t)

        ProfileUtils.profile('runInfectionProbs()', globals(), locals())

    def profileContactTracingRate(self):
        s = 3
        gen = scipy.stats.zipf(s)
        hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
        rates = HIVRates(self.graph, hiddenDegSeq)

        #Create a network of sexual contacts 
        numContactEvents = 10000
        for i in range(numContactEvents):
            vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
            vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
            rates.contactEvent(vertexInd1, vertexInd2, 5)

        print((self.graph))
        print((self.graph.degreeDistribution()))

        #Choose some individuals as being infected and then detected 
        p = 0.3
        q = 0.4
        for i in range(self.graph.getNumVertices()):
            if numpy.random.rand() < p and not self.graph.getVertex(i)[HIVVertices.stateIndex] == HIVVertices.infected:
                self.graph.getVertexList().setInfected(i, 5.0)

                if numpy.random.rand() < q:
                    self.graph.getVertexList().setDetected(i, 6.0, HIVVertices.randomDetect)

        infectedSet = self.graph.getInfectedSet()
        print((len(infectedSet)))
        print((len(self.graph.getRemovedSet())))

        removedSet = self.graph.getRemovedSet()

        t = 200
        def runContactTracingRate():
#.........这里部分代码省略.........
开发者ID:charanpald,项目名称:wallhack,代码行数:103,代码来源:HIVRatesProfile.py


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