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 oneModelRunWithOutput(self, allocationDictionary): import costcov import data from copy import deepcopy as dcp costCov = costcov.Costcov() spreadsheetData = data.readSpreadsheet(self.dataSpreadsheetName, self.helper.keyList) model, derived, params = self.helper.setupModelConstantsParameters( spreadsheetData) costCoverageInfo = self.getCostCoverageInfo() # run the model modelList = [] timestepsPre = 12 for t in range(timestepsPre): model.moveOneTimeStep() modelThisTimeStep = dcp(model) modelList.append(modelThisTimeStep) # update coverages after 1 year targetPopSize = getTargetPopSizeFromModelInstance( self.dataSpreadsheetName, self.helper.keyList, model) newCoverages = {} for i in range(0, len(spreadsheetData.interventionList)): intervention = spreadsheetData.interventionList[i] newCoverages[intervention] = costCov.function( allocationDictionary[intervention], costCoverageInfo[intervention], targetPopSize[intervention]) / targetPopSize[intervention] model.updateCoverages(newCoverages) for t in range(self.numModelSteps - timestepsPre): model.moveOneTimeStep() modelThisTimeStep = dcp(model) modelList.append(modelThisTimeStep) return modelList
def getTotalInitialAllocation(data, costCoverageInfo, targetPopSize): import costcov costCov = costcov.Costcov() allocation = [] for intervention in data.interventionList: coverageFraction = array( [dcp(data.interventionCoveragesCurrent[intervention])]) coverageNumber = coverageFraction * targetPopSize[intervention] if coverageNumber == 0: spending = array([0.]) else: spending = costCov.inversefunction(coverageNumber, costCoverageInfo[intervention], targetPopSize[intervention]) allocation.append(spending) return allocation
def getTotalInitialAllocation(data, costCoverageInfo, targetPopSize): import costcov from copy import deepcopy as dcp costCov = costcov.Costcov() allocation = [] for intervention in data.interventionList: coverageFraction = dcp(data.coverage[intervention]) coverageNumber = coverageFraction * targetPopSize[intervention] if coverageNumber == 0: spending = 0. else: spending = costCov.inversefunction(coverageNumber, costCoverageInfo[intervention], targetPopSize[intervention]) allocation.append(spending) return allocation
@author: madhurakilledar """ from __future__ import division from copy import deepcopy as dcp from numpy import array import os, sys moduleDir = os.path.join(os.path.dirname(__file__), '..') sys.path.append(moduleDir) import data import helper import output import costcov helper = helper.Helper() costCov = costcov.Costcov() country = 'Bangladesh' startYear = 2016 version = '1604' dataFilename = '../input_spreadsheets/%s/InputForCode_%s.xlsx' % (country, country) #dataFilename = '../input_spreadsheets/%s/Input_%s_%i_%s.xlsx'%(country, country, startYear, version) inputData = data.readSpreadsheet(dataFilename, helper.keyList) numAgeGroups = len(helper.keyList['ages']) numsteps = 180 oldCoverages = {} costCovParams = {}