networks: Add list-interactions.

This commit is contained in:
Sergiu Ivanov 2020-02-20 15:17:32 +01:00
parent 71f979808c
commit 75bf044fd8
2 changed files with 15 additions and 1 deletions

View File

@ -44,3 +44,9 @@
(check-equal? ((hash-ref bn1 'a) s) #t)
(check-equal? ((hash-ref bn2 'a) s) #t)
(check-equal? ((hash-ref bn3 'a) s) #t)))
(test-case "Inferring interaction graphs"
(let ([n #hash((a . (+ a b c))
(b . (- b c)))])
(check-true (set=? (list-interactions n 'a) '(a b)))
(check-true (set=? (list-interactions n 'b) '(b)))))

View File

@ -20,7 +20,8 @@
[update-function-form->update-function (-> update-function-form? update-function/c)]
[network-form->network (-> network-form? network?)]
[make-network-from-forms (-> (listof (cons/c symbol? update-function-form?))
network?)])
network?)]
[list-interactions (-> network-form? variable? (listof variable?))])
;; Predicates
(contract-out [variable? (-> any/c boolean?)]
[state? (-> any/c boolean?)]
@ -121,3 +122,10 @@
;;; interaction graphs, but since the inference of signed interaction
;;; graphs is based on analysing the dynamics of the networks, it may
;;; be quite resource-consuming.
;;; Lists the variables of the network form appearing in the update
;;; function form for x.
(define (list-interactions nf x)
(set-intersect
(extract-symbols (hash-ref nf x))
(hash-keys nf)))