networks: build-interaction-graph → build-syntactic-interaction-graph.

The interaction graph is *not* usually defined in this way.
This commit is contained in:
Sergiu Ivanov 2020-11-11 00:45:01 +01:00
parent af581f91df
commit cde6ee30fa
2 changed files with 29 additions and 10 deletions

View file

@ -356,7 +356,7 @@ tab
Some functions in =dds= build graphs:
#+BEGIN_SRC racket :results output drawer :var bf=munch-sexp(another-test-table)
(build-interaction-graph (unorgv bf))
(build-syntactic-interaction-graph (unorgv bf))
#+END_SRC
#+RESULTS:
@ -372,7 +372,7 @@ tab
#+NAME: igraph
#+BEGIN_SRC racket :results output drawer :var bf=munch-sexp(another-test-table)
(display (graphviz (build-interaction-graph (unorgv bf))))
(display (graphviz (build-syntactic-interaction-graph (unorgv bf))))
#+END_SRC
#+RESULTS: igraph
@ -433,10 +433,10 @@ tab
because 0 is not #f. For example, =(if 0 1 2)= evaluates to 1, and
not to 2.
Here's the unsigned interaction graph of this network:
Here's the unsigned syntactic interaction graph of this network:
#+NAME: simple-bn-ig
#+BEGIN_SRC racket :results silent :var simple-bn=munch-sexp(simple-bn)
(dotit (build-interaction-graph (unorgv simple-bn)))
(dotit (build-syntactic-interaction-graph (unorgv simple-bn)))
#+END_SRC
#+BEGIN_SRC dot :file dots/examplejTo8XT.svg :results raw drawer :cmd sfdp :noweb yes
@ -448,6 +448,15 @@ tab
[[file:dots/examplejTo8XT.svg]]
:END:
Note that, while this definition is an easy one to check
structurally, this is *not* how interaction graphs are typically
defined. An interaction graph is usually defined based on the
dynamics of the network: an arrow from a variable x to a variable
y means that varying x and only x may have an influence on the
value of y. It is easy to imagine a situation in which the
syntactic interaction graph does not in fact agree with this
criterion, the simplest example being the network y = x \wedge \neg x.
Here's the signed interaction graph of this network:
#+NAME: simple-bn-sig

View file

@ -29,7 +29,7 @@
[make-network-from-forms (-> (listof (cons/c symbol? update-function-form?))
network?)]
[list-interactions (-> network-form? variable? (listof variable?))]
[build-interaction-graph (-> network-form? graph?)]
[build-syntactic-interaction-graph (-> network-form? graph?)]
[build-all-states (-> domain-mapping/c (listof state?))]
[make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)]
[make-boolean-domains (-> (listof variable?) (hash/c variable? (list/c #f #t)))]
@ -304,16 +304,26 @@
;;; Builds the graph in which the vertices are the variables of a
;;; given network, and which contains an arrow from a to b whenever a
;;; appears in (list-interactions a).
(define (build-interaction-graph n)
;;;
;;; Note that, while this definition is an easy one to check
;;; structurally, this is *not* how interaction graphs are typically
;;; defined. An interaction graph is usually defined based on the
;;; dynamics of the network: an arrow from a variable x to a variable
;;; y means that varying x and only x may have an influence on the
;;; value of y. It is easy to imagine a situation in which the
;;; syntactic interaction graph does not in fact agree with this
;;; criterion, the simplest example being the network y = x AND (NOT
;;; x).
(define (build-syntactic-interaction-graph n)
(transpose
(unweighted-graph/adj
(for/list ([(var _) n]) (cons var (list-interactions n var))))))
(module+ test
(test-case "build-interaction-graph"
(test-case "build-syntactic-interaction-graph"
(define n #hash((a . (+ a b c))
(b . (- b c))))
(define ig (build-interaction-graph n))
(define ig (build-syntactic-interaction-graph n))
(check-true (has-vertex? ig 'a))
(check-true (has-vertex? ig 'b))
(check-false (has-vertex? ig 'c))
@ -456,7 +466,7 @@
;;; network for every arrow in the unsigned interaction graph, so its
;;; performance decreases very quickly with the size of the network.
(define (build-signed-interaction-graph/form network-form doms)
(let ([ig (build-interaction-graph network-form)]
(let ([ig (build-syntactic-interaction-graph network-form)]
[network (network-form->network network-form)])
;; Label every edge of the interaction graph with the sign.
(define sig
@ -567,7 +577,7 @@
(module+ test
(test-case "Interaction must graphs always contain all nodes."
(define n #hash((a . #t) (b . #t)))
(define ig (build-interaction-graph n))
(define ig (build-syntactic-interaction-graph n))
(define sig-nf (build-boolean-signed-interaction-graph/form n))
(define sig (build-boolean-signed-interaction-graph (network-form->network n)))
(check-equal? (get-vertices ig) '(b a))