def runModel(meanTheta): startDate, endDate, recordStep, M, targetGraph = HIVModelUtils.toySimulationParams() endDate = 1000.0 recordStep = 50 undirected = True logging.debug("MeanTheta=" + str(meanTheta)) numReps = 10 numInfectedIndices = [] numRemovedIndices = [] numRemovedEdges = [] numContactEdges = [] statistics = GraphStatistics() statsTimes = numpy.arange(0, endDate, recordStep) for i in range(numReps): graph = HIVGraph(M, undirected) logging.info("Created graph at index " + str(i) + ": " + str(graph)) alpha = 2 zeroVal = 0.9 p = Util.powerLawProbs(alpha, zeroVal) hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices()) rates = HIVRates(graph, hiddenDegSeq) model = HIVEpidemicModel(graph, rates) model.setT0(startDate) model.setT(endDate) model.setRecordStep(recordStep) model.setParams(meanTheta) times, infectedIndices, removedIndices, graph = model.simulate(True) vertexArray, infectedIndices, removedIndices, contactGraphStats, removedGraphStats = HIVModelUtils.generateStatistics( graph, statsTimes ) numInfectedIndices.append([len(x) for x in infectedIndices]) numRemovedIndices.append([len(x) for x in removedIndices]) numContactEdges.append(contactGraphStats[:, statistics.numVerticesIndex]) numRemovedEdges.append(removedGraphStats[:, statistics.numVerticesIndex]) numInfectedIndices = numpy.array(numInfectedIndices) numInfectedIndices = numpy.mean(numInfectedIndices, 0) numRemovedIndices = numpy.array(numRemovedIndices) numRemovedIndices = numpy.mean(numRemovedIndices, 0) numContactEdges = numpy.array(numContactEdges) numContactEdges = numpy.mean(numContactEdges, 0) numRemovedEdges = numpy.array(numRemovedEdges) numRemovedEdges = numpy.mean(numRemovedEdges, 0) return statsTimes, numInfectedIndices, numRemovedIndices, numContactEdges, numRemovedEdges, vertexArray[:, 6]
def profileSimulate(self): startDate, endDates, numRecordSteps, M, targetGraph = HIVModelUtils.realSimulationParams() meanTheta, sigmaTheta = HIVModelUtils.estimatedRealTheta() undirected = True graph = HIVGraph(M, undirected) logging.info("Created graph: " + str(graph)) alpha = 2 zeroVal = 0.9 p = Util.powerLawProbs(alpha, zeroVal) hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices()) rates = HIVRates(graph, hiddenDegSeq) model = HIVEpidemicModel(graph, rates) model.setT0(startDate) model.setT(startDate+1000) model.setRecordStep(10) model.setParams(meanTheta) logging.debug("MeanTheta=" + str(meanTheta)) ProfileUtils.profile('model.simulate()', globals(), locals())
meanTheta, sigmaTheta = HIVModelUtils.estimatedRealTheta() meanTheta = numpy.array([ 1, 0.1, 0.0, 0.00, 0.5, 0.1]) outputDir = PathDefaults.getOutputDir() + "viroscopy/" undirected = True graph = HIVGraph(M, undirected) logging.info("Created graph: " + str(graph)) alpha = 2 zeroVal = 0.9 p = Util.powerLawProbs(alpha, zeroVal) hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices()) rates = HIVRates(graph, hiddenDegSeq) model = HIVEpidemicModel(graph, rates) model.setT0(startDate) model.setT(endDate) model.setRecordStep(recordStep) model.setParams(meanTheta) logging.debug("MeanTheta=" + str(meanTheta)) times, infectedIndices, removedIndices, graph = model.simulate(True) statistics = GraphStatistics() vertexArray, infectedIndices, removedIndices, contactGraphStats, removedGraphStats = HIVModelUtils.generateStatistics(graph, times) numInfectedIndices = [len(x) for x in infectedIndices] plt.figure(0) plt.plot(times, numInfectedIndices)