-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameters.py
More file actions
163 lines (145 loc) · 8.71 KB
/
parameters.py
File metadata and controls
163 lines (145 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-
"""
Created on Fri April 1 2016
@author: madhura
"""
from __future__ import division
from copy import deepcopy as dcp
class Params:
def __init__(self, data, derived, keyList):
self.derived = derived
for key in keyList.keys():
setattr(self, key, keyList[key])
self.causesOfDeath = dcp(data.causesOfDeath)
self.conditions = dcp(data.conditions)
self.demographics = dcp(data.demographics)
#self.rawMortality = dcp(data.rawMortality)
self.causeOfDeathDist = dcp(data.causeOfDeathDist)
self.stuntingDistribution = dcp(data.stuntingDistribution)
self.wastingDistribution = dcp(data.wastingDistribution)
self.breastfeedingDistribution = dcp(data.breastfeedingDistribution)
self.RRdeathStunting = dcp(data.RRdeathStunting)
self.RRdeathWasting = dcp(data.RRdeathWasting)
self.RRdeathBreastfeeding = dcp(data.RRdeathBreastfeeding)
self.RRdeathByBirthOutcome = dcp(data.RRdeathByBirthOutcome)
#self.ORstuntingProgression = dcp(data.ORstuntingProgression)
self.incidences = dcp(data.incidences)
#self.RRdiarrhea = dcp(data.RRdiarrhea)
#self.ORstuntingCondition = dcp(data.ORstuntingCondition)
#self.ORstuntingBirthOutcome = dcp(data.ORstuntingBirthOutcome)
self.birthOutcomeDist = dcp(data.birthOutcomeDist)
#self.ORstuntingIntervention = dcp(data.ORstuntingIntervention)
#self.ORappropriatebfIntervention = dcp(data.ORappropriatebfIntervention)
self.ageAppropriateBreastfeeding = dcp(data.ageAppropriateBreastfeeding)
self.coverage = dcp(data.coverage)
self.effectivenessMortality = dcp(data.effectivenessMortality)
self.affectedFraction = dcp(data.affectedFraction)
self.effectivenessIncidence = dcp(data.effectivenessIncidence)
self.interventionsMaternal = dcp(data.interventionsMaternal)
self.foodSecurityGroups = dcp(data.foodSecurityGroups)
# Add all functions for updating parameters due to interventions here....
def getMortalityUpdate(self, newCoverage):
mortalityUpdate = {}
for ageName in self.ages:
mortalityUpdate[ageName] = {}
for cause in self.causesOfDeath:
mortalityUpdate[ageName][cause] = 1.
causeList = ((self.effectivenessMortality.values()[0]).values()[0]).keys()
for ageName in self.ages:
for intervention in newCoverage.keys():
for cause in causeList:
affectedFrac = self.affectedFraction[intervention][ageName][cause]
effectiveness = self.effectivenessMortality[intervention][ageName][cause]
newCoverageVal = newCoverage[intervention]
oldCoverage = self.coverage[intervention]
reduction = affectedFrac * effectiveness * (newCoverageVal - oldCoverage) / (1. - effectiveness*oldCoverage)
mortalityUpdate[ageName][cause] *= 1. - reduction
return mortalityUpdate
def getBirthOutcomeUpdate(self, newCoverage):
birthOutcomeUpdate = {}
for outcome in self.birthOutcomes:
birthOutcomeUpdate[outcome] = 1.
for intervention in newCoverage.keys():
for outcome in self.birthOutcomes:
affectedFrac = self.interventionsMaternal[intervention][outcome]['affected fraction']
effectiveness = self.interventionsMaternal[intervention][outcome]['effectiveness']
newCoverageVal = newCoverage[intervention]
oldCoverage = self.coverage[intervention]
reduction = affectedFrac * effectiveness * (newCoverageVal - oldCoverage) / (1. - effectiveness*oldCoverage)
birthOutcomeUpdate[outcome] *= 1. - reduction
return birthOutcomeUpdate
def getStuntingUpdate(self, newCoverage):
stuntingUpdate = {}
for ageName in self.ages:
stuntingUpdate[ageName] = 1.
oldProbStunting = self.stuntingDistribution[ageName]["high"] + self.stuntingDistribution[ageName]["moderate"]
for intervention in newCoverage.keys():
probStuntingIfCovered = self.derived.probStuntedIfCovered[intervention]["covered"][ageName]
probStuntingIfNotCovered = self.derived.probStuntedIfCovered[intervention]["not covered"][ageName]
newProbStunting = newCoverage[intervention]*probStuntingIfCovered + (1.-newCoverage[intervention])*probStuntingIfNotCovered
reduction = (oldProbStunting - newProbStunting)/oldProbStunting
stuntingUpdate[ageName] *= 1. - reduction
return stuntingUpdate
def getAppropriateBFNew(self, newCoverage):
correctbfFracNew = {}
for ageName in self.ages:
correctPractice = self.ageAppropriateBreastfeeding[ageName]
correctbfFracBefore = self.breastfeedingDistribution[ageName][correctPractice]
correctbfFracNew[ageName] = correctbfFracBefore
for intervention in newCoverage.keys():
probCorrectIfCovered = self.derived.probCorrectlyBreastfedIfCovered[intervention]["covered"][ageName]
probCorrectIfNotCovered = self.derived.probCorrectlyBreastfedIfCovered[intervention]["not covered"][ageName]
correctbfFracNewThis = newCoverage[intervention]*probCorrectIfCovered + (1.-newCoverage[intervention])*probCorrectIfNotCovered
fracAdd = correctbfFracNewThis - correctbfFracBefore
correctbfFracNew[ageName] += fracAdd
return correctbfFracNew
def getIncidenceUpdate(self, newCoverage):
incidenceUpdate = {}
for ageName in self.ages:
incidenceUpdate[ageName] = {}
for condition in self.conditions:
incidenceUpdate[ageName][condition] = 1.
for ageName in self.ages:
for intervention in newCoverage.keys():
for condition in self.conditions:
affectedFrac = self.affectedFraction[intervention][ageName][condition]
effectiveness = self.effectivenessIncidence[intervention][ageName][condition]
newCoverageVal = newCoverage[intervention]
oldCoverage = self.coverage[intervention]
reduction = affectedFrac * effectiveness * (newCoverageVal - oldCoverage) / (1. - effectiveness*oldCoverage)
incidenceUpdate[ageName][condition] *= 1. - reduction
return incidenceUpdate
def getStuntingUpdateDueToIncidence(self, beta):
stuntingUpdate = {}
for ageName in self.ages:
stuntingUpdate[ageName] = 1.
newProbStunting = 0
oldProbStunting = self.stuntingDistribution[ageName]["high"] + self.stuntingDistribution[ageName]["moderate"]
for breastfeedingCat in self.breastfeedingList:
pab = self.breastfeedingDistribution[ageName][breastfeedingCat]
t1 = beta[ageName][breastfeedingCat] * self.derived.fracStuntedIfDiarrhea["dia"][ageName]
t2 = (1 - beta[ageName][breastfeedingCat]) * self.derived.fracStuntedIfDiarrhea["nodia"][ageName]
newProbStunting += pab * (t1 + t2)
reduction = (oldProbStunting - newProbStunting)/oldProbStunting
stuntingUpdate[ageName] *= 1. - reduction
return stuntingUpdate
def getStuntingUpdateComplementaryFeeding(self, newCoverage):
stuntingUpdate = {}
FracSecure = 1. - self.demographics['fraction food insecure']
FracCoveredEducation = newCoverage['Complementary feeding (education)']
FracCoveredSupplements = newCoverage['Complementary feeding (supplementation)']
Frac = [0.]*4
Frac[0] = FracSecure * FracCoveredEducation
Frac[1] = FracSecure * (1 - FracCoveredEducation)
Frac[2] = (1 - FracSecure) * FracCoveredSupplements
Frac[3] = (1 - FracSecure) * (1 - FracCoveredSupplements)
for ageName in self.ages:
stuntingUpdate[ageName] = 1.
oldProbStunting = self.stuntingDistribution[ageName]["high"] + self.stuntingDistribution[ageName]["moderate"]
newProbStunting = 0
for i in range(len(self.foodSecurityGroups)):
probThisGroup = self.derived.probStuntedComplementaryFeeding[ageName][self.foodSecurityGroups[i]]
newProbStunting += probThisGroup * Frac[i]
reduction = (oldProbStunting - newProbStunting)/oldProbStunting
stuntingUpdate[ageName] *= 1. - reduction
return stuntingUpdate