networks: Add tbn->network.

This commit is contained in:
Sergiu Ivanov 2020-10-16 00:55:26 +02:00
parent 119fcdb8df
commit c2237ecdbc
1 changed files with 16 additions and 1 deletions

View File

@ -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))))))