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


Python HIVGraph.getVertexList方法代码示例

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


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

示例1: testRemoveEvent

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testRemoveEvent(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)
        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        t = 0.1

        V = graph.getVertexList().getVertices()
        femaleInds = V[:, HIVVertices.genderIndex]==HIVVertices.female
        maleInds = V[:, HIVVertices.genderIndex]==HIVVertices.male
        biMaleInds = numpy.logical_and(maleInds, V[:, HIVVertices.orientationIndex]==HIVVertices.bi)

        self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p)

        graph.getVertexList().setInfected(4, t)
        graph.getVertexList().setInfected(7, t)
        graph.getVertexList().setInfected(8, t)
        rates.removeEvent(4, HIVVertices.randomDetect, t)
        rates.removeEvent(7, HIVVertices.randomDetect, t)
        
        removedInds= list(graph.getRemovedSet())    
        
        hiddenDegSeq[removedInds] = 0 
        
        #Check the new degree sequences are correct 
        self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p)
开发者ID:charanpald,项目名称:wallhack,代码行数:33,代码来源:HIVRatesTest.py

示例2: testGetSusceptibleSet

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testGetSusceptibleSet(self):
        numVertices = 10
        graph = HIVGraph(numVertices)

        self.assertTrue(graph.getSusceptibleSet() == set(range(numVertices)))

        for i in range(9):
            graph.getVertexList().setInfected(i, 0.0)

        self.assertTrue(graph.getSusceptibleSet() == set([9]))
开发者ID:charanpald,项目名称:wallhack,代码行数:12,代码来源:HIVGraphTest.py

示例3: testGetInfectedSet

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testGetInfectedSet(self):
        numVertices = 10
        graph = HIVGraph(numVertices)

        self.assertTrue(graph.getInfectedSet() == set([]))

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(3, 0.0)
        graph.getVertexList().setInfected(7, 0.0)

        self.assertTrue(graph.getInfectedSet() == set([1, 3, 7]))
开发者ID:charanpald,项目名称:wallhack,代码行数:13,代码来源:HIVGraphTest.py

示例4: testRandomDetectionRates

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testRandomDetectionRates(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)

        t = 0.1
        graph.getVertexList().setInfected(0, t)

        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        infectedList = [0, 2, 9]

        rdRates = rates.randomDetectionRates(infectedList, float(graph.size - len(graph.getRemovedSet())))

        nptst.assert_array_almost_equal(rdRates, numpy.ones(len(infectedList))*rates.randDetectRate*len(infectedList)/float(graph.size - len(graph.getRemovedSet())))
开发者ID:charanpald,项目名称:wallhack,代码行数:17,代码来源:HIVRatesTest.py

示例5: testSummary

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testSummary(self): 
        numVertices = 10
        graph = HIVGraph(numVertices)

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 2.0)
        graph.getVertexList().setInfected(7, 3.0)
        
        times = numpy.array([0, 1.0, 3.0, 4.0])
        
        metrics = HIVGraphMetrics(times)
        summary = metrics.summary(graph)
        
        summaryReal = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
        nptst.assert_array_equal(summaryReal, summary)
开发者ID:charanpald,项目名称:wallhack,代码行数:17,代码来源:HIVGraphMetricsTest.py

示例6: testContructor

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testContructor(self):
        numVertices = 10
        graph = HIVGraph(numVertices)

        
        self.assertEquals(numVertices, graph.getNumVertices())
        self.assertEquals(8, graph.getVertexList().getNumFeatures())
        self.assertTrue(graph.isUndirected() == True)
开发者ID:charanpald,项目名称:wallhack,代码行数:10,代码来源:HIVGraphTest.py

