예제 #1
0
    def testInfectionProbability(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)
        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        t = 0.1

        graph.getVertex(0)[HIVVertices.stateIndex] = HIVVertices.infected
        graph.getVertex(1)[HIVVertices.stateIndex] = HIVVertices.removed
        graph.getVertex(2)[HIVVertices.stateIndex] = HIVVertices.infected

        for vertexInd1 in range(numVertices):
            for vertexInd2 in range(numVertices): 
                vertex1 = graph.getVertex(vertexInd1)
                vertex2 = graph.getVertex(vertexInd2)

                if vertex1[HIVVertices.stateIndex]!=HIVVertices.infected or vertex2[HIVVertices.stateIndex]!=HIVVertices.susceptible:
                    self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), 0.0)
                elif vertex1[HIVVertices.genderIndex] == HIVVertices.female and vertex2[HIVVertices.genderIndex] == HIVVertices.male:
                    self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb) 
                elif vertex1[HIVVertices.genderIndex] == HIVVertices.male and vertex2[HIVVertices.genderIndex] == HIVVertices.female:
                    self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb)
                elif vertex1[HIVVertices.genderIndex] == HIVVertices.male and vertex2[HIVVertices.orientationIndex]==HIVVertices.bi:
                    self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb)
                else:
                    self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), 0.0)
예제 #2
0
    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)