bn: Add make-bn-forms.
This commit is contained in:
parent
608b606717
commit
f0a7c270e9
2 changed files with 17 additions and 4 deletions
|
@ -36,7 +36,9 @@
|
||||||
(let ([s (make-state '((x . #t) (y . #f)))]
|
(let ([s (make-state '((x . #t) (y . #f)))]
|
||||||
[f (update-func-form->update-func '(and x y))])
|
[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)))))]
|
(let ([bn1 (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))]
|
||||||
|
[bn2 (make-bn-forms '((a . (and a b))
|
||||||
|
(b . (not b))))]
|
||||||
[s (make-state '((a . #t) (b . #t)))])
|
[s (make-state '((a . #t) (b . #t)))])
|
||||||
(check-equal? ((hash-ref bn 'a) s)
|
(check-equal? ((hash-ref bn1 'a) s) #t)
|
||||||
#t))))))
|
(check-equal? ((hash-ref bn2 'a) s) #t))))))
|
||||||
|
|
13
bn.rkt
13
bn.rkt
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
(provide Variable State UpdateFunc Network
|
(provide Variable State UpdateFunc Network
|
||||||
update make-state make-bn-funcs update-func-form->update-func
|
update make-state make-bn-funcs update-func-form->update-func
|
||||||
bn-form->bn)
|
bn-form->bn make-bn-forms)
|
||||||
|
|
||||||
|
|
||||||
;;; =================
|
;;; =================
|
||||||
|
@ -80,3 +80,14 @@
|
||||||
(make-hash
|
(make-hash
|
||||||
(hash-map bnf (lambda ([x : Variable] [form : UpdateFuncForm])
|
(hash-map bnf (lambda ([x : Variable] [form : UpdateFuncForm])
|
||||||
(cons x (update-func-form->update-func form))))))
|
(cons x (update-func-form->update-func form))))))
|
||||||
|
|
||||||
|
;;; Build a network from a list of pairs of forms of update functions.
|
||||||
|
(: make-bn-forms (-> (Listof (Pairof Variable UpdateFuncForm)) Network))
|
||||||
|
(define (make-bn-forms forms)
|
||||||
|
(bn-form->bn (make-hash forms)))
|
||||||
|
|
||||||
|
(let ([bn (make-bn-forms '((a . (and a b))
|
||||||
|
(b . (not b))))]
|
||||||
|
[s (make-state '((a . #t)
|
||||||
|
(b . #t)))])
|
||||||
|
((hash-ref bn 'a) s))
|
||||||
|
|
Loading…
Reference in a new issue