示例7: testContactRates3

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
 def testContactRates3(self): 
     #Figure out why infection does not explode when we set infection probability 
     #to a high value and do not detect 
     
     undirected = True
     numVertices = 20
     graph = HIVGraph(numVertices, undirected)
     hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
     rates = HIVRates(graph, hiddenDegSeq)
     t = 0.1
     
     for i in range(10): 
         graph.getVertexList().setInfected(i, t)
     
     t = 0.2
     infectedList = graph.infectedIndsAt(t)
     contactList = range(0, numVertices)
     contactRateInds, contactRates = rates.contactRates(infectedList, contactList, t)
     
     print(contactRateInds, contactRates)
开发者ID:charanpald,项目名称:wallhack,代码行数:22,代码来源:HIVRatesTest.py

示例8: testUpperDetectionRates

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testUpperDetectionRates(self): 
        """
        See if the upper bound on detection rates is correct 
        """
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)
        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        t = 0.1
        
        graph.getVertexList().setInfected(0, t)
        graph.getVertexList().setInfected(1, t)
        graph.getVertexList().setInfected(8, t)
        
        t = 0.2
        rates.removeEvent(8, HIVVertices.randomDetect, t)
        rates.infectionProbability = 1.0
        
        infectedList = graph.infectedIndsAt(t)
        removedList = graph.removedIndsAt(t)
        n = graph.size-removedList
        self.assertEquals(rates.upperDetectionRates(infectedList, n), rates.randomDetectionRates(infectedList, n, seed=21).sum()) 
        
        t = 0.3
        rates.contactEvent(0, 2, t)
        graph.vlist.setInfected(2, t)
        
        t = 0.4
        rates.removeEvent(0, HIVVertices.randomDetect, t)
        
        infectedList = graph.infectedIndsAt(t)
        removedSet = graph.removedIndsAt(t)
        removedSet = set(removedSet.tolist())

        nptst.assert_array_almost_equal(rates.contactTracingRates(infectedList, removedSet, t + rates.ctStartTime + 1), numpy.array([0, rates.ctRatePerPerson]))
        
        upperDetectionRates = rates.ctRatePerPerson + rates.randomDetectionRates(infectedList, n, seed=21).sum()
        self.assertEquals(rates.upperDetectionRates(infectedList, n), upperDetectionRates) 
开发者ID:charanpald,项目名称:wallhack,代码行数:41,代码来源:HIVRatesTest.py

示例9: testShouldBreak

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testShouldBreak(self): 
        numVertices = 10
        graph = HIVGraph(numVertices)

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 2.0)
        graph.getVertexList().setInfected(7, 3.0)        
        
        summary1 = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
        summary2 = numpy.array([[1,0], [2,0], [3, 0], [3,0]])
        
        times = numpy.array([0, 1.0, 3.0, 4.0])      
        epsilon = 1
        
        currentTime = 5
        self.assertTrue(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))

        currentTime = 1        
        self.assertTrue(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))
        
        currentTime = 0.9        
        self.assertFalse(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))
开发者ID:charanpald,项目名称:wallhack,代码行数:24,代码来源:HIVGraphMetricsTest.py

示例10: testGetRemovedSet

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testGetRemovedSet(self):
        numVertices = 10
        graph = HIVGraph(numVertices)

        self.assertTrue(graph.getRemovedSet() == set([]))

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 0.0)
        graph.getVertexList().setInfected(7, 0.0)

        graph.getVertexList().setDetected(1, 0.0, HIVVertices.randomDetect)
        graph.getVertexList().setDetected(2, 0.0, HIVVertices.randomDetect)
        graph.getVertexList().setDetected(7, 0.0, HIVVertices.randomDetect)

        self.assertTrue(graph.getRemovedSet() == set([1, 2, 7]))
开发者ID:charanpald,项目名称:wallhack,代码行数:17,代码来源:HIVGraphTest.py

