Type build-syntactic-interaction-graph.
This commit is contained in:
parent
0018c91fb6
commit
8722d63d3e
2 changed files with 36 additions and 38 deletions
61
networks.rkt
61
networks.rkt
|
@ -23,7 +23,7 @@
|
|||
network-form->network/01 make-boolean-network-form
|
||||
forms->boolean-network
|
||||
|
||||
list-syntactic-interactions
|
||||
list-syntactic-interactions build-syntactic-interaction-graph
|
||||
)
|
||||
|
||||
(define-type (State a) (VariableMapping a))
|
||||
|
@ -254,6 +254,27 @@
|
|||
(b . (- b c)))))
|
||||
(check-true (set=? (list-syntactic-interactions n 'a) '(a b)))
|
||||
(check-true (set=? (list-syntactic-interactions n 'b) '(b)))))
|
||||
|
||||
(: build-syntactic-interaction-graph (All (a) (-> (NetworkForm a) Graph)))
|
||||
(define (build-syntactic-interaction-graph n)
|
||||
(transpose
|
||||
(unweighted-graph/adj
|
||||
(for/list ([(var _) (in-hash (network-form-forms n))])
|
||||
(cons var (list-syntactic-interactions n var))))))
|
||||
|
||||
(module+ test
|
||||
(test-case "build-syntactic-interaction-graph"
|
||||
(define n (make-boolean-network-form #hash((a . (+ a b c))
|
||||
(b . (- b c)))))
|
||||
(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))
|
||||
(check-true (has-edge? ig 'a 'a))
|
||||
(check-true (has-edge? ig 'b 'a))
|
||||
(check-true (has-edge? ig 'b 'b))
|
||||
(check-false (has-edge? ig 'c 'b))
|
||||
(check-false (has-edge? ig 'c 'a))))
|
||||
)
|
||||
|
||||
(require 'typed)
|
||||
|
@ -270,8 +291,7 @@
|
|||
[struct dynamics ([network network?]
|
||||
[mode mode?])])
|
||||
;; Functions
|
||||
(contract-out [build-syntactic-interaction-graph (-> network-form? graph?)]
|
||||
[interaction? (-> network? variable? variable? boolean?)]
|
||||
(contract-out [interaction? (-> network? variable? variable? boolean?)]
|
||||
[get-interaction-sign (-> network? variable? variable? (or/c #f -1 0 1))]
|
||||
[build-interaction-graph (-> network? graph?)]
|
||||
[build-interaction-graph/form (-> network-form? graph?)]
|
||||
|
@ -420,41 +440,6 @@
|
|||
;;; Inferring interaction graphs
|
||||
;;; ============================
|
||||
|
||||
|
||||
|
||||
;;; 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).
|
||||
;;;
|
||||
;;; 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 _) (in-hash (network-form-forms n))])
|
||||
(cons var (list-syntactic-interactions n var))))))
|
||||
|
||||
(module+ test
|
||||
(test-case "build-syntactic-interaction-graph"
|
||||
(define n (make-boolean-network-form #hash((a . (+ a b c))
|
||||
(b . (- b c)))))
|
||||
(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))
|
||||
(check-true (has-edge? ig 'a 'a))
|
||||
(check-true (has-edge? ig 'b 'a))
|
||||
(check-true (has-edge? ig 'b 'b))
|
||||
(check-false (has-edge? ig 'c 'b))
|
||||
(check-false (has-edge? ig 'c 'a))))
|
||||
|
||||
;;; Given a hash-set mapping variables to generic sets of their
|
||||
;;; possible values, constructs the list of all possible states.
|
||||
(define (build-all-states vars-domains)
|
||||
|
|
|
@ -366,6 +366,19 @@ The variables which are not part of the network are excluded from the listing.
|
|||
'a)
|
||||
]}
|
||||
|
||||
@defproc[(build-syntactic-interaction-graph [n (NetworkForm a)])
|
||||
Graph]{
|
||||
|
||||
Builds the graph in which the vertices are the variables of a given network,
|
||||
and which contains an arrow from @racket[x] to @racket[y] whenever @racket[x]
|
||||
appears in @racket[(list-interactions y)].
|
||||
|
||||
@ex[
|
||||
(require (only-in "utils.rkt" dotit))
|
||||
(dotit (build-syntactic-interaction-graph
|
||||
(make-boolean-network-form #hash((a . (+ a b))
|
||||
(b . (- b))))))
|
||||
]}
|
||||
|
||||
@section{Dynamics of networks}
|
||||
|
||||
|
|
Loading…
Reference in a new issue