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 bn1 'a) s) #t)
(check-equal? ((hash-ref bn2 'a) s) #t) (check-equal? ((hash-ref bn2 'a) s) #t)
(check-equal? ((hash-ref bn3 '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)] [update-function-form->update-function (-> update-function-form? update-function/c)]
[network-form->network (-> network-form? network?)] [network-form->network (-> network-form? network?)]
[make-network-from-forms (-> (listof (cons/c symbol? update-function-form?)) [make-network-from-forms (-> (listof (cons/c symbol? update-function-form?))
network?)]) network?)]
[list-interactions (-> network-form? variable? (listof variable?))])
;; Predicates ;; Predicates
(contract-out [variable? (-> any/c boolean?)] (contract-out [variable? (-> any/c boolean?)]
[state? (-> any/c boolean?)] [state? (-> any/c boolean?)]
@ -121,3 +122,10 @@
;;; interaction graphs, but since the inference of signed interaction ;;; interaction graphs, but since the inference of signed interaction
;;; graphs is based on analysing the dynamics of the networks, it may ;;; graphs is based on analysing the dynamics of the networks, it may
;;; be quite resource-consuming. ;;; 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)))