bn: Add bn-form->bn.
This commit is contained in:
parent
7a4dd09f40
commit
35abded486
2 changed files with 14 additions and 2 deletions
|
@ -35,4 +35,8 @@
|
|||
(test-case "Constructing networks from forms"
|
||||
(let ([s (make-state '((x . #t) (y . #f)))]
|
||||
[f (update-func-form->update-func '(and x y))])
|
||||
(check-equal? (f s) #f))))))
|
||||
(check-equal? (f s) #f))
|
||||
(let ([bn (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))]
|
||||
[s (make-state '((a . #t) (b . #t)))])
|
||||
(check-equal? ((hash-ref bn 'a) s)
|
||||
#t))))))
|
||||
|
|
10
bn.rkt
10
bn.rkt
|
@ -10,7 +10,8 @@
|
|||
(require "utils.rkt")
|
||||
|
||||
(provide Variable State UpdateFunc Network
|
||||
update make-state make-bn update-func-form->update-func)
|
||||
update make-state make-bn update-func-form->update-func
|
||||
bn-form->bn)
|
||||
|
||||
|
||||
;;; =================
|
||||
|
@ -72,3 +73,10 @@
|
|||
(define (update-func-form->update-func form)
|
||||
(lambda ([s : State])
|
||||
(cast (eval-with1 (cast s (HashTable Variable Any)) form) Boolean)))
|
||||
|
||||
;;; Build a Network from a Network form.
|
||||
(: bn-form->bn (-> NetworkForm Network))
|
||||
(define (bn-form->bn bnf)
|
||||
(make-hash
|
||||
(hash-map bnf (lambda ([x : Variable] [form : UpdateFuncForm])
|
||||
(cons x (update-func-form->update-func form))))))
|
||||
|
|
Loading…
Reference in a new issue