示例11: testContactEvent

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testContactEvent(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)

        #for i in range(numVertices):
        #    logging.debug(graph.getVertex(i))

        t = 0.2
        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)

        V = graph.getVertexList().getVertices()
        femaleInds = V[:, HIVVertices.genderIndex]==HIVVertices.female
        maleInds = V[:, HIVVertices.genderIndex]==HIVVertices.male
        biMaleInds = numpy.logical_and(maleInds, V[:, HIVVertices.orientationIndex]==HIVVertices.bi)

        self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p)
        self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p)

        for i in range(numVertices):
            self.assertEquals(rates.contactTimesArr[i], -1)

        rates.contactEvent(0, 9, 0.1)
        rates.contactEvent(0, 3, 0.2)
        
        self.assertEquals(graph.getEdge(0, 3), 0.2)
        self.assertEquals(graph.getEdge(0, 9), 0.1)

        self.assertTrue((rates.contactTimesArr[0] == numpy.array([3])).all())
        self.assertTrue((rates.contactTimesArr[9] == numpy.array([0])).all())
        self.assertTrue((rates.contactTimesArr[3] == numpy.array([0])).all())

        for i in range(numVertices):
            self.assertTrue((rates.neighboursList[i] == graph.neighbours(i)).all())

        #Check that the degree sequence is correct
        degSequence = graph.outDegreeSequence()
        r = rates.q-rates.p 

        self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p + degSequence[femaleInds].sum()*r)
        self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p + degSequence[maleInds].sum()*r)
        self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p + degSequence[biMaleInds].sum()*r)
开发者ID:charanpald,项目名称:wallhack,代码行数:46,代码来源:HIVRatesTest.py

示例12: testInfectedIndsAt

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testInfectedIndsAt(self): 
        numVertices = 10
        graph = HIVGraph(numVertices)

        self.assertTrue(graph.getRemovedSet() == set([]))

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 2.0)
        graph.getVertexList().setInfected(7, 3.0)
        
        
        inds = graph.infectedIndsAt(10)
        nptst.assert_array_equal(inds, numpy.array([1, 2, 7]))
        
        graph.getVertexList().setInfected(5, 12.0)
        nptst.assert_array_equal(inds, numpy.array([1, 2, 7]))
开发者ID:charanpald,项目名称:wallhack,代码行数:18,代码来源:HIVGraphTest.py

示例13: HIVRatesProfile

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [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

示例14: testContactTracingRate

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
    def testContactTracingRate(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)

        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        t = 0.1
        graph.getVertexList().setInfected(0, t)
        rates.contactEvent(0, 3, 0.2)
        rates.contactEvent(0, 9, 0.1)

        t = 0.3
        graph.getVertexList().setInfected(3, t)
        graph.getVertexList().setInfected(9, t)

        t = 0.4
        rates.removeEvent(0, HIVVertices.randomDetect, t)

        removedSet = graph.getRemovedSet()
        infectedList = [3, 9]
        ctRates = rates.contactTracingRates(infectedList, removedSet, t)
        self.assertTrue((ctRates==numpy.array([0.0, 0.0])).all())

        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctStartTime)
        self.assertTrue((ctRates == numpy.array([rates.ctRatePerPerson, rates.ctRatePerPerson])).all())

        #Test contact tracing is within correct time period
        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctEndTime-0.01)
        self.assertTrue((ctRates == numpy.array([rates.ctRatePerPerson, rates.ctRatePerPerson])).all())

        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctEndTime+1)
        self.assertTrue((ctRates == numpy.array([0, 0])).all())

        rates.contactEvent(3, 5, t)
        graph.getVertexList().setInfected(5, t)
        rates.removeEvent(5, HIVVertices.randomDetect, t)
        removedSet = graph.getRemovedSet()
        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctStartTime)

        self.assertTrue((ctRates == numpy.array([rates.ctRatePerPerson, rates.ctRatePerPerson])).all())
        
        rates.contactEvent(3, 6, t)
        graph.getVertexList().setInfected(6, t)
        infectedList = [3, 6, 9]
        removedSet = graph.getRemovedSet()
 
        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctStartTime)
        self.assertTrue((ctRates == numpy.array([rates.ctRatePerPerson, 0, rates.ctRatePerPerson])).all())

        #Now make removedSet bigger than infectedList
        graph.getVertexList().setInfected(4, t)
        graph.getVertexList().setInfected(7, t)
        graph.getVertexList().setInfected(8, t)
        graph.getVertexList().setDetected(4, t, HIVVertices.randomDetect)
        graph.getVertexList().setDetected(7, t, HIVVertices.randomDetect)
        graph.getVertexList().setDetected(8, t, HIVVertices.randomDetect)

        #Note: InfectedList is out of order 
        infectedList = list(graph.getInfectedSet())
        sortInds = numpy.argsort(numpy.array(infectedList))
        removedSet = graph.getRemovedSet()

        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctStartTime)
        ctRates2 = numpy.array([rates.ctRatePerPerson, 0, rates.ctRatePerPerson])
        self.assertTrue((ctRates[sortInds] == ctRates2).all())

        #Test the case where InfectedList is out of order and removedSet is small
        graph.getVertexList().setInfected(4, t)
        graph.getVertex(7)[HIVVertices.stateIndex] = HIVVertices.susceptible
        graph.getVertex(8)[HIVVertices.stateIndex] = HIVVertices.susceptible

        infectedList = list(graph.getInfectedSet())
        sortInds = numpy.argsort(numpy.array(infectedList))
        removedSet = graph.getRemovedSet()

        ctRates = rates.contactTracingRates(infectedList, removedSet, t+rates.ctStartTime)
        ctRates2 = numpy.array([rates.ctRatePerPerson, 0, 0, rates.ctRatePerPerson])
        self.assertTrue((ctRates[sortInds] == ctRates2).all())
