networks: Add interaction?.
This commit is contained in:
parent
d24dadd4cd
commit
8a1f4c682e
1 changed files with 35 additions and 0 deletions
35
networks.rkt
35
networks.rkt
|
@ -31,6 +31,7 @@
|
||||||
network?)]
|
network?)]
|
||||||
[list-syntactic-interactions (-> network-form? variable? (listof variable?))]
|
[list-syntactic-interactions (-> network-form? variable? (listof variable?))]
|
||||||
[build-syntactic-interaction-graph (-> network-form? graph?)]
|
[build-syntactic-interaction-graph (-> network-form? graph?)]
|
||||||
|
[interaction? (-> network? domain-mapping/c variable? variable? boolean?)]
|
||||||
[build-all-states (-> domain-mapping/c (listof state?))]
|
[build-all-states (-> domain-mapping/c (listof state?))]
|
||||||
[make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)]
|
[make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)]
|
||||||
[make-boolean-domains (-> (listof variable?) (hash/c variable? (list/c #f #t)))]
|
[make-boolean-domains (-> (listof variable?) (hash/c variable? (list/c #f #t)))]
|
||||||
|
@ -397,7 +398,41 @@
|
||||||
#hash((a . 1) (b . 0))
|
#hash((a . 1) (b . 0))
|
||||||
#hash((a . 1) (b . 1))))))
|
#hash((a . 1) (b . 1))))))
|
||||||
|
|
||||||
|
;;; Given two variables x and y of a network f, verifies if they
|
||||||
|
;;; interact, i.e. that there exists such a state s with the property
|
||||||
|
;;; that s' which is s with a different value for x yields such a new
|
||||||
|
;;; state f(s') in which the value for y is different from f(s).
|
||||||
|
(define (interaction? network doms x y)
|
||||||
|
(define states-not-x (build-all-states (hash-remove doms x)))
|
||||||
|
(define (different-ys-exist? st)
|
||||||
|
(define x-states (for/list ([x-val (in-list (hash-ref doms x))])
|
||||||
|
(hash-set st x x-val)))
|
||||||
|
(for*/first ([st1 x-states]
|
||||||
|
[st2 x-states]
|
||||||
|
#:unless (equal? (hash-ref st1 x) (hash-ref st2 x))
|
||||||
|
#:unless (equal? ((hash-ref network y) st1)
|
||||||
|
((hash-ref network y) st2)))
|
||||||
|
#t))
|
||||||
|
(for*/first ([st (in-list states-not-x)]
|
||||||
|
#:when (different-ys-exist? st))
|
||||||
|
#t))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "interaction?"
|
||||||
|
(define n-bool (network-form->network
|
||||||
|
(hash 'x '(not y)
|
||||||
|
'y 'x
|
||||||
|
'z '(and y z))))
|
||||||
|
(define bool-doms (make-boolean-domains '(x y z)))
|
||||||
|
(check-true (interaction? n-bool bool-doms 'x 'y))
|
||||||
|
(check-true (interaction? n-bool bool-doms 'y 'x))
|
||||||
|
(check-false (interaction? n-bool bool-doms 'x 'z))
|
||||||
|
(define n-multi (network-form->network
|
||||||
|
(hash 'x '(max (+ y 1) 2)
|
||||||
|
'y '(min (- y 1) 0))))
|
||||||
|
(define 123-doms (make-same-domains '(x y) '(0 1 2)))
|
||||||
|
(check-false (interaction? n-multi 123-doms 'x 'y))
|
||||||
|
(check-true (interaction? n-multi 123-doms 'y 'x))))
|
||||||
|
|
||||||
;;; ====================
|
;;; ====================
|
||||||
;;; Dynamics of networks
|
;;; Dynamics of networks
|
||||||
|
|
Loading…
Reference in a new issue