def generateResultsForGeospatialCascades(self): import optimisation for region in range(0, self.numRegions): regionName = self.regionNameList[region] spreadsheet = self.regionSpreadsheetList[region] thisOptimisation = optimisation.Optimisation( spreadsheet, self.numModelSteps) filename = self.resultsFileStem + regionName + '_cascade_' + self.optimise + '_' thisOptimisation.performCascadeOptimisation( self.optimise, self.MCSampleSize, filename, self.cascadeValues)
def performGeospatialOptimisation(self, geoMCSampleSize, MCSampleSize, filenameStem): import optimisation print 'beginning geospatial optimisation..' optimisedRegionalBudgetList = self.getOptimisedRegionalBudgetList( geoMCSampleSize) print 'finished geospatial optimisation' for region in range(0, self.numRegions): regionName = self.regionNameList[region] print 'optimising for individual region ', regionName filename = filenameStem + '_' + regionName thisSpreadsheet = self.regionSpreadsheetList[region] thisOptimisation = optimisation.Optimisation( thisSpreadsheet, self.numModelSteps) thisBudget = optimisedRegionalBudgetList[region] thisOptimisation.performSingleOptimisationForGivenTotalBudget( self.optimise, MCSampleSize, filename, thisBudget)
def getTotalNationalBudget(self): import optimisation import data regionalBudgets = [] for region in range(0, self.numRegions): thisSpreadsheet = self.regionSpreadsheetList[region] thisOptimisation = optimisation.Optimisation( thisSpreadsheet, self.numModelSteps) spreadsheetData = data.readSpreadsheet( thisSpreadsheet, thisOptimisation.helper.keyList) costCoverageInfo = thisOptimisation.getCostCoverageInfo() initialTargetPopSize = thisOptimisation.getInitialTargetPopSize() initialAllocation = getTotalInitialAllocation( spreadsheetData, costCoverageInfo, initialTargetPopSize) regionTotalBudget = sum(initialAllocation) regionalBudgets.append(regionTotalBudget) nationalTotalBudget = sum(regionalBudgets) return nationalTotalBudget
def generateAllRegionsBOC(self): print 'reading files to generate regional BOCs..' import optimisation regionalBOCs = {} regionalBOCs['spending'] = [] regionalBOCs['outcome'] = [] for region in range(0, self.numRegions): print 'generating BOC for region: ', self.regionNameList[region] thisSpreadsheet = self.regionSpreadsheetList[region] thisOptimisation = optimisation.Optimisation( thisSpreadsheet, self.numModelSteps) filename = self.resultsFileStem + self.regionNameList[region] spending, outcome = thisOptimisation.generateBOCVectors( filename, self.regionNameList, self.cascadeValues, self.optimise) regionalBOCs['spending'].append(spending) regionalBOCs['outcome'].append(outcome) print 'finished generating regional BOCs from files' self.regionalBOCs = regionalBOCs
# read the optimal budget allocations from file filename = '../Results2016Jul/Bangladesh/deaths/v1/Bangladesh_cascade_deaths_v1_1.0.pkl' infile = open(filename, 'rb') deathsOptimumAllocation = pickle.load(infile) infile.close() filename = '../Results2016Jul/Bangladesh/stunting/v1/Bangladesh_cascade_stunting_v1_1.0.pkl' infile = open(filename, 'rb') stuntingOptimumAllocation = pickle.load(infile) infile.close() numModelSteps = 180 # NATIONAL dataSpreadsheetName = '../input_spreadsheets/Bangladesh/InputForCode_Bangladesh.xlsx' thisOptimisation = optimisation.Optimisation(dataSpreadsheetName, numModelSteps) initialAllocation = thisOptimisation.getInitialAllocationDictionary() # run models and save output baseline = thisOptimisation.oneModelRunWithOutput(initialAllocation) optimiseDeaths = thisOptimisation.oneModelRunWithOutput( deathsOptimumAllocation) optimiseStunting = thisOptimisation.oneModelRunWithOutput( stuntingOptimumAllocation) # GET Y AXIS FOR NUMBER OF DEATHS numberOfDeaths_baseline = [] numberOfDeaths_optimiseDeaths = [] numberOfDeaths_optimiseStunting = [] numberOfDeaths_baseline.append(baseline[0].getTotalCumulativeDeaths()) numberOfDeaths_optimiseDeaths.append(
# -*- coding: utf-8 -*- """ Created on Fri Jun 24 14:28:54 2016 @author: ruth """ import os, sys moduleDir = os.path.join(os.path.dirname(__file__), '..') sys.path.append(moduleDir) import optimisation numModelSteps = 180 MCSampleSize = 25 optimise = 'stunting' spreadsheet0 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Barisal.xlsx' spreadsheet1 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Chittagong.xlsx' spreadsheet2 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Dhaka.xlsx' spreadsheet3 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Khulna.xlsx' spreadsheet4 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Rajshahi.xlsx' spreadsheet5 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Rangpur.xlsx' spreadsheet6 = '../input_spreadsheets/Bangladesh/subregionSpreadsheets/Sylhet.xlsx' spreadsheetList = [spreadsheet0, spreadsheet1, spreadsheet2, spreadsheet3, spreadsheet4, spreadsheet5, spreadsheet6] for i in range(0, len(spreadsheetList)): spreadsheet = spreadsheetList[i] thisOptimisation = optimisation.Optimisation(spreadsheet, numModelSteps) filename = 'Bangladesh_geospatial_stunting_region_'+str(i) thisOptimisation.performSingleOptimisation(optimise, MCSampleSize, filename)
from plotting import plotallocations import optimisation country = 'Bangladesh' version = 'Results20160718' root = '../../%s/%s' % (country, version) print "\n find input here : %s" % root # NATIONAL nationalAllocations = {} # current baseline numsteps = 180 spreadsheetPath = '../input_spreadsheets/%s/InputForCode_%s.xlsx' % (country, country) thisOptimisation = optimisation.Optimisation(spreadsheetPath, numsteps) nationalAllocations[ 'baseline'] = thisOptimisation.getInitialAllocationDictionary() # optimised for objective in ['deaths', 'stunting']: filename = '%s/%s/national/%s_cascade_%s_1.0.pkl' % (root, objective, country, objective) infile = open(filename, 'rb') allocation = pickle.load(infile) nationalAllocations[objective] = allocation infile.close() # plot plotallocations(nationalAllocations['baseline'], nationalAllocations[objective]) # GEOSPATIAL