networks: Ensure that all variables always appear in the interaction graphs.
This commit is contained in:
parent
6c707ddba7
commit
82def3b704
2 changed files with 35 additions and 13 deletions
|
@ -114,7 +114,16 @@
|
||||||
(check-equal? (edge-weight sig3 'a 'a) '+)
|
(check-equal? (edge-weight sig3 'a 'a) '+)
|
||||||
(check-equal? (edge-weight sig3 'b 'b) '+)
|
(check-equal? (edge-weight sig3 'b 'b) '+)
|
||||||
(check-equal? (edge-weight sig3 'a 'b) '+)
|
(check-equal? (edge-weight sig3 'a 'b) '+)
|
||||||
(check-equal? (edge-weight sig3 'b 'a) '-)))
|
(check-equal? (edge-weight sig3 'b 'a) '-))
|
||||||
|
(let* ([n #hash((a . #t) (b . #t))]
|
||||||
|
[ig (build-interaction-graph n)]
|
||||||
|
[sig-nf (build-boolean-signed-interaction-graph/form n)]
|
||||||
|
[sig (build-boolean-signed-interaction-graph (network-form->network n))])
|
||||||
|
(check-equal? (get-vertices ig) '(b a))
|
||||||
|
(check-true (empty? (get-edges ig)))
|
||||||
|
(check-equal? (get-vertices sig-nf) '(b a))
|
||||||
|
(check-true (empty? (get-edges sig-nf)))
|
||||||
|
(check-equal? (get-vertices sig) '(b a))))
|
||||||
|
|
||||||
(test-case "Dynamics of networks"
|
(test-case "Dynamics of networks"
|
||||||
(check-equal? (pretty-print-state (make-state '((a . #f) (b . 3) (c . 4)))) "a:#f b:3 c:4")
|
(check-equal? (pretty-print-state (make-state '((a . #f) (b . 3) (c . 4)))) "a:#f b:3 c:4")
|
||||||
|
|
15
networks.rkt
15
networks.rkt
|
@ -286,11 +286,18 @@
|
||||||
(define (build-signed-interaction-graph/form network-form doms)
|
(define (build-signed-interaction-graph/form network-form doms)
|
||||||
(let ([ig (build-interaction-graph network-form)]
|
(let ([ig (build-interaction-graph network-form)]
|
||||||
[network (network-form->network network-form)])
|
[network (network-form->network network-form)])
|
||||||
|
;; Label every edge of the interaction graph with the sign.
|
||||||
|
(define sig
|
||||||
(weighted-graph/directed
|
(weighted-graph/directed
|
||||||
(for/list ([e (in-edges ig)])
|
(for/list ([e (in-edges ig)])
|
||||||
(match-let ([(list x y) e])
|
(match-let ([(list x y) e])
|
||||||
(list (get-interaction-sign network doms x y)
|
(list (get-interaction-sign network doms x y)
|
||||||
x y))))))
|
x y)))))
|
||||||
|
;; Ensure that every variable of the network appears in the signed
|
||||||
|
;; interaction graph as well.
|
||||||
|
(for ([v (in-vertices ig)])
|
||||||
|
(add-vertex! sig v))
|
||||||
|
sig))
|
||||||
|
|
||||||
;;; Calls build-signed-interaction-graph with the Boolean domain for
|
;;; Calls build-signed-interaction-graph with the Boolean domain for
|
||||||
;;; all variable.
|
;;; all variable.
|
||||||
|
@ -314,6 +321,7 @@
|
||||||
;;; every arrow in the unsigned interaction graph, so its performance
|
;;; every arrow in the unsigned interaction graph, so its performance
|
||||||
;;; decreases very quickly with the size of the network.
|
;;; decreases very quickly with the size of the network.
|
||||||
(define (build-signed-interaction-graph network doms)
|
(define (build-signed-interaction-graph network doms)
|
||||||
|
(define sig
|
||||||
(weighted-graph/directed
|
(weighted-graph/directed
|
||||||
(for*/fold ([edges '()])
|
(for*/fold ([edges '()])
|
||||||
([(x _) (in-hash network)]
|
([(x _) (in-hash network)]
|
||||||
|
@ -321,6 +329,11 @@
|
||||||
(match (get-interaction-sign network doms x y)
|
(match (get-interaction-sign network doms x y)
|
||||||
['0 edges]
|
['0 edges]
|
||||||
[sign (cons (list sign x y) edges)]))))
|
[sign (cons (list sign x y) edges)]))))
|
||||||
|
;; Ensure that all variables of the network appear in the signed
|
||||||
|
;; interaction graph.
|
||||||
|
(for ([(v _) (in-hash network)])
|
||||||
|
(add-vertex! sig v))
|
||||||
|
sig)
|
||||||
|
|
||||||
;;; Calls build-signed-interaction-graph assuming that the domains of
|
;;; Calls build-signed-interaction-graph assuming that the domains of
|
||||||
;;; all variables are Boolean.
|
;;; all variables are Boolean.
|
||||||
|
|
Loading…
Reference in a new issue