OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 01a2a2e

Revise, cleanup.
01a2a2ebc928d817a4346c35ceb4b351c623cff9
by Linas Vepstas <linasvepstas@gmail.com> · 2020-04-21T17:34:16.000Z

Changed files (1) +25 -19

demo/seir.scm +25 -19
……@@ -77,17 +77,18 @@
7777(use-modules (ice-9 textual-ports))
7878
7979; ---------------------------------------------------------------------
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.
8381(define susceptible (Concept "susceptible"))
8482(define exposed (Concept "exposed"))
8583(define infected (Concept "infected"))
8684(define recovered (Concept "recovered"))
8785(define died (Concept "died"))
8886
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.
9192(define seir-state (Predicate "SEIR state"))
9293
9394; Predicate under which a susceptibility weight will be stored.
……@@ -107,8 +108,10 @@
107108
108109; ---------------------------------------------------------------------
109110; 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.
112115(Define
113116 (DefinedSchema "transmission")
114117 (Lambda
……@@ -132,9 +135,9 @@
132135 ; If A is exposed, and is infirm, then A is infected.
133136 ; The probability of infection is controlled by a random
134137 ; number generator. RandomNumberLink generates a uniform
135 ; distribution.
138 ; distribution between the two indicated bounds.
136139 (And
137 (Equal (ValueOf (Variable "$A") seir-state) (Concept "exposed"))
140 (Equal (ValueOf (Variable "$A") seir-state) exposed)
138141 (GreaterThan
139142 (ValueOf (Variable "$A") susceptibility)
140143 (RandomNumber (Number 0) (Number 1))))
……@@ -147,7 +150,7 @@
147150 ; one returns to original, unexposed state.
148151 ; Use one minus the probability of getting infected.
149152 (And
150 (Equal (ValueOf (Variable "$A") seir-state) (Concept "exposed"))
153 (Equal (ValueOf (Variable "$A") seir-state) exposed)
151154 (GreaterThan
152155 (Minus (Number 1)
153156 (ValueOf (Variable "$A") susceptibility))
……@@ -157,16 +160,16 @@
157160 ; If A is infected, then A has a chance of dying,
158161 ; depending on the infirmity.
159162 (And
160 (Equal (ValueOf (Variable "$A") seir-state) (Concept "infected"))
163 (Equal (ValueOf (Variable "$A") seir-state) infected)
161164 (GreaterThan
162165 (ValueOf (Variable "$A") infirmity)
163166 (RandomNumber (Number 0) (Number 1))))
164167 (SetValue (Variable "$A") seir-state died)
165168
166169 ; If A is infected, then A has a chance of recovering,
167 ; depending on the infirmity.
170 ; depending on the recovery-health strength.
168171 (And
169 (Equal (ValueOf (Variable "$A") seir-state) (Concept "infected"))
172 (Equal (ValueOf (Variable "$A") seir-state) infected)
170173 (GreaterThan
171174 (ValueOf (Variable "$A") recovery)
172175 (RandomNumber (Number 0) (Number 1))))
……@@ -354,20 +357,23 @@
354357(format #t "The social network consists of ~D individuals\n"
355358 (length individual-list))
356359
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.
359365(for-each
360366 (lambda (individual)
361367 (cog-set-value! individual seir-state susceptible)
362368 (cog-set-value! individual susceptibility
363 (cog-execute! (RandomNumber (Number 0.1) (Number 1))))
364 (cog-set-value! individual infirmity
365369 (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))))
366372 (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)))))
368374 individual-list)
369375
370; Pick one person, and make them infected
376; Pick one person, and make them infected.
371377(cog-set-value! (car individual-list) seir-state infected)
372378
373379; ---------------------------------------------------------------------