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 'b '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"
|
||||
(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)
|
||||
(let ([ig (build-interaction-graph network-form)]
|
||||
[network (network-form->network network-form)])
|
||||
(weighted-graph/directed
|
||||
(for/list ([e (in-edges ig)])
|
||||
(match-let ([(list x y) e])
|
||||
(list (get-interaction-sign network doms x y)
|
||||
x y))))))
|
||||
;; Label every edge of the interaction graph with the sign.
|
||||
(define sig
|
||||
(weighted-graph/directed
|
||||
(for/list ([e (in-edges ig)])
|
||||
(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
|
||||
;;; all variable.
|
||||
|
@ -314,13 +321,19 @@
|
|||
;;; every arrow in the unsigned interaction graph, so its performance
|
||||
;;; decreases very quickly with the size of the network.
|
||||
(define (build-signed-interaction-graph network doms)
|
||||
(weighted-graph/directed
|
||||
(for*/fold ([edges '()])
|
||||
([(x _) (in-hash network)]
|
||||
[(y _) (in-hash network)])
|
||||
(match (get-interaction-sign network doms x y)
|
||||
['0 edges]
|
||||
[sign (cons (list sign x y) edges)]))))
|
||||
(define sig
|
||||
(weighted-graph/directed
|
||||
(for*/fold ([edges '()])
|
||||
([(x _) (in-hash network)]
|
||||
[(y _) (in-hash network)])
|
||||
(match (get-interaction-sign network doms x y)
|
||||
['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
|
||||
;;; all variables are Boolean.
|
||||
|
|
Loading…
Reference in a new issue