Beispiel #1
0
def objectiveFunction(proposalAllocation, totalBudget, costCoverageInfo,
                      optimise, mothers, timestep, agingRateList, agePopSizes,
                      keyList, data):
    import helper as helper
    from numpy import array
    helper = helper.Helper()
    model, constants, params = helper.setupModelConstantsParameters(
        'optimisation model', mothers, timestep, agingRateList, agePopSizes,
        keyList, data)
    if sum(proposalAllocation) == 0:
        scaledproposalAllocation = proposalAllocation
    else:
        scaledproposalAllocation = rescaleAllocation(totalBudget,
                                                     proposalAllocation)
    # calculate coverage (%)
    newCoverages = {}
    for i in range(0, len(data.interventionList)):
        intervention = data.interventionList[i]
        newCoverages[intervention] = costCov.function(
            array([scaledproposalAllocation[i]
                   ]), costCoverageInfo[intervention],
            targetPopSize[intervention]) / targetPopSize[intervention]
    model.updateCoverages(newCoverages)
    for t in range(numsteps):
        model.moveOneTimeStep()
    if optimise == 'deaths':
        performanceMeasure = model.getTotalCumulativeDeaths()
    if optimise == 'stunting':
        performanceMeasure = model.getCumulativeAgingOutStunted()
    return performanceMeasure
Beispiel #2
0
def objectiveFunction(proposalAllocation, totalBudget, costCoverageInfo, optimise, numModelSteps, dataSpreadsheetName, data):
    import helper 
    import costcov
    helper = helper.Helper()
    costCov = costcov.Costcov()
    model, derived, params = helper.setupModelConstantsParameters(data)
    if sum(proposalAllocation) == 0: 
        scaledproposalAllocation = proposalAllocation
    else:    
        scaledproposalAllocation = rescaleAllocation(totalBudget, proposalAllocation)
    # run the model
    timestepsPre = 12
    for t in range(timestepsPre):
        model.moveOneTimeStep()    
    # update coverages after 1 year   
    targetPopSize = getTargetPopSizeFromModelInstance(dataSpreadsheetName, helper.keyList, model)   
    newCoverages = {}    
    for i in range(0, len(data.interventionList)):
        intervention = data.interventionList[i]
        newCoverages[intervention] = costCov.function(scaledproposalAllocation[i], costCoverageInfo[intervention], targetPopSize[intervention]) / targetPopSize[intervention]
    model.updateCoverages(newCoverages)
    for t in range(numModelSteps - timestepsPre):
        model.moveOneTimeStep()
    if optimise == 'deaths':    
        performanceMeasure = model.getTotalCumulativeDeaths()
    if optimise == 'stunting':        
        performanceMeasure = model.getCumulativeAgingOutStunted()
    return performanceMeasure    
Beispiel #3
0
def objectiveFunction(proposalAllocation, totalBudget, costCoverageInfo,
                      optimise, numModelSteps, dataSpreadsheetName, data):
    import helper
    import costcov
    helper = helper.Helper()
    costCov = costcov.Costcov()
    model, derived, params = helper.setupModelConstantsParameters(data)
    if sum(proposalAllocation) == 0:
        scaledproposalAllocation = proposalAllocation
    else:
        scaledproposalAllocation = rescaleAllocation(totalBudget,
                                                     proposalAllocation)
    # run the model
    timestepsPre = 12
    for t in range(timestepsPre):
        model.moveOneTimeStep()
    # update coverages after 1 year
    targetPopSize = getTargetPopSizeFromModelInstance(dataSpreadsheetName,
                                                      helper.keyList, model)
    newCoverages = {}
    for i in range(0, len(data.interventionList)):
        intervention = data.interventionList[i]
        newCoverages[intervention] = costCov.function(
            scaledproposalAllocation[i], costCoverageInfo[intervention],
            targetPopSize[intervention]) / targetPopSize[intervention]
    model.updateCoverages(newCoverages)
    for t in range(numModelSteps - timestepsPre):
        model.moveOneTimeStep()
    if optimise == 'deaths':
        performanceMeasure = model.getTotalCumulativeDeaths()
    if optimise == 'stunting':
        performanceMeasure = model.getCumulativeAgingOutStunted()
    return performanceMeasure
def objectiveFunction(proposalAllocation, totalBudget, costCoverageInfo, optimise, mothers, timestep, agingRateList, agePopSizes, keyList, data):
    import helper as helper
    from numpy import array
    helper = helper.Helper()
    model, constants, params = helper.setupModelConstantsParameters('optimisation model', mothers, timestep, agingRateList, agePopSizes, keyList, data)
    if sum(proposalAllocation) == 0: 
        scaledproposalAllocation = proposalAllocation
    else:    
        scaledproposalAllocation = rescaleAllocation(totalBudget, proposalAllocation)
    # calculate coverage (%)
    newCoverages = {}    
    for i in range(0, len(data.interventionList)):
        intervention = data.interventionList[i]
        newCoverages[intervention] = costCov.function(array([scaledproposalAllocation[i]]), costCoverageInfo[intervention], targetPopSize[intervention]) / targetPopSize[intervention]
    model.updateCoverages(newCoverages)
    for t in range(numsteps):
        model.moveOneTimeStep()
    if optimise == 'deaths':    
        performanceMeasure = model.getTotalCumulativeDeaths()
    if optimise == 'stunting':        
        performanceMeasure = model.getCumulativeAgingOutStunted()
    return performanceMeasure    
    costCovParams[intervention] = {}
    costCovParams[intervention]['unitcost'] = dcp(
        inputData.costSaturation[intervention]["unit cost"])
    costCovParams[intervention]['saturation'] = dcp(
        inputData.costSaturation[intervention]["saturation coverage"])

plotData = []
run = 0

#------------------------------------------------------------------------
# DEFAULT RUN WITH NO CHANGES TO INTERVENTIONS
nametag = "Baseline"
plotcolor = 'grey'

print "\n" + nametag
model, derived, params = helper.setupModelConstantsParameters(inputData)
modelList = []

# Run model
for t in range(numsteps):
    model.moveOneTimeStep()
    modelList.append(dcp(model))

plotData.append({})
plotData[run]["modelList"] = modelList
plotData[run]["tag"] = nametag
plotData[run]["color"] = plotcolor
run += 1

#------------------------------------------------------------------------
# INTERVENTION
timespan = helper.keyList['timestep'] * float(numsteps)

print "Baseline coverage of: "
for intervention in inputData.interventionList:
    print "%s = %g"%(intervention,inputData.coverage[intervention])

plotData = []
run = 0
#------------------------------------------------------------------------    
# DEFAULT RUN WITH NO CHANGES TO INTERVENTIONS
nametag = "Baseline"
pickleFilename = '%s_Default_Investment.pkl'%(country)
plotcolor = 'grey'

print "\n"+nametag
model, derived, params = helper.setupModelConstantsParameters(inputData)

# file to dump objects into at each time step
outfile = open(pickleFilename, 'wb')

# Run model
for t in range(numsteps):
    model.moveOneTimeStep()
    pickle.dump(model, outfile)
outfile.close()    

# collect output, make graphs etc.
infile = open(pickleFilename, 'rb')
modelList = []
while 1:
    try: