distributor
add_intervention_nchooser_df(campaign, intervention_list, distribution_df, property_restrictions=None, target_disease_state=None, target_disease_state_has_intervention_name=None, event_name=None, node_ids=None)
Overview:
Distributes a list of individual-level interventions to exactly N people of a targeted demographic in HIV simulations. This contrasts with other event coordinators that distribute an intervention to a percentage of the population, not to an exact count.
Population Scaling:
'N' is assumed to be a number that is for the non-scaled population. This means you can make it the number actually
used in the real world. The 'N' values entered will be multiplied by the config parameter x_Base_Population.
For example
- If you wanted to model how the real world distributed 2,000 male circumcisions in 1990 when the total population was 400,000, and your demographic parameters are configured such that EMOD has about 400,000 people in 1990, you would distribute 2,000 male circumcisions.
- If the simulation is taking a long time, and you change
config.x_Base_Populationto 0.5 to cut the agents in the simulation in half, you would also want to reduce the number of male circumcisions being distributed. This feature will automatically adjust the number being targeted byconfig.x_Base_Populationto only hand out 1,000 male circumcisions.
Distribution Over Time:
NChooser will also spread out the number of interventions being distributed over the entire time period.
For example
- Let's assume that you are trying to distribute MaleCircumcision to 9 men over five update periods. NChooser will give out two interventions the first four update periods and one during the last update period.
DataFrame Requirements:
This function takes in a DataFrame containing the distribution data
- Required columns:
year,min_age,max_age - At least one of the following columns is required:
num_targeted,num_targeted_female,num_targeted_male
The data in the DataFrame is used to create a list of NChooserTargetedDistributionHIV objects specifying:
- When: with the year data
- To whom: with the min_age and max_age data
- How many interventions are distributed: with the num_targeted data, or the num_targeted_female for female
individuals and num_targeted_male for male individuals
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
campaign
|
(campaign, required)
|
|
required |
intervention_list
|
(list[IndividualIntervention], required)
|
|
required |
distribution_df
|
(DataFrame, required)
|
|
required |
target_disease_state
|
list[list[TargetDiseaseState]]
|
|
None
|
target_disease_state_has_intervention_name
|
str
|
|
None
|
property_restrictions
|
PropertyRestrictions
|
|
None
|
event_name
|
str
|
|
None
|
node_ids
|
list[int]
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return anything. It modifies the campaign object in place. |
Examples:
Example 1: This example demonstrates how to distribute a MaleCircumcision intervention to male individuals who are HIV positive and do not have the intervention already. The intervention is distributed based on the distribution data provided in a DataFrame.
>>> import emod_api
>>> from emodpy_hiv.campaign.distributor import add_intervention_nchooser_df
>>> from emodpy_hiv.campaign.individual_intervention import MaleCircumcision
>>> from emodpy_hiv.campaign.common import CommonInterventionParameters as CIP
>>> from emodpy_hiv.utils.emod_enum import TargetDiseaseState
>>> import pandas as pd
>>>
>>> campaign_obj = emod_api.campaign
>>> campaign_obj.schema_path = 'path_to_schema'
>>> # Initialize a MaleCircumcision intervention with intervention_name: 'MaleCircumcision'
>>> intervention_name='MaleCircumcision'
>>> mc = MaleCircumcision(campaign_obj, common_intervention_parameters=CIP(intervention_name=intervention_name)
>>> # Create a DataFrame with the distribution data: year, min_age, max_age, num_targeted_male
>>> # The intervention will be distributed to MALE individuals with the following values:
>>> # for the year 2010, age ranges: [1, 14.999), [15, 49.999), the number of targeted MALE individuals are: [200, 1300].
>>> # for the year 2011, age ranges: [1, 14.999), [15, 49.999), the number of targeted MALE individuals are: [290, 1490].
>>> data = {'year': [2010, 2010, 2011, 2011],
>>> 'min_age': [1, 15, 1, 15],
>>> 'max_age': [14.999, 49.999, 14.999, 49.999],
>>> 'num_targeted_male': [200, 1300, 290, 1490]}
>>> distributions_df = pd.DataFrame.from_dict(data)
>>> # Distribute the MaleCircumcision intervention to the campaign with the distribution data. The targeted
>>> # individuals should be male, HIV negative and don't have an intervention called 'MaleCircumcision' already.
>>> add_intervention_nchooser_df(campaign_obj,
>>> intervention_list=[mc],
>>> target_disease_state=[[TargetDiseaseState.HIV_POSITIVE, TargetDiseaseState.NOT_HAVE_INTERVENTION]],
>>> target_disease_state_has_intervention_name=intervention_name,
>>> distribution_df=distributions_df)
Example 2: This example demonstrates the usage of "And" and "Or" relationship in the target_disease_state parameter. With the following target_disease_state parameter, the MaleCircumcision intervention will be distributed to individuals who don't have the intervention already and are either HIV positive or tested positive.
>>> add_intervention_nchooser_df(campaign_obj,
>>> intervention_list=[mc],
>>> target_disease_state=[[TargetDiseaseState.HIV_POSITIVE, TargetDiseaseState.NOT_HAVE_INTERVENTION],
>>> [TargetDiseaseState.TESTED_POSITIVE, TargetDiseaseState.NOT_HAVE_INTERVENTION]],
>>> target_disease_state_has_intervention_name=intervention_name,
>>> distribution_df=distributions_df)
Raises:
Source code in emodpy_hiv/campaign/distributor.py
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
add_intervention_reference_tracking(campaign, intervention_list, time_value_map, tracking_config, start_year, end_year=2200, update_period=365, target_demographics_config=TargetDemographicsConfig(demographic_coverage=None), property_restrictions=None, targeting_config=None, event_name=None, node_ids=None)
Distribute interventions to the population such that a user determined coverage of an attribute is maintained over time.
This function creates a "tracker" that will track the prevalence of a specific attribute in the population and distribute interventions to achieve the desired coverage. The tracker will periodically poll the population to determine the current prevalence of the attribute and distribute the number of interventions needed to get prevalence up to the desired value. If prevalence is higher than the desired value, then no interventions will be distributed. Other things outside of this tracker (like expiration timers in the intervention) maybe needed to cause the coverage to stay down to the desired coverage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
campaign
|
(campaign, required)
|
|
required |
intervention_list
|
(list[IndividualIntervention], required)
|
|
required |
time_value_map
|
(ValueMap, required)
|
|
required |
tracking_config
|
(AbstractTargetingConfig, required)
|
|
required |
start_year
|
(float, required)
|
|
required |
end_year
|
float
|
|
2200
|
update_period
|
float
|
|
365
|
target_demographics_config
|
TargetDemographicsConfig
|
|
TargetDemographicsConfig(demographic_coverage=None)
|
property_restrictions
|
PropertyRestrictions
|
|
None
|
targeting_config
|
AbstractTargetingConfig
|
|
None
|
event_name
|
str
|
|
None
|
node_ids
|
list[int]
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return anything. It modifies the campaign object in place. |
Examples:
Use a reference tracker to ensure that the fraction of medium risk men that are circumcised meets certain levels each year from 1960 through 1965 where the tracker is updating who is circumcised every 6 months (182 days) If coverage is below the target level at the time of polling, apply the MaleCircumcision intervention to uncircumcised men to reach the target coverage.
Please note that you don't need to specify the negative of what you want to track(~IsCircumcised()) in the targeting_config. See more details in the targeting_config argument description.
>>> import emod_api
>>> from emodpy_hiv.campaign.distributor import add_intervention_reference_tracking
>>> from emodpy_hiv.campaign.individual_intervention import MaleCircumcision
>>> from emodpy_hiv.campaign.common import (ValueMap, TargetGender, CommonInterventionParameters as CIP,
>>> TargetDemographicsConfig as TDC)
>>> from emodpy_hiv.utils.targeting_config import IsCircumcised, HasIP
>>>
>>> campaign_obj = emod_api.campaign
>>> campaign_obj.schema_path = 'path_to_schema'
>>> mc = MaleCircumcision(campaign_obj,
>>> distributed_event_trigger='VMMC_1')
>>> time_value_map = ValueMap(times=[1960, 1961, 1962, 1963, 1964],
>>> values=[0.25, 0.375, 0.4, 0.4375, 0.46875])
>>> targeting_config = HasIP(ip_key_value="Risk:MEDIUM")
>>> tracking_config = IsCircumcised()
>>> add_intervention_reference_tracking(campaign_obj,
>>> intervention_list=[mc],
>>> time_value_map=time_value_map,
>>> tracking_config=tracking_config,
>>> targeting_config=targeting_config,
>>> start_year=1960,
>>> end_year=1965,
>>> update_period=182,
>>> target_demographics_config=TDC(target_gender=TargetGender.MALE))
Source code in emodpy_hiv/campaign/distributor.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |