OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 8ec81f5

Remove the alternate-demo. Its verbose, its confusing.
8ec81f552df50638747670d72036c158177d1c5f
by Linas Vepstas <linasvepstas@gmail.com> · 2020-04-22T16:23:47.000Z

Changed files (1) +28 -63

demo/seir.scm +28 -63
……@@ -405,63 +405,8 @@
405405(format #t "Found a network of size ~D\n" (cog-arity (gar just-one)))
406406
407407; ---------------------------------------------------------------------
408; Assign initial susceptibility and infirmity values to individuals
409; in the network. These will be randomly generated numbers.
410;
411; This will be done twice, illustrating two different styles of coding.
412; The first style is a traditional, scheme list (srfi-1) style of
413; coding, something that a naive coder might attempt. (This is not
414; scheme-specific; python coders might code the same way, if this
415; demo was written in python.) Despite every attempt to "keep it
416; simple", this code quickly becomes opaque and hard to understand.
417; Thus, the first thing shown is NOT the recommended style.
418;
419; The second time, it will be done in Atomese. The code is recognizably
420; identical to the first attempt, but with far fewer calls to srfi-1
421; routines to manage and transform lists. This is because Atomese,
422; and specifically, the Atomese query language, is far more compact in
423; managing state. You don't have to juggle things around with maps
424; and lists and functions -- the query language manages all this,
425; automatically.
426;
427; ----------
428; So: version 1: traditional software proramming style.
429
430; Each individual is linked back to the anchor node. Each individual
431; is also represented with a ConceptNode (we have some other junk
432; also attached to the anchor, so filter that out.)
433(define individual-list
434 (filter (lambda (ind) (equal? (cog-type ind) 'ConceptNode))
435 (map gar (cog-incoming-by-type anchor 'MemberLink))))
408; A handy utility. We need this for the rest of the demo.
436409
437(format #t "The social network consists of ~D individuals\n"
438 (length individual-list))
439
440; Assign to each individual the state of "initially healthy".
441; Choose some random numbers for the overall population health:
442; some random susceptibility (the probability of becoming ill after
443; being exposed), the infirmity (probability of illness leading to
444; death) and a probability of recovering from illness.
445(for-each
446 (lambda (individual)
447 (cog-set-value! individual seir-state susceptible)
448 (cog-set-value! individual susceptibility
449 (cog-execute! (RandomNumber (Number 0.2) (Number 0.8))))
450 (cog-set-value! individual infirmity
451 (cog-execute! (RandomNumber (Number 0.01) (Number 0.55))))
452 (cog-set-value! individual recovery
453 (cog-execute! (RandomNumber (Number 0.6) (Number 0.95)))))
454 individual-list)
455
456; ----------
457; So: version 2: Atomese query language proramming style.
458
459; The above uses a very traditional scheme `for-each` loop to perform
460; the initialization. The Atomese query language automatically iterates
461; over the entire contents of the AtomSpace, so this loop is not
462; explicitly needed.
463
464; ------ But first, a handy utility:
465410; Execute some Atomese. Assume that it returns a SetLink.
466411; Unwrap the SetLink, discard it, return the contents.
467412(define (exec-unwrap ATOMESE)
……@@ -470,13 +415,23 @@
470415 (cog-delete set-link)
471416 contents)
472417
473; ---------
474
475; Here's the Atomese version of the above. This performs a search of the
476; AtomSpace, locating all individuals. They are easy to identify: each
477; individual was previously anchored via a MemberLink. The DeleteLink
478; runs the contents inside of it, but then deletes the return value.
479; This is handy, to avoid garbage from accumulating in the AtomSpace.
418; ---------------------------------------------------------------------
419; Initialize the network.
420;
421; Assign to each individual the state of "initially healthy".
422; Choose some random numbers for the overall population health:
423; some random susceptibility (the probability of becoming ill after
424; being exposed), the infirmity (probability of illness leading to
425; death) and a probability of recovering from illness.
426;
427; The initialization is done with a graph-query and graph-rewrite
428; run over the AtomSpace. The query is simple: find all individuals
429; attached with a `MemberLink` to an anchor node. The rewrite is
430; trickier: its a `DeleteLink` whose contents are executed first.
431; The contents perform the intialization of each individual that is
432; found. The DeleteLink then just discards the wrapper ListLink.
433; We didn't actually need to discard it, but it seems nice to not
434; leave ponitless garbage lying round in the AtomSpace.
480435
481436(define (initialize-state)
482437 (exec-unwrap
……@@ -498,6 +453,16 @@
498453(initialize-state)
499454
500455; ---------
456; Each individual is linked back to the anchor node. Each individual
457; is also represented with a ConceptNode (we have some other junk
458; also attached to the anchor, so filter that out.)
459(define individual-list
460 (filter (lambda (ind) (equal? (cog-type ind) 'ConceptNode))
461 (map gar (cog-incoming-by-type anchor 'MemberLink))))
462
463(format #t "The social network consists of ~D individuals\n"
464 (length individual-list))
465
501466; Pick one person, and make them infected.
502467(cog-set-value! (car individual-list) seir-state infected)
503468