开发者ID:charanpald,项目名称:wallhack,代码行数:81,代码来源:HIVRatesTest.py

示例15: HIVGraphMetricsTest

# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getVertexList [as 别名]
class  HIVGraphMetricsTest(unittest.TestCase):
    def setUp(self):
        numpy.random.seed(21)
        numpy.set_printoptions(linewidth=100, suppress=True, precision=3)
        
        
        numVertices = 10
        self.graph = HIVGraph(numVertices)

        self.graph.getVertexList().setInfected(1, 0.0)
        self.graph.getVertexList().setDetected(1, 0.1, 0)
        self.graph.getVertexList().setInfected(2, 2.0)
        self.graph.getVertexList().setDetected(2, 2.0, 0)
        self.graph.getVertexList().setInfected(7, 3.0)
        self.graph.getVertexList().setDetected(7, 3.0, 0)

    def testSummary(self): 
        numVertices = 10
        graph = HIVGraph(numVertices)

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 2.0)
        graph.getVertexList().setInfected(7, 3.0)
        
        times = numpy.array([0, 1.0, 3.0, 4.0])
        
        metrics = HIVGraphMetrics(times)
        summary = metrics.summary(graph)
        
        summaryReal = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
        nptst.assert_array_equal(summaryReal, summary)
    
        
    def testDistance(self): 
        summary1 = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
        summary2 = numpy.array([[1,0], [1,0], [3, 0], [4,0]])
        
        times = numpy.array([0, 1.0, 3.0, 4.0])        
        
        self.assertEquals(HIVGraphMetrics(times).distance(summary1, summary2), numpy.linalg.norm(summary1 - summary2)) 
        
    def testShouldBreak(self): 
        numVertices = 10
        graph = HIVGraph(numVertices)

        graph.getVertexList().setInfected(1, 0.0)
        graph.getVertexList().setInfected(2, 2.0)
        graph.getVertexList().setInfected(7, 3.0)        
        
        summary1 = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
        summary2 = numpy.array([[1,0], [2,0], [3, 0], [3,0]])
        
        times = numpy.array([0, 1.0, 3.0, 4.0])      
        epsilon = 1
        
        currentTime = 5
        self.assertTrue(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))

        currentTime = 1        
        self.assertTrue(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))
        
        currentTime = 0.9        
        self.assertFalse(HIVGraphMetrics(times).shouldBreak(summary2, graph, epsilon, currentTime))
开发者ID:charanpald,项目名称:wallhack,代码行数:65,代码来源:HIVGraphMetricsTest.py


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