Skip to content

Commit

Permalink
Finish up work on he Markov chain
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Apr 18, 2015
1 parent 874d349 commit 8f81c2d
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions examples/pattern-matcher/markov-chain.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
; In either viewpoint, the numbers, which are probabilities, are
; stored in the "strength" portion of a SimpleTruthValue.
;
; XXX Right now, this demo is broken/unfinished! It doesn't work! XXX
;
; The run this, you probably need to do this:
;
; OCDIR=home/home/yourname/opencog
Expand Down Expand Up @@ -277,23 +275,23 @@
(VariableNode "$state")
(ImplicationLink
;; Find the state vector...
(ListLink
chain-state
(VariableNode "$state")
)
(ListLink chain-state (VariableNode "$state"))
;; Delete the state vector.
(DeleteLink
(ListLink
chain-state
(VariableNode "$state")
)
(ListLink chain-state (VariableNode "$state"))
)
)
)
)

;; --------------------------------------------------------------------
;; Copy a state vector from chain-from to chain-to
;; Since the TV's carry the probabilities, they must be copied.

;; Copy TV from second atom to first
(define (copy-tv b a)
(begin (cog-set-tv! b (cog-tv a)) b))

(define (create-chain-copier chain-to chain-from)
(BindLink
(VariableNode "$state")
Expand All @@ -304,9 +302,14 @@
(VariableNode "$state")
)
;; Copy it to the copy-to state vector.
(ListLink
chain-to
(VariableNode "$state")
;; We need to use an execution-output link to copy
;; the tv values from one to the other.
(ExecutionOutputLink
(GroundedSchemaNode "scm:copy-tv")
(ListLink
(ListLink chain-to (VariableNode "$state"))
(ListLink chain-from (VariableNode "$state"))
)
)
)
)
Expand All @@ -318,7 +321,13 @@
;; It should be a bit faster.
(define (create-chain-move chain-to chain-from)
(BindLink
(VariableNode "$state")
; Constrain the allowed types on the variable;
; we only want to copy the actual state, and not
; (for example) the subgraphs of this link.
(TypedVariableLink
(VariableNode "$state")
(TypeNode "ConceptNode")
)
(ImplicationLink
;; Find the copy-from state vector...
(ListLink
Expand All @@ -327,16 +336,18 @@
)
(AndLink
;; Copy it to the copy-to state vector.
(ListLink
chain-to
(VariableNode "$state")
;; We need to use an execution-output link to copy
;; the tv values from one to the other.
(ExecutionOutputLink
(GroundedSchemaNode "scm:copy-tv")
(ListLink
(ListLink chain-to (VariableNode "$state"))
(ListLink chain-from (VariableNode "$state"))
)
)
;; Delete the copy-from state vector
(DeleteLink
(ListLink
chain-from
(VariableNode "$state")
)
(ListLink chain-from (VariableNode "$state"))
)
)
)
Expand Down Expand Up @@ -382,18 +393,20 @@
(define my-delter (create-chain-deleter my-state))
(define my-mover (create-chain-move my-state my-nexts))
(cog-bind my-stepper)
(show-state my-nexts)
; (show-state my-nexts)
(cog-bind my-delter)
(cog-bind my-mover)
(show-state my-state)
)

;;; Show the initial state
; (show-state)
; (show-state my-state)

;;; Take one step.
;(take-a-step)

;;; Take three steps.
;;; Try it!
;(take-a-step)
;(take-a-step)
;(take-a-step)

0 comments on commit 8f81c2d

Please sign in to comment.