def multiprocessingSim(params):
    # Create Sim instance
    folderRun = params[0]['rootFolder'] + '/Rep_' + str(params[0]['repeatIndex'])
    
    s = Sim(params[0]['scenarioIndex'], params[0], folderRun)
    
    print''
    print params[1]['policyIndex']
    print''
    
    s.run(params[1]['policyIndex'], params[1], params[1]['randomSeed'])
예제 #2
0
def gemRun(reps):
    taxMeans = []
    taxSEs = []

    p['verboseDebugging'] = False
    p['singleRunGraphs'] = False
    p['interactiveGraphics'] = False

    dataFile = open('GEMSA data new.txt', 'a')
    meansFile = open('GEMSA means new.txt', 'a')
    outFile = open('GEMSA outputs new.txt', 'a')

    #    agingParentList = [ 0.0, 0.1, 0.2, 0.4 ]
    #    careProbList = [ 0.0004, 0.0008, 0.0012, 0.0016 ]
    #    retiredHoursList = [ 20.0, 30.0, 40.0, 60.0 ]
    #    retiredAgeList = [ 60.0 ]
    #    ageingParentList = [ 0.0, 0.1 ]
    #    careProbList = [ 0.0004 ]
    #    retiredHoursList = [ 20.0 ]
    #    retiredAgeList = [ 60.0 ]

    for variableCare in p['ageingParentList']:
        for variableProb in p['careProbList']:
            for variableRetired in p['retiredHoursList']:
                for variableAge in p['retiredAgeList']:
                    p['agingParentsMoveInWithKids'] = variableCare
                    p['personCareProb'] = variableProb
                    p['retiredHours'] = variableRetired
                    p['ageOfRetirement'] = variableAge
                    print "Trying parents-moving-in probability: ", variableCare
                    print "Trying person care probability: ", variableProb
                    print "Trying retired hours: ", variableRetired
                    print "Trying retirement age: ", variableAge
                    taxList = []
                    taxSum = 0.0
                    meansFile.write(
                        str(variableCare) + "\t" + str(variableProb) + "\t" +
                        str(variableRetired) + "\t" + str(variableAge) + "\n")
                    for i in range(0, reps):
                        print i,
                        s = Sim(p)
                        tax, seed = s.run()
                        taxList.append(tax)
                        taxSum += tax
                        print tax
                        dataFile.write(
                            str(seed) + "\t" + str(variableCare) + "\t" +
                            str(variableProb) + "\t" + str(variableRetired) +
                            "\t" + str(variableAge) + "\t" + str(tax) + "\n")
                    taxMeans.append(pylab.mean(taxList))
                    outFile.write(str(taxSum / reps) + "\n")
                    taxSEs.append(pylab.std(taxList) / math.sqrt(reps))

    dataFile.close()
    meansFile.close()
    outFile.close()
예제 #3
0
def sensitivityRun(runtype, ageingList, careList, retiredHList, retiredAList,
                   reps):
    taxMeans = []
    taxSEs = []

    p['verboseDebugging'] = False
    p['singleRunGraphs'] = False
    p['interactiveGraphics'] = False

    dataFile = open(runtype + ' GEMSA data.txt', 'a')
    meansFile = open(runtype + ' GEMSA means.txt', 'a')
    outFile = open(runtype + ' GEMSA outputs.txt', 'a')

    #    agingParentList = [ 0.0, 0.1, 0.2, 0.4 ]
    #    careProbList = [ 0.0004, 0.0008, 0.0012, 0.0016 ]
    #    retiredHoursList = [ 20.0, 30.0, 40.0, 60.0 ]
    #    retiredAgeList = [ 60.0 ]
    #    ageingParentList = [ 0.0, 0.1 ]
    #    careProbList = [ 0.0004 ]
    #    retiredHoursList = [ 20.0 ]
    #    retiredAgeList = [ 60.0 ]

    for run in xrange(len(ageingList)):
        p['agingParentsMoveInWithKids'] = ageingList[run]
        p['personCareProb'] = careList[run]
        p['retiredHours'] = retiredHList[run]
        p['ageOfRetirement'] = retiredAList[run]
        print "Trying parents-moving-in probability: ", ageingList[run]
        print "Trying person care probability: ", careList[run]
        print "Trying retired hours: ", retiredHList[run]
        print "Trying retirement age: ", retiredAList[run]
        taxList = []
        taxSum = 0.0
        meansFile.write(
            str(ageingList[run]) + "\t" + str(careList[run]) + "\t" +
            str(retiredHList[run]) + "\t" + str(retiredAList[run]) + "\n")
        for i in range(0, reps):
            print i,
            s = Sim(p)
            tax, seed = s.run()
            taxList.append(tax)
            taxSum += tax
            print tax
            dataFile.write(
                str(seed) + "\t" + str(ageingList[run]) + "\t" +
                str(careList[run]) + "\t" + str(retiredHList[run]) + "\t" +
                str(retiredAList[run]) + "\t" + str(tax) + "\n")
        taxMeans.append(pylab.mean(taxList))
        outFile.write(str(taxSum / reps) + "\n")
        taxSEs.append(pylab.std(taxList) / math.sqrt(reps))

    dataFile.close()
    meansFile.close()
    outFile.close()
