OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 3627a4e

An alternative Atomese initialization
3627a4eaf1d2dcbc4eb69c42f3a0529189a69be9
by Linas Vepstas <linasvepstas@gmail.com> · 2020-04-22T01:45:02.000Z

Changed files (1) +41 -10

demo/seir.scm +41 -10
……@@ -415,6 +415,47 @@
415415 (cog-execute! (RandomNumber (Number 0.6) (Number 0.95)))))
416416 individual-list)
417417
418; The above uses a very traditional scheme `for-each` loop to perform
419; the initialization. This could also be done directly, in Atomese, as
420; shown below.
421
422; ------ But first, a handy utility:
423; Execute some Atomese. Assume that it returns a SetLink.
424; Unwrap the SetLink, discard it, return the contents.
425(define (exec-unwrap ATOMESE)
426 (define set-link (cog-execute! ATOMESE))
427 (define contents (cog-outgoing-set set-link))
428 (cog-delete set-link)
429 contents)
430
431; ---------
432
433; Here's the Atomese version of the above. This performs a search of the
434; AtomSpace, locating all individuals. They are easy to identify: each
435; individual was previously anchored via a MemberLink. The DeleteLink
436; runs the contents inside of it, but then deletes the return value.
437; This is handy, to avoid garbage from accumulating in the AtomSpace.
438
439(define (initialize-state)
440 (exec-unwrap
441 (Bind
442 (TypedVariable (Variable "$person") (Type "ConceptNode"))
443 (Present (Member (Variable "$person") anchor))
444 (Delete (List
445 (SetValue (Variable "$person") seir-state susceptible)
446 (SetValue (Variable "$person") susceptibility
447 (RandomNumber (Number 0.2) (Number 0.8)))
448 (SetValue (Variable "$person") infirmity
449 (RandomNumber (Number 0.01) (Number 0.55)))
450 (SetValue (Variable "$person") recovery
451 (RandomNumber (Number 0.6) (Number 0.95)))
452 ))))
453 *unspecified*)
454
455; Run the above.
456(initialize-state)
457
458; ---------
418459; Pick one person, and make them infected.
419460(cog-set-value! (car individual-list) seir-state infected)
420461
……@@ -454,16 +495,6 @@
454495; second way is ultimately simpler, and provides better automation,
455496; but both ways are illustrated, for comparison.
456497
457; ------ But first, a handy utility:
458; Execute some Atomese. Assume that it returns a SetLink.
459; Unwrap the SetLink, discard it, return the contents.
460(define (exec-unwrap ATOMESE)
461 (define set-link (cog-execute! ATOMESE))
462 (define contents (cog-outgoing-set set-link))
463 (cog-delete set-link)
464 contents)
465
466; ---------
467498; A function that runs the transmission step once. This is written
468499; using a scheme `for-each` loop to iterate over all encounters.
469500; It requires, as input, the list of all relations created above.