diff --git a/networks.rkt b/networks.rkt index 1905e3b..a1b8ef5 100644 --- a/networks.rkt +++ b/networks.rkt @@ -34,6 +34,8 @@ [get-interaction-sign (-> network? domain-mapping/c variable? variable? (or/c '+ '- '0))] [build-signed-interaction-graph/form (-> network-form? domain-mapping/c 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-syn (-> (listof variable?) mode?)] [make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)] @@ -310,6 +312,38 @@ 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