Type pretty-print-tbn-interaction-graph.
This commit is contained in:
parent
ac7f928737
commit
e9ecbd8a7c
2 changed files with 25 additions and 1 deletions
|
@ -436,6 +436,17 @@ will also appear in the interaction graph.
|
||||||
#:zero-edges #f))
|
#:zero-edges #f))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(pretty-print-tbn-interaction-graph [ig Graph]) Graph]{
|
||||||
|
|
||||||
|
Pretty prints the node labels of the interaction graph of a TBN.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(dotit (pretty-print-tbn-interaction-graph
|
||||||
|
(tbn-interaction-graph (hash 'a (tbf/state (hash 'b 1) 0)
|
||||||
|
'b (tbf/state (hash 'a -1) -1)))))
|
||||||
|
]}
|
||||||
|
|
||||||
|
|
||||||
@section{Reading and printing TBNs and SBNs}
|
@section{Reading and printing TBNs and SBNs}
|
||||||
|
|
||||||
@defproc[(parse-org-tbn [tab (Listof (Listof (U Symbol Real)))]
|
@defproc[(parse-org-tbn [tab (Listof (Listof (U Symbol Real)))]
|
||||||
|
|
15
tbn.rkt
15
tbn.rkt
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
TBN sbn? tbn->network
|
TBN sbn? tbn->network
|
||||||
build-tbn-state-graph normalized-tbn? normalize-tbn compact-tbn
|
build-tbn-state-graph normalized-tbn? normalize-tbn compact-tbn
|
||||||
tbn-interaction-graph
|
tbn-interaction-graph pretty-print-tbn-interaction-graph
|
||||||
parse-org-tbn read-org-tbn read-org-sbn tbn->lists sbn->lists
|
parse-org-tbn read-org-tbn read-org-sbn tbn->lists sbn->lists
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -524,6 +524,19 @@
|
||||||
(check-equal? (graphviz (tbn-interaction-graph tbn #:zero-edges #f))
|
(check-equal? (graphviz (tbn-interaction-graph tbn #:zero-edges #f))
|
||||||
"digraph G {\n\tnode0 [label=\"'(b . -1)\"];\n\tnode1 [label=\"'(a . 0)\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"1\"];\n\t\tnode1 -> node0 [label=\"-1\"];\n\t}\n}\n")))
|
"digraph G {\n\tnode0 [label=\"'(b . -1)\"];\n\tnode1 [label=\"'(a . 0)\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"1\"];\n\t\tnode1 -> node0 [label=\"-1\"];\n\t}\n}\n")))
|
||||||
|
|
||||||
|
(: pretty-print-tbn-interaction-graph (-> Graph Graph))
|
||||||
|
(define (pretty-print-tbn-interaction-graph ig)
|
||||||
|
(update-graph ig #:v-func (match-lambda
|
||||||
|
[(cons var weight) (~a var ":" weight)])))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "pretty-print-tbn-interaction-graph"
|
||||||
|
(define tbn (hash 'a (tbf/state (hash 'b 1) 0)
|
||||||
|
'b (tbf/state (hash 'a -1) -1)))
|
||||||
|
(check-equal? (graphviz (pretty-print-tbn-interaction-graph
|
||||||
|
(tbn-interaction-graph tbn)))
|
||||||
|
"digraph G {\n\tnode0 [label=\"a:0\"];\n\tnode1 [label=\"b:-1\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"0\"];\n\t\tnode1 -> node1 [label=\"0\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node1 [label=\"-1\"];\n\t\tnode1 -> node0 [label=\"1\"];\n\t}\n}\n")))
|
||||||
|
|
||||||
(: parse-org-tbn (->* ((Listof (Listof (U Symbol Real))))
|
(: parse-org-tbn (->* ((Listof (Listof (U Symbol Real))))
|
||||||
(#:headers Boolean
|
(#:headers Boolean
|
||||||
#:func-names Boolean)
|
#:func-names Boolean)
|
||||||
|
|
Loading…
Reference in a new issue