networks: Add build-signed-interaction-graph and build-boolean-signed-interaction-graph.

No tests yet.
This commit is contained in:
Sergiu Ivanov 2020-03-22 21:00:12 +01:00
parent a77d42af85
commit b0eb81b051

View file

@ -34,6 +34,8 @@
[get-interaction-sign (-> network? domain-mapping/c variable? variable? (or/c '+ '- '0))] [get-interaction-sign (-> network? domain-mapping/c variable? variable? (or/c '+ '- '0))]
[build-signed-interaction-graph/form (-> network-form? domain-mapping/c graph?)] [build-signed-interaction-graph/form (-> network-form? domain-mapping/c graph?)]
[build-boolean-signed-interaction-graph/form (-> network-form? graph?)] [build-boolean-signed-interaction-graph/form (-> network-form? graph?)]
[build-signed-interaction-graph (-> network? domain-mapping/c graph?)]
[build-boolean-signed-interaction-graph (-> network? graph?)]
[make-asyn (-> (listof variable?) mode?)] [make-asyn (-> (listof variable?) mode?)]
[make-syn (-> (listof variable?) mode?)] [make-syn (-> (listof variable?) mode?)]
[make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)] [make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)]
@ -310,6 +312,38 @@
network-form network-form
(make-boolean-domains (hash-keys network-form)))) (make-boolean-domains (hash-keys network-form))))
;;; Similar to build-signed-interaction-graph/form, but operates on a
;;; network rather than a form. The resulting graph only includes the
;;; edges for positive or negative interactions.
;;;
;;; This function has operates with much less knowledge than
;;; build-signed-interaction-graph/form, so prefer using the latter
;;; when you can get a network form.
;;;
;;; /!\ This function iterates through all states of the network for
;;; 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  x-val) (in-hash network)]
[(y  y-val) (in-hash network)])
(match (get-interaction-sign network doms x y)
['0 edges]
[sign (cons (list sign x y) edges)]))))
;;; Calls build-signed-interaction-graph assuming that the domains of
;;; all variables are Boolean.
;;;
;;; This function has operates with much less knowledge than
;;; build-boolean-signed-interaction-graph/form, so prefer using the
;;; latter when you can get a network form.
;;;
;;; /!\ This function iterates through all states of the network for
;;; every arrow in the unsigned interaction graph, so its performance
;;; decreases very quickly with the size of the network.
(define (build-boolean-signed-interaction-graph network)
(build-signed-interaction-graph network (make-boolean-domains (hash-keys network))))
;;; ==================== ;;; ====================
;;; Dynamics of networks ;;; Dynamics of networks