예제 #4
0
def batchRun(num):
    p['interactiveGraphics'] = False
    dataFile = open('batchRunData.txt', 'w')
    for i in range(0, num):
        print "Doing batch run: ", i
        taxList = []
        s = Sim(p)
        tax = s.run()
        taxList.append(tax)
        print "Social care cost per taxpayer: ", tax
        dataFile.write(str(i) + "\t" + str(tax) + "\n")
    dataFile.close()
예제 #5
0
def sensitivityLarge(runtype, input_list, reps):
    taxMeans = []
    taxSEs = []

    p['verboseDebugging'] = False
    p['singleRunGraphs'] = False
    p['interactiveGraphics'] = False

    outFile = open(runtype + ' GEMSA outputs large.txt', 'a')

    for run in xrange(len(input_list[0])):
        print("Running simulation number {}...".format(run))
        print("Number of reps: {}".format(reps))
        sim_list = np.array(input_list)
        print(sim_list)
        p['agingParentsMoveInWithKids'] = sim_list[0, run]
        print(p['agingParentsMoveInWithKids'])
        p['personCareProb'] = sim_list[1, run]
        p['retiredHours'] = sim_list[2, run]
        p['ageOfRetirement'] = sim_list[3, run]
        p['baseDieProb'] = sim_list[4, run]
        p['babyDieProb'] = sim_list[5, run]
        p['personCareProb'] = sim_list[6, run]
        p['maleAgeCareScaling'] = sim_list[7, run]
        p['femaleAgeCareScaling'] = sim_list[8, run]
        p['childHours'] = sim_list[9, run]
        p['homeAdultHours'] = sim_list[10, run]
        p['workingAdultHours'] = sim_list[11, run]
        p['lowCareHandicap'] = sim_list[12, run]
        p['growingPopBirthProb'] = sim_list[13, run]
        p['basicDivorceRate'] = sim_list[14, run]
        p['variableDivorce'] = sim_list[15, run]
        p['basicMaleMarriageProb'] = sim_list[16, run]
        p['basicFemaleMarriageProb'] = sim_list[17, run]
        p['probApartWillMoveTogether'] = sim_list[18, run]
        p['coupleMovesToExistingHousehold'] = sim_list[19, run]
        p['basicProbAdultMoveOut'] = sim_list[20, run]
        p['variableMoveBack'] = sim_list[21, run]
        taxList = []
        taxSum = 0.0
        for i in range(0, reps):
            print i,
            s = Sim(p)
            tax, seed = s.run()
            taxList.append(tax)
            taxSum += tax
            print tax
        taxMeans.append(pylab.mean(taxList))
        outFile.write(str(taxSum / reps) + "\n" + str(seed) + "\n")
        taxSEs.append(pylab.std(taxList) / math.sqrt(reps))

    outFile.close()
예제 #6
0
def retireRun(reps):
    taxMeans = []
    taxSEs = []
    p['verboseDebugging'] = False
    p['singleRunGraphs'] = False
    p['interactiveGraphics'] = False
    dataFile = open('retirementAgeData2.txt', 'w')
    #p['ageingParentList'] = [50, 55, 65, 70, 75, 80]
    for variableCare in p['ageingParentList']:
        p['ageOfRetirement'] = variableCare
        print "Trying retirement age: ", variableCare
        taxList = []
        for i in range(0, reps):
            print i,
            s = Sim(p)
            tax = s.run()
            taxList.append(tax)
            print tax
            dataFile.write(
                str(variableCare) + "\t" + str(i) + "\t" + str(tax) + "\n")
        taxMeans.append(pylab.mean(taxList))
        taxSEs.append(pylab.std(taxList) / math.sqrt(reps))

    dataFile.close()

    indices1 = pylab.arange(len(p['ageingParentList']))

    taxFig = pylab.figure()
    taxBar = taxFig.add_subplot(1, 1, 1)
    taxBar.bar(indices1,
               taxMeans,
               facecolor='red',
               align='center',
               yerr=taxSEs,
               ecolor='black')
    taxBar.set_ylabel('Mean social care cost per taxpayer')
    taxBar.set_xlabel('Age of retirement')
    taxBar.set_xticks(indices1)
    taxBar.set_xticklabels(p['ageingParentList'])
    pylab.savefig('retirementAgeRunSet1.pdf')
    pylab.show()
