networks: Add group-truth-table-by-nai.
This commit is contained in:
parent
59c7108510
commit
2b60b23bf1
1 changed files with 27 additions and 0 deletions
27
networks.rkt
27
networks.rkt
|
@ -106,6 +106,7 @@
|
||||||
(listof (listof (or/c symbol? number?))))]
|
(listof (listof (or/c symbol? number?))))]
|
||||||
[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?))))]
|
||||||
|
[group-truth-table-by-nai (-> (listof (listof (or/c 0 1))) (listof (listof (listof (or/c 0 1)))))]
|
||||||
[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?)]
|
[make-sbn (-> (listof (cons/c variable? tbf/state?)) sbn?)]
|
||||||
|
@ -1298,6 +1299,32 @@
|
||||||
(1 0 0)
|
(1 0 0)
|
||||||
(1 1 0)))))
|
(1 1 0)))))
|
||||||
|
|
||||||
|
;;; Given a truth table of a Boolean function, groups the lines by the
|
||||||
|
;;; "number of activated inputs"—the number of inputs which are 1 in
|
||||||
|
;;; the input vector.
|
||||||
|
;;;
|
||||||
|
;;; The truth table must not include the header line.
|
||||||
|
(define (group-truth-table-by-nai tt)
|
||||||
|
(define sum (((curry foldl) +) 0))
|
||||||
|
(group-by (λ (row) (drop-right row 1))
|
||||||
|
tt
|
||||||
|
(λ (in1 in2) (= (sum in1) (sum in2)))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "group-truth-table-by-nai"
|
||||||
|
(check-equal? (group-truth-table-by-nai '((0 0 0 1)
|
||||||
|
(0 0 1 1)
|
||||||
|
(0 1 0 0)
|
||||||
|
(0 1 1 1)
|
||||||
|
(1 0 0 0)
|
||||||
|
(1 0 1 0)
|
||||||
|
(1 1 0 1)
|
||||||
|
(1 1 1 0)))
|
||||||
|
'(((0 0 0 1))
|
||||||
|
((0 0 1 1) (0 1 0 0) (1 0 0 0))
|
||||||
|
((0 1 1 1) (1 0 1 0) (1 1 0 1))
|
||||||
|
((1 1 1 0))))))
|
||||||
|
|
||||||
;;; A TBN is a network form mapping variables to tbf/state.
|
;;; A TBN is a network form mapping variables to tbf/state.
|
||||||
;;;
|
;;;
|
||||||
;;; The tbf/state must only reference variables appearing in the
|
;;; The tbf/state must only reference variables appearing in the
|
||||||
|
|
Loading…
Reference in a new issue