networks: Add tbn->network.
This commit is contained in:
parent
119fcdb8df
commit
c2237ecdbc
1 changed files with 16 additions and 1 deletions
17
networks.rkt
17
networks.rkt
|
@ -101,7 +101,8 @@
|
|||
(listof (listof (or/c symbol? number?))))]
|
||||
[tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?)
|
||||
(listof (listof (or/c symbol? number?))))]
|
||||
[make-tbn (-> (listof (cons/c variable? tbf/state?)) tbn?)])
|
||||
[make-tbn (-> (listof (cons/c variable? tbf/state?)) tbn?)]
|
||||
[tbn->network (-> tbn? network?)])
|
||||
;; Predicates
|
||||
(contract-out [variable? (-> any/c boolean?)]
|
||||
[state? (-> any/c boolean?)]
|
||||
|
@ -1247,3 +1248,17 @@
|
|||
(check-equal? (make-tbn `((a . ,tbf-not) (b . ,tbf-id)))
|
||||
(hash 'a (tbf/state '#hash((a . -1)) -1)
|
||||
'b (tbf/state '#hash((a . 1)) 0)))))
|
||||
|
||||
;;; Constructs a network from a network form defining a TBN.
|
||||
(define (tbn->network tbn)
|
||||
(for/hash ([(var tbf) (in-hash tbn)])
|
||||
(values var ((curry apply-tbf/state) tbf))))
|
||||
|
||||
(module+ test
|
||||
(test-case "tbn->network"
|
||||
(define tbn (make-tbn `((a . ,(make-sbf/state '((b . 1))))
|
||||
(b . ,(make-tbf/state '((a . -1)) -1)))))
|
||||
(define n (tbn->network tbn))
|
||||
(define s1 (make-state '((a . 0) (b . 0))))
|
||||
(check-equal? (update n s1 '(a b))
|
||||
(make-state '((a . 0) (b . 1))))))
|
||||
|
|
Loading…
Reference in a new issue