예제 #7
0
def sensitivityTenParams(runtype, input_list, reps):
    taxMeans = []
    taxSEs = []

    p['verboseDebugging'] = False
    p['singleRunGraphs'] = False
    p['interactiveGraphics'] = False

    outFile = open(runtype + ' GEMSA outputs.txt', 'a')

    for run in xrange(len(input_list[0])):
        print("Running simulation number {}...".format(run))
        print("Number of reps: {}".format(reps))
        sim_list = np.array(input_list)
        print(sim_list)
        p['agingParentsMoveInWithKids'] = sim_list[0, run]
        p['baseCareProb'] = sim_list[1, run]
        p['retiredHours'] = sim_list[2, run]
        p['ageOfRetirement'] = sim_list[3, run]
        p['personCareProb'] = sim_list[4, run]
        p['maleAgeCareScaling'] = sim_list[5, run]
        p['femaleAgeCareScaling'] = sim_list[6, run]
        p['childHours'] = sim_list[7, run]
        p['homeAdultHours'] = sim_list[8, run]
        p['workingAdultHours'] = sim_list[9, run]

        taxList = []
        taxSum = 0.0
        for i in range(0, reps):
            print i,
            s = Sim(p)
            tax, seed = s.run()
            taxList.append(tax)
            taxSum += tax
            print tax
        taxMeans.append(pylab.mean(taxList))
        outFile.write(str(taxSum / reps) + "\t" + str(seed) + "\n")
        taxSEs.append(pylab.std(taxList) / math.sqrt(reps))

    outFile.close()
예제 #8
0
        for r in range(numRepeats):
            # Create Run folders
            folderRun = folder + '/Rep_' + str(r)
            if not os.path.exists(folderRun):
                os.makedirs(folderRun)
            # Set seed
            seed = fSeed
            if r > 0:
                seed = int(time.time() / (r + 1))
            for i in range(len(scenariosParams)):
                n = OrderedDict(scenariosParams[i])
                s = Sim(i, n, folderRun)
                for j in range(len(policiesParams[i])):
                    p = OrderedDict(policiesParams[i][j])
                    s.run(j, p, seed)  # Add policy paramters later

    else:
        processors = int(metaParams['numberProcessors'])
        if processors > multiprocessing.cpu_count():
            processors = multiprocessing.cpu_count()

        pool = multiprocessing.Pool(processors)
        # Create a list of dictionaries (number repetitions times number of scenarios), adding repeat index for folders' creation
        params = multiprocessParams(scenariosParams, policiesParams,
                                    metaParams['numRepeats'], fSeed, folder, 0)
        pool.map(multiprocessingSim, params)
        pool.close()
        pool.join()

        if numberPolicies > 1:
예제 #9
0
    p['pixelsInPopPyramid'] = 2000
    p['careLevelColour'] = ['blue', 'green', 'yellow', 'orange', 'red']
    p['houseSizeColour'] = ['brown', 'purple', 'yellow']
    p['pixelsPerTown'] = 56
    p['maxTextUpdateList'] = 22

    return p


p = init_params()

#######################################################
## A basic single run

s = Sim(p)
tax = s.run()

##runs for sensitivity analysis using GEM-SA
##taxMeans = []
##taxSEs = []
##
##p['verboseDebugging'] = False
##p['singleRunGraphs'] = False
##p['interactiveGraphics'] = False
##
##dataFile = open('GEMSA data new.txt','a')
##meansFile = open('GEMSA means new.txt', 'a')
##
##agingParentList = [ 0.0, 0.1, 0.2, 0.4 ]
##careProbList = [ 0.0004, 0.0008, 0.0012, 0.0016 ]
##retiredHoursList = [ 20.0, 30.0, 40.0, 60.0 ]
예제 #10
0
def basicRun(p):
    s = Sim(p)
    tax = s.run()