From aca3fb78683e543d5996824fab9be35b7d0ba00f Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 7 Aug 2023 20:06:30 +0200 Subject: [PATCH] Add sbn->lists. --- scribblings/tbn.scrbl | 13 +++++++++++++ tbn.rkt | 26 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index 6c7022b..4ae9356 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -526,6 +526,19 @@ the first cell of the first column contains the symbol 'b (tbf/state (hash 'a -1) -1))) ]} +@defproc[(sbn->lists [sbn TBN] + [#:headers headers Boolean #t] + [#:func-names func-names Boolean #t]) + (Listof (Listof (U Symbol Real)))]{ + +Like @racket[tbn->lists], but does not show the thresholds—an +adaptation for printing SBNs. + +@ex[ +(sbn->lists (hash 'a (tbf/state (hash 'b 1) 0) + 'b (tbf/state (hash 'a -1) 0))) +]} + @section{Miscellaneous utilities} @defproc[(group-truth-table-by-nai [tt (Listof (Listof Integer))]) diff --git a/tbn.rkt b/tbn.rkt index a0debc6..76f65a2 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -48,7 +48,7 @@ TBN sbn? tbn->network build-tbn-state-graph normalized-tbn? normalize-tbn compact-tbn - parse-org-tbn read-org-tbn read-org-sbn tbn->lists + parse-org-tbn read-org-tbn read-org-sbn tbn->lists sbn->lists ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -639,6 +639,30 @@ '((a b θ) (0 1 0) (-1 0 -1))) (check-equal? (tbn->lists tbn #:headers #f #:func-names #f) '((0 1 0) (-1 0 -1))))) + + (: sbn->lists (->* (TBN) (#:headers Boolean + #:func-names Boolean) + (Listof (Listof (U Symbol Real))))) + (define (sbn->lists sbn + #:headers [headers #t] + #:func-names [func-names #t]) + (define tab (tbn->lists sbn #:headers headers #:func-names func-names)) + (define-values (tab-no-θ _) + (multi-split-at tab (sub1 (length (car tab))))) + tab-no-θ) + + (module+ test + (test-case "sbn->lists" + (define sbn (hash 'a (tbf/state (hash 'b 2) 0) + 'b (tbf/state (hash 'a 2) 0))) + (check-equal? (sbn->lists sbn) + '((- a b) (a 0 2) (b 2 0))) + (check-equal? (sbn->lists sbn #:headers #f) + '((a 0 2) (b 2 0))) + (check-equal? (sbn->lists sbn #:func-names #f) + '((a b) (0 2) (2 0))) + (check-equal? (sbn->lists sbn #:headers #f #:func-names #f) + '((0 2) (2 0))))) ) (module+ test