networks: Add compact-tbf.
This commit is contained in:
parent
a00f21ad18
commit
f7e44df117
1 changed files with 14 additions and 1 deletions
15
networks.rkt
15
networks.rkt
|
@ -120,7 +120,8 @@
|
|||
tbn?)]
|
||||
[build-tbn-state-graph (-> tbn? graph?)]
|
||||
[normalized-tbn? (-> tbn? boolean?)]
|
||||
[normalize-tbn (-> tbn? normalized-tbn?)])
|
||||
[normalize-tbn (-> tbn? normalized-tbn?)]
|
||||
[compact-tbf (-> tbf/state? tbf/state?)])
|
||||
;; Predicates
|
||||
(contract-out [variable? (-> any/c boolean?)]
|
||||
[state? (-> any/c boolean?)]
|
||||
|
@ -1520,3 +1521,15 @@
|
|||
(tbf/state '#hash((a . 0) (b . 1)) 0)
|
||||
'b
|
||||
(tbf/state '#hash((a . -1) (b . 0)) -1)))))
|
||||
|
||||
;;; Compacts (and denormalizes) a TBF by removing all inputs which
|
||||
;;; are 0.
|
||||
(define (compact-tbf tbf)
|
||||
(tbf/state
|
||||
(hash-filter (tbf/state-w tbf) #:predicate (compose not zero?))
|
||||
(tbf/state-θ tbf)))
|
||||
|
||||
(module+ test
|
||||
(test-case "compact-tbf"
|
||||
(check-equal? (compact-tbf (tbf/state (hash 'a 0 'b 1 'c 2 'd 0) 2))
|
||||
(tbf/state '#hash((b . 1) (c . 2)) 2))))
|
||||
|
|
Loading…
Reference in a new issue