Exemplo n.º 1
0
    def generateStatistics(graph, startDate, endDate, recordStep): 
        """
        For a given theta, simulate the epidemic, and then return a number of 
        relevant statistics. 
        """
        times = [] 
        removedIndices = []
        
        for t in numpy.arange(startDate, endDate+1, recordStep): 
            times.append(t)
            removedIndices.append(graph.removedIndsAt(t))

        V = graph.getVertexList().getVertices()
        
        removedArray  = numpy.array([len(x) for x in removedIndices])
        maleArray  = numpy.array([numpy.sum(V[x, HIVVertices.genderIndex]==HIVVertices.male) for x in removedIndices])
        femaleArray = numpy.array([numpy.sum(V[x, HIVVertices.genderIndex]==HIVVertices.female) for x in removedIndices])
        heteroArray = numpy.array([numpy.sum(V[x, HIVVertices.orientationIndex]==HIVVertices.hetero) for x in removedIndices])
        biArray = numpy.array([numpy.sum(V[x, HIVVertices.orientationIndex]==HIVVertices.bi) for x in removedIndices])
        randDetectArray = numpy.array([numpy.sum(V[x, HIVVertices.detectionTypeIndex]==HIVVertices.randomDetect) for x in removedIndices])
        conDetectArray = numpy.array([numpy.sum(V[x, HIVVertices.detectionTypeIndex]==HIVVertices.contactTrace) for x in removedIndices])
        
        vertexArray = numpy.c_[removedArray, maleArray, femaleArray, heteroArray, biArray, randDetectArray, conDetectArray]
        
        graphStats = GraphStatistics()
        removedGraphStats = graphStats.sequenceScalarStats(graph, removedIndices, slowStats=False)
        
        return times, vertexArray, removedGraphStats
    def testSequenceScalarStats(self):
        numFeatures = 1
        numVertices = 10
        vList = VertexList(numVertices, numFeatures)
        graph = SparseGraph(vList)

        graph.addEdge(0, 2)
        graph.addEdge(0, 1)

        subgraphIndices = [[0, 1, 3], [0, 1, 2, 3]]

        growthStatistics = GraphStatistics()
        statsArray = growthStatistics.sequenceScalarStats(graph, subgraphIndices)

        self.assertTrue(statsArray[0, 0] == 3.0)
        self.assertTrue(statsArray[1, 0] == 4.0)
        self.assertTrue(statsArray[0, 1] == 1.0)
        self.assertTrue(statsArray[1, 1] == 2.0)
Exemplo n.º 3
0
    def generateStatistics(graph, times): 
        """
        For a given theta, simulate the epidemic, and then return a number of 
        relevant statistics. 
        """
        contactIndices = []
        removedIndices = []
        infectedIndices = []
        
        for t in times: 
            removedIndices.append(graph.removedIndsAt(t))
            infectedIndices.append(graph.infectedIndsAt(t))
            contactIndices.append(graph.contactIndsAt(t))

        infectedIndices = numpy.array(infectedIndices)

        V = graph.getVertexList().getVertices()
        graphStatsList = []
        
        for inds in [contactIndices, removedIndices]: 
            numVerticesArray  = numpy.array([len(x) for x in inds])
            maleArray  = numpy.array([numpy.sum(V[x, HIVVertices.genderIndex]==HIVVertices.male) for x in inds])
            femaleArray = numpy.array([numpy.sum(V[x, HIVVertices.genderIndex]==HIVVertices.female) for x in inds])
            heteroArray = numpy.array([numpy.sum(V[x, HIVVertices.orientationIndex]==HIVVertices.hetero) for x in inds])
            biArray = numpy.array([numpy.sum(V[x, HIVVertices.orientationIndex]==HIVVertices.bi) for x in inds])
            randDetectArray = numpy.array([numpy.sum(V[x, HIVVertices.detectionTypeIndex]==HIVVertices.randomDetect) for x in inds])
            conDetectArray = numpy.array([numpy.sum(V[x, HIVVertices.detectionTypeIndex]==HIVVertices.contactTrace) for x in inds])
            
            vertexArray = numpy.c_[numVerticesArray, maleArray, femaleArray, heteroArray, biArray, randDetectArray, conDetectArray]
        
            graphStatistics = GraphStatistics()
            graphStats = graphStatistics.sequenceScalarStats(graph, inds, slowStats=False)
            graphStatsList.append(graphStats)
            
        finalRemovedGraph = graph.subgraph(removedIndices[-1])
        finalRemovedDegrees = finalRemovedGraph.degreeDistribution()
        
        return vertexArray, infectedIndices, removedIndices, graphStatsList[0], graphStatsList[1], finalRemovedDegrees