11use ixa:: {
2- Context , ContextEntitiesExt , ContextRandomExt , IxaError , define_property, define_rng,
3- impl_property, prelude:: PropertyChangeEvent ,
2+ Context , ContextEntitiesExt , ContextRandomExt , IxaError , define_derived_property, define_rng, impl_derived_property, impl_property, prelude:: PropertyChangeEvent
43} ;
54use rand_distr:: LogNormal ;
65use serde:: { Deserialize , Serialize } ;
76
87use crate :: {
9- ContextParametersExt , Params ,
10- infectiousness_manager:: InfectionStatus ,
11- population_loader:: { Person , PersonId } ,
8+ Age , ContextParametersExt , Params , infectiousness_manager:: InfectionStatus , population_loader:: { Person , PersonId }
129} ;
1310
1411define_rng ! ( SymptomsRng ) ;
@@ -29,12 +26,21 @@ impl_property!(
2926 default_const = SymptomStatus :: NoSymptoms
3027) ;
3128
32- pub enum SymptomAgeGroupNames {
29+ #[ derive( Debug , Clone , Serialize , Deserialize , Eq , PartialEq , Hash ) ]
30+ pub enum SymptomAgeGroup {
3331 Young ,
3432 Old ,
3533}
3634
37- define_property ! ( SymptomAgeGroupNames , Person , ) ;
35+ impl_derived_property ! ( SymptomAgeGroup , Person , [ Age ] , [ GlobalParams ] ,
36+ |age, params|{
37+ let symptom_age_group_thresholds = params. symptom_age_groups. clone( ) ;
38+ for ( age_group, min_age) in symptom_age_group_thresholds{
39+ if age >= min_age {
40+ let symptom_age_group: SymptomAgeGroup = age_group;
41+ }
42+ }
43+ } ) ;
3844
3945#[ derive( Debug , Serialize , Deserialize , Copy , Clone ) ]
4046pub struct SymptomDelayDistLogNormParams {
@@ -61,6 +67,7 @@ fn process_symptom_change_event(
6167 event : PropertyChangeEvent < Person , SymptomStatus > ,
6268) {
6369 let & Params {
70+ symptom_age_groups,
6471 probability_severe_given_mild,
6572 mild_to_severe_delay,
6673 mild_to_resolved_delay,
@@ -75,7 +82,7 @@ fn process_symptom_change_event(
7582
7683 match event. current {
7784 SymptomStatus :: Mild => {
78- if context. sample_bool ( SymptomsRng , probability_severe_given_mild) {
85+ if context. sample_bool ( SymptomsRng , probability_severe_given_mild. get ( symptom_age_group ) ) {
7986 plan_symptom_transition (
8087 context,
8188 event. entity_id ,
@@ -92,7 +99,7 @@ fn process_symptom_change_event(
9299 }
93100 }
94101 SymptomStatus :: Severe => {
95- if context. sample_bool ( SymptomsRng , probability_critical_given_severe) {
102+ if context. sample_bool ( SymptomsRng , probability_critical_given_severe. get ( symptom_age_group ) ) {
96103 plan_symptom_transition (
97104 context,
98105 event. entity_id ,
@@ -109,7 +116,7 @@ fn process_symptom_change_event(
109116 }
110117 }
111118 SymptomStatus :: Critical => {
112- if context. sample_bool ( SymptomsRng , probability_dead_given_critical) {
119+ if context. sample_bool ( SymptomsRng , probability_dead_given_critical. get ( & symptom_age_group ) ) {
113120 plan_symptom_transition (
114121 context,
115122 event. entity_id ,
@@ -194,27 +201,39 @@ mod test {
194201 ..Default :: default ( )
195202 } ,
196203 ( SymptomStatus :: Mild , SymptomStatus :: Severe ) => Params {
197- probability_severe_given_mild : expected_proportion,
204+ probability_severe_given_mild : HashMap :: from ( [
205+ ( "all" , expected_proportion)
206+ ] ) ,
198207 ..Default :: default ( )
199208 } ,
200209 ( SymptomStatus :: Mild , SymptomStatus :: Resolved ) => Params {
201- probability_severe_given_mild : 1.0 - expected_proportion,
210+ probability_severe_given_mild : HashMap :: from ( [
211+ ( "all" , 1.0 - expected_proportion)
212+ ] ) ,
202213 ..Default :: default ( )
203214 } ,
204215 ( SymptomStatus :: Severe , SymptomStatus :: Critical ) => Params {
205- probability_critical_given_severe : expected_proportion,
216+ probability_critical_given_severe : HashMap :: from ( [
217+ ( "all" , expected_proportion)
218+ ] ) ,
206219 ..Default :: default ( )
207220 } ,
208221 ( SymptomStatus :: Severe , SymptomStatus :: Resolved ) => Params {
209- probability_critical_given_severe : 1.0 - expected_proportion,
222+ probability_critical_given_severe : HashMap :: from ( [
223+ ( "all" , 1.0 - expected_proportion)
224+ ] ) ,
210225 ..Default :: default ( )
211226 } ,
212227 ( SymptomStatus :: Critical , SymptomStatus :: Dead ) => Params {
213- probability_dead_given_critical : expected_proportion,
228+ probability_dead_given_critical : HashMap :: from ( [
229+ ( "all" , expected_proportion)
230+ ] ) ,
214231 ..Default :: default ( )
215232 } ,
216233 ( SymptomStatus :: Critical , SymptomStatus :: Resolved ) => Params {
217- probability_dead_given_critical : 1.0 - expected_proportion,
234+ probability_dead_given_critical : HashMap :: from ( [
235+ ( "all" , 1.0 - expected_proportion)
236+ ] ) ,
218237 ..Default :: default ( )
219238 } ,
220239 _ => panic ! (
@@ -290,47 +309,59 @@ mod test {
290309 ..Default :: default ( )
291310 } ,
292311 ( SymptomStatus :: Mild , SymptomStatus :: Severe ) => Params {
293- probability_severe_given_mild : 1.0 ,
312+ probability_severe_given_mild : HashMap :: from ( [
313+ ( "all" , 1.0 )
314+ ] ) ,
294315 mild_to_severe_delay : SymptomDelayDistLogNormParams {
295316 mu : expected_mu,
296317 sigma : expected_sigma,
297318 } ,
298319 ..Default :: default ( )
299320 } ,
300321 ( SymptomStatus :: Mild , SymptomStatus :: Resolved ) => Params {
301- probability_severe_given_mild : 0.0 ,
322+ probability_severe_given_mild : HashMap :: from ( [
323+ ( "all" , 0.0 )
324+ ] ) ,
302325 mild_to_resolved_delay : SymptomDelayDistLogNormParams {
303326 mu : expected_mu,
304327 sigma : expected_sigma,
305328 } ,
306329 ..Default :: default ( )
307330 } ,
308331 ( SymptomStatus :: Severe , SymptomStatus :: Critical ) => Params {
309- probability_critical_given_severe : 1.0 ,
332+ probability_critical_given_severe : HashMap :: from ( [
333+ ( "all" , 1.0 )
334+ ] ) ,
310335 severe_to_critical_delay : SymptomDelayDistLogNormParams {
311336 mu : expected_mu,
312337 sigma : expected_sigma,
313338 } ,
314339 ..Default :: default ( )
315340 } ,
316341 ( SymptomStatus :: Severe , SymptomStatus :: Resolved ) => Params {
317- probability_critical_given_severe : 0.0 ,
342+ probability_critical_given_severe : HashMap :: from ( [
343+ ( "all" , 0.0 )
344+ ] ) ,
318345 severe_to_resolved_delay : SymptomDelayDistLogNormParams {
319346 mu : expected_mu,
320347 sigma : expected_sigma,
321348 } ,
322349 ..Default :: default ( )
323350 } ,
324351 ( SymptomStatus :: Critical , SymptomStatus :: Dead ) => Params {
325- probability_dead_given_critical : 1.0 ,
352+ probability_dead_given_critical : HashMap :: from ( [
353+ ( "all" , 1.0 )
354+ ] ) ,
326355 critical_to_dead_delay : SymptomDelayDistLogNormParams {
327356 mu : expected_mu,
328357 sigma : expected_sigma,
329358 } ,
330359 ..Default :: default ( )
331360 } ,
332361 ( SymptomStatus :: Critical , SymptomStatus :: Resolved ) => Params {
333- probability_dead_given_critical : 0.0 ,
362+ probability_dead_given_critical : HashMap :: from ( [
363+ ( "all" , 0.0 )
364+ ] ) ,
334365 critical_to_resolved_delay : SymptomDelayDistLogNormParams {
335366 mu : expected_mu,
336367 sigma : expected_sigma,
@@ -463,9 +494,15 @@ mod test {
463494 let mut count_resolved: u64 = 0 ;
464495 let mut count_dead: u64 = 0 ;
465496 let probability_mild_given_infect = 0.5 ;
466- let probability_severe_given_mild = 0.5 ;
467- let probability_critical_given_severe = 0.5 ;
468- let probability_dead_given_critical = 0.5 ;
497+ let probability_severe_given_mild = HashMap :: from ( [
498+ ( "all" , 0.5 )
499+ ] ) ;
500+ let probability_critical_given_severe = HashMap :: from ( [
501+ ( "all" , 0.5 )
502+ ] ) ;
503+ let probability_dead_given_critical = HashMap :: from ( [
504+ ( "all" , 0.5 )
505+ ] ) ;
469506 for seed in 0 ..num_sims {
470507 let mut context = Context :: new ( ) ;
471508 let parameters = Params {
0 commit comments