networks: Add sbn? and make-sbn.
This commit is contained in:
parent
c2237ecdbc
commit
218ecfc009
1 changed files with 21 additions and 2 deletions
23
networks.rkt
23
networks.rkt
|
@ -102,7 +102,8 @@
|
||||||
[tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?)
|
[tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?)
|
||||||
(listof (listof (or/c symbol? number?))))]
|
(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?)])
|
[tbn->network (-> tbn? network?)]
|
||||||
|
[make-sbn (-> (listof (cons/c variable? tbf/state?)) sbn?)])
|
||||||
;; Predicates
|
;; Predicates
|
||||||
(contract-out [variable? (-> any/c boolean?)]
|
(contract-out [variable? (-> any/c boolean?)]
|
||||||
[state? (-> any/c boolean?)]
|
[state? (-> any/c boolean?)]
|
||||||
|
@ -115,7 +116,8 @@
|
||||||
(contract-out [state/c contract?]
|
(contract-out [state/c contract?]
|
||||||
[update-function/c contract?]
|
[update-function/c contract?]
|
||||||
[domain-mapping/c contract?]
|
[domain-mapping/c contract?]
|
||||||
[tbn? contract?]))
|
[tbn? contract?]
|
||||||
|
[sbn? contract?]))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit))
|
(require rackunit))
|
||||||
|
@ -1249,6 +1251,23 @@
|
||||||
(hash 'a (tbf/state '#hash((a . -1)) -1)
|
(hash 'a (tbf/state '#hash((a . -1)) -1)
|
||||||
'b (tbf/state '#hash((a . 1)) 0)))))
|
'b (tbf/state '#hash((a . 1)) 0)))))
|
||||||
|
|
||||||
|
;;; A SBN is a network form mapping variables to sbf/state.
|
||||||
|
;;;
|
||||||
|
;;; The tbf/state must only reference variables appearing in the
|
||||||
|
;;; network. This contract does not check this condition.
|
||||||
|
(define sbn? (hash/c variable? sbf/state?))
|
||||||
|
|
||||||
|
;;; Builds an SBN from a list of pairs (variable, sbf/state).
|
||||||
|
(define make-sbn make-immutable-hash)
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "make-sbn"
|
||||||
|
(define sbf1 (make-sbf/state '((a . -1))))
|
||||||
|
(define sbf2 (make-sbf/state '((a . 1))))
|
||||||
|
(check-equal? (make-sbn `((a . ,sbf1) (b . ,sbf2)))
|
||||||
|
(hash 'a (tbf/state '#hash((a . -1)) 0)
|
||||||
|
'b (tbf/state '#hash((a . 1)) 0)))))
|
||||||
|
|
||||||
;;; Constructs a network from a network form defining a TBN.
|
;;; Constructs a network from a network form defining a TBN.
|
||||||
(define (tbn->network tbn)
|
(define (tbn->network tbn)
|
||||||
(for/hash ([(var tbf) (in-hash tbn)])
|
(for/hash ([(var tbf) (in-hash tbn)])
|
||||||
|
|
Loading…
Reference in a new issue