networks: Add and illustrate sbn-interaction-graph.

This commit is contained in:
Sergiu Ivanov 2020-11-08 22:56:46 +01:00
parent bc9a2bd5f8
commit 59c7108510
2 changed files with 42 additions and 1 deletions

View File

@ -1157,6 +1157,24 @@ tab
[[file:dots/exampleQLHMVK.svg]]
:end:
As usual, =dds= includes a specific function for constructing the
interaction graph of SBN. This function does not include the
thresholds of the SBF in the interaction graph.
#+NAME: sbn-figure2-ig
#+BEGIN_SRC racket :results silent drawer :var sbn-figure2=munch-sexp(sbn-figure2)
(dotit (sbn-interaction-graph (read-org-sbn sbn-figure2)))
#+END_SRC
#+BEGIN_SRC dot :file dots/exampleaSeyzw.svg :results raw drawer :cmd sfdp :noweb yes
<<sbn-figure2-ig()>>
#+END_SRC
#+RESULTS:
:results:
[[file:dots/exampleaSeyzw.svg]]
:end:
* Reaction systems
:PROPERTIES:
:header-args:racket: :prologue "#lang racket\n(require graph dds/rs dds/utils)"

View File

@ -129,7 +129,8 @@
(listof (listof (or/c number? symbol?))))]
[tbn-interaction-graph (->* (tbn?) (#:zero-edges boolean?)
graph?)]
[pretty-print-tbn-interaction-graph (-> graph? graph?)])
[pretty-print-tbn-interaction-graph (-> graph? graph?)]
[sbn-interaction-graph (-> sbn? graph?)])
;; Predicates
(contract-out [variable? (-> any/c boolean?)]
[state? (-> any/c boolean?)]
@ -1677,3 +1678,25 @@
(b . ,(make-tbf/state '((a . -1)) -1)))))
(check-equal? (graphviz (pretty-print-tbn-interaction-graph (tbn-interaction-graph tbn)))
"digraph G {\n\tnode0 [label=\"b:-1\"];\n\tnode1 [label=\"a:0\"];\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")))
;;; Given an SBN, constructs its interaction graph. As in
;;; tbn-interaction-graph, the nodes of this graph are labeled with
;;; the variable names, while the edges are labelled with the weights.
;;;
;;; If #:zero-edges is #t, the edges with zero weights will appear in
;;; the interaction graph.
(define (sbn-interaction-graph sbn
#:zero-edges [zero-edges #t])
(update-graph (tbn-interaction-graph sbn)
#:v-func (match-lambda
[(cons var _) var])))
(module+ test
(test-case "sbn-interaction-graph"
(define sbn (hash
'a
(tbf/state (hash 'b 2) 0)
'b
(tbf/state (hash 'a 2) 0)))
(check-equal? (graphviz (sbn-interaction-graph sbn))
"digraph G {\n\tnode0 [label=\"b\"];\n\tnode1 [label=\"a\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node1 [label=\"2\"];\n\t\tnode0 -> node0 [label=\"0\"];\n\t\tnode1 -> node1 [label=\"0\"];\n\t}\n\tsubgraph D {\n\t}\n}\n")))