OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 7d5f2da

Move around the intialization
7d5f2da88d36614953d248ed6dff4fab3c449858
by Linas Vepstas <linasvepstas@gmail.com> · 2020-04-22T16:35:41.000Z

Changed files (1) +16 -21

demo/seir.scm +16 -21
……@@ -452,20 +452,6 @@
452452; Run the above.
453453(initialize-state)
454454
455; ---------
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
466; Pick one person, and make them infected.
467(cog-set-value! (car individual-list) seir-state infected)
468
469455; ---------------------------------------------------------------------
470456; Reporting statistics.
471457;
……@@ -510,14 +496,13 @@
510496 *unspecified*)
511497
512498; ---------------------------------------------------------------------
513; Start applying state transition rules to the network.
499; Apply state transition rules to the network.
514500;
515; State transitions, applied as rewrite rules, run over the AtomSpace.
516; Instead of iterating over scheme lists of relations and individuals,
517; the code below searches the AtomSpace directly for the relevant
518; relations and individuals. This is more elegant than monkeying around
519; with scheme code. It operates by applying graph rewrite rules directly
520; to the AtomSpace, where the data actually lives.
501; The state transition rules drive the actual simulation. These rules
502; are applied as graph rewrite rules, running over the AtomSpace.
503; There are two rules to apply. One rule that runs over all pairs,
504; transmitting disease from one individual to another. The other rule
505; updates the individual state, from exposed to infected to resolved.
521506
522507; Search for all pairs, and apply the transmission rule.
523508(define (do-transmission)
……@@ -551,6 +536,16 @@
551536 (Variable "$person"))))
552537 *unspecified*)
553538
539; Oh, but first, pick one person, and make them infected!
540(define everyone (get-individuals-in-state susceptible))
541(define one-person (first everyone))
542(cog-execute! (SetValue one-person seir-state infected))
543
544; Start the simulation. Run several steps by hand, to get the
545; hang of it.
546(do-transmission) (report-stats)
547(do-state-transition) (report-stats)
548
554549(do-transmission) (report-stats)
555550(do-state-transition) (report-stats)
556551