| … | … | @@ -77,17 +77,18 @@ |
| 77 | 77 | (use-modules (ice-9 textual-ports)) |
| 78 | 78 | |
| 79 | 79 | ; --------------------------------------------------------------------- |
| 80 | | ; Scheme short-hand for five possible states. This serves no particular |
| 81 | | ; purpose, other than to be slightly less verbose when writing later |
| 82 | | ; expressions. |
| 80 | ; Scheme short-hand for five possible disease states. |
| 83 | 81 | (define susceptible (Concept "susceptible")) |
| 84 | 82 | (define exposed (Concept "exposed")) |
| 85 | 83 | (define infected (Concept "infected")) |
| 86 | 84 | (define recovered (Concept "recovered")) |
| 87 | 85 | (define died (Concept "died")) |
| 88 | 86 | |
| 89 | | ; Predicate under which the SEIR state will be stored. This marks |
| 90 | | ; the location (key) under which the state-value will be stored. |
| 87 | ; State will be stored as Atomese Values, placed at certain locations |
| 88 | ; (keys). Every Atom is a key-value database; the below defines the keys |
| 89 | ; where the Values (attributes) will be stored. |
| 90 | ; |
| 91 | ; Predicate under which the SEIR state will be stored. |
| 91 | 92 | (define seir-state (Predicate "SEIR state")) |
| 92 | 93 | |
| 93 | 94 | ; Predicate under which a susceptibility weight will be stored. |
| … | … | @@ -107,8 +108,10 @@ |
| 107 | 108 | |
| 108 | 109 | ; --------------------------------------------------------------------- |
| 109 | 110 | ; A function that implements the transmission of the disease. |
| 110 | | ; It takes two arguments: two people, A and B, with A being |
| 111 | | ; exposed if B is infected. It is unidirectional. |
| 111 | ; It takes two arguments: two people, A and B, with A becoming |
| 112 | ; exposed if B is infected. It is unidirectional. This is a |
| 113 | ; deterministic state change: there's no "probability of exposure", |
| 114 | ; one simply is, or isn't. The probabilities are in the next step. |
| 112 | 115 | (Define |
| 113 | 116 | (DefinedSchema "transmission") |
| 114 | 117 | (Lambda |
| … | … | @@ -132,9 +135,9 @@ |
| 132 | 135 | ; If A is exposed, and is infirm, then A is infected. |
| 133 | 136 | ; The probability of infection is controlled by a random |
| 134 | 137 | ; number generator. RandomNumberLink generates a uniform |
| 135 | | ; distribution. |
| 138 | ; distribution between the two indicated bounds. |
| 136 | 139 | (And |
| 137 | | (Equal (ValueOf (Variable "$A") seir-state) (Concept "exposed")) |
| 140 | (Equal (ValueOf (Variable "$A") seir-state) exposed) |
| 138 | 141 | (GreaterThan |
| 139 | 142 | (ValueOf (Variable "$A") susceptibility) |
| 140 | 143 | (RandomNumber (Number 0) (Number 1)))) |
| … | … | @@ -147,7 +150,7 @@ |
| 147 | 150 | ; one returns to original, unexposed state. |
| 148 | 151 | ; Use one minus the probability of getting infected. |
| 149 | 152 | (And |
| 150 | | (Equal (ValueOf (Variable "$A") seir-state) (Concept "exposed")) |
| 153 | (Equal (ValueOf (Variable "$A") seir-state) exposed) |
| 151 | 154 | (GreaterThan |
| 152 | 155 | (Minus (Number 1) |
| 153 | 156 | (ValueOf (Variable "$A") susceptibility)) |
| … | … | @@ -157,16 +160,16 @@ |
| 157 | 160 | ; If A is infected, then A has a chance of dying, |
| 158 | 161 | ; depending on the infirmity. |
| 159 | 162 | (And |
| 160 | | (Equal (ValueOf (Variable "$A") seir-state) (Concept "infected")) |
| 163 | (Equal (ValueOf (Variable "$A") seir-state) infected) |
| 161 | 164 | (GreaterThan |
| 162 | 165 | (ValueOf (Variable "$A") infirmity) |
| 163 | 166 | (RandomNumber (Number 0) (Number 1)))) |
| 164 | 167 | (SetValue (Variable "$A") seir-state died) |
| 165 | 168 | |
| 166 | 169 | ; If A is infected, then A has a chance of recovering, |
| 167 | | ; depending on the infirmity. |
| 170 | ; depending on the recovery-health strength. |
| 168 | 171 | (And |
| 169 | | (Equal (ValueOf (Variable "$A") seir-state) (Concept "infected")) |
| 172 | (Equal (ValueOf (Variable "$A") seir-state) infected) |
| 170 | 173 | (GreaterThan |
| 171 | 174 | (ValueOf (Variable "$A") recovery) |
| 172 | 175 | (RandomNumber (Number 0) (Number 1)))) |
| … | … | @@ -354,20 +357,23 @@ |
| 354 | 357 | (format #t "The social network consists of ~D individuals\n" |
| 355 | 358 | (length individual-list)) |
| 356 | 359 | |
| 357 | | ; Assign to each individual the state of "initially healthy", and |
| 358 | | ; some random numbers for susceptibility. |
| 360 | ; Assign to each individual the state of "initially healthy". |
| 361 | ; Choose some random numbers for the overall population health: |
| 362 | ; some random susceptibility (the probability of becoming ill after |
| 363 | ; being exposed), the infirmity (probability of illness leading to |
| 364 | ; death) and a probability of recovering from illness. |
| 359 | 365 | (for-each |
| 360 | 366 | (lambda (individual) |
| 361 | 367 | (cog-set-value! individual seir-state susceptible) |
| 362 | 368 | (cog-set-value! individual susceptibility |
| 363 | | (cog-execute! (RandomNumber (Number 0.1) (Number 1)))) |
| 364 | | (cog-set-value! individual infirmity |
| 365 | 369 | (cog-execute! (RandomNumber (Number 0.2) (Number 0.8)))) |
| 370 | (cog-set-value! individual infirmity |
| 371 | (cog-execute! (RandomNumber (Number 0.01) (Number 0.55)))) |
| 366 | 372 | (cog-set-value! individual recovery |
| 367 | | (cog-execute! (RandomNumber (Number 0.3) (Number 0.7))))) |
| 373 | (cog-execute! (RandomNumber (Number 0.6) (Number 0.95))))) |
| 368 | 374 | individual-list) |
| 369 | 375 | |
| 370 | | ; Pick one person, and make them infected |
| 376 | ; Pick one person, and make them infected. |
| 371 | 377 | (cog-set-value! (car individual-list) seir-state infected) |
| 372 | 378 | |
| 373 | 379 | ; --------------------------------------------------------------------- |