def loadParams(ind): if processReal: resultsDir = PathDefaults.getOutputDir() + "viroscopy/real/theta" + str(ind) + "/" outputDir = resultsDir + "stats/" N, matchAlpha, breakScale, numEpsilons, epsilon, minEpsilon, matchAlg, abcMaxRuns, batchSize, pertScale = HIVModelUtils.realABCParams(True) startDate, endDate, recordStep, M, targetGraph, numInds = HIVModelUtils.realSimulationParams(test=True, ind=ind) realTheta, sigmaTheta, pertTheta = HIVModelUtils.estimatedRealTheta(ind) numInds=2 prefix = "Real" else: resultsDir = PathDefaults.getOutputDir() + "viroscopy/toy/theta/" outputDir = resultsDir + "stats/" N, matchAlpha, breakScale, numEpsilons, epsilon, minEpsilon, matchAlg, abcMaxRuns, batchSize, pertScale = HIVModelUtils.toyABCParams() startDate, endDate, recordStep, M, targetGraph = HIVModelUtils.toySimulationParams(test=True) realTheta, sigmaTheta, pertTheta = HIVModelUtils.toyTheta() prefix = "Toy" numInds = 1 breakSize = (targetGraph.subgraph(targetGraph.removedIndsAt(endDate)).size - targetGraph.subgraph(targetGraph.removedIndsAt(startDate)).size) * breakScale return N, resultsDir, outputDir, recordStep, startDate, endDate, prefix, targetGraph, breakSize, numEpsilons, M, matchAlpha, matchAlg, numInds
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())
numProcesses = multiprocessing.cpu_count() if len(sys.argv) > 2: i = int(sys.argv[2]) else: i = 0 FORMAT = "%(levelname)s:root:%(process)d:%(message)s" logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=FORMAT) logging.debug("Number of processes: " + str(numProcesses)) logging.debug("Epidemic period index " + str(i)) numpy.set_printoptions(suppress=True, precision=4, linewidth=150) numpy.seterr(invalid='raise') resultsDir = PathDefaults.getOutputDir() + "viroscopy/real/" startDate, endDate, recordStep, M, targetGraph, numInds = HIVModelUtils.realSimulationParams(ind=i) N, matchAlpha, breakScale, numEpsilons, epsilon, minEpsilon, matchAlg, abcMaxRuns, batchSize, pertScale = HIVModelUtils.realABCParams(i) logging.debug("Posterior sample size " + str(N)) logging.debug("Matching algorithm " + str(matchAlg)) logging.debug("="*10 + "Starting new simulation batch with index " + str(i) + "="*10) logging.debug("Total time of simulation is " + str(endDate-startDate)) breakSize = (targetGraph.subgraph(targetGraph.removedIndsAt(endDate)).size - targetGraph.subgraph(targetGraph.removedIndsAt(startDate)).size) * breakScale logging.debug("Largest acceptable graph is " + str(breakSize)) def createModel(t): """ The parameter t is the particle index. """
matplotlib.use("GTK3Agg") import matplotlib.pyplot as plt """ This is the epidemic model for the HIV spread in cuba. Let's try to get an exponential infection. """ assert False, "Must run with -O flag" logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) numpy.seterr(all='raise') numpy.random.seed(24) numpy.set_printoptions(suppress=True, precision=4, linewidth=100) startDate, endDate, recordStep, M, targetGraph = HIVModelUtils.realSimulationParams() M = 100 endDate = startDate + 1000 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())
assert False, "Must run with -O flag" if len(sys.argv) > 1: numProcesses = int(sys.argv[1]) else: numProcesses = multiprocessing.cpu_count() FORMAT = "%(levelname)s:root:%(process)d:%(message)s" logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=FORMAT) logging.debug("Number of processes: " + str(numProcesses)) numpy.set_printoptions(suppress=True, precision=4, linewidth=150) numpy.seterr(invalid='raise') resultsDir = PathDefaults.getOutputDir() + "viroscopy/real/" startDates, endDates, numRecordSteps, M, targetGraph = HIVModelUtils.realSimulationParams() N, matchAlpha, breakScale, numEpsilons, epsilon, minEpsilon, matchAlg, abcMaxRuns, batchSize = HIVModelUtils.realABCParams() logging.debug("Posterior sample size " + str(N)) alpha = 2 zeroVal = 0.9 for i, endDate in enumerate(endDates): startDate = startDates[i] logging.debug("="*10 + "Starting new simulation batch with index " + str(i) + "="*10) logging.debug("Total time of simulation is " + str(endDate-startDate)) breakSize = targetGraph.subgraph(targetGraph.removedIndsAt(endDate)).size * breakScale logging.debug("Largest acceptable graph is " + str(breakSize))