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")
|
||||||
|
|
37
networks.rkt
37
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)])
|
||||||
(weighted-graph/directed
|
;; Label every edge of the interaction graph with the sign.
|
||||||
(for/list ([e (in-edges ig)])
|
(define sig
|
||||||
(match-let ([(list x y) e])
|
(weighted-graph/directed
|
||||||
(list (get-interaction-sign network doms x y)
|
(for/list ([e (in-edges ig)])
|
||||||
x y))))))
|
(match-let ([(list x y) e])
|
||||||
|
(list (get-interaction-sign network doms 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,13 +321,19 @@
|
||||||
;;; 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)
|
||||||
(weighted-graph/directed
|
(define sig
|
||||||
(for*/fold ([edges '()])
|
(weighted-graph/directed
|
||||||
([(x _) (in-hash network)]
|
(for*/fold ([edges '()])
|
||||||
[(y _) (in-hash network)])
|
([(x _) (in-hash network)]
|
||||||
(match (get-interaction-sign network doms x y)
|
[(y _) (in-hash network)])
|
||||||
['0 edges]
|
(match (get-interaction-sign network doms x y)
|
||||||
[sign (cons (list sign x y) edges)]))))
|
['0 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