Type network-form->network as network-form->network/any.
This commit is contained in:
parent
181b427cd8
commit
b795be0a39
2 changed files with 37 additions and 24 deletions
49
networks.rkt
49
networks.rkt
|
@ -19,6 +19,7 @@
|
||||||
update-function-form->update-function/any
|
update-function-form->update-function/any
|
||||||
update-function-form->update-function/boolean
|
update-function-form->update-function/boolean
|
||||||
update-function-form->update-function/01
|
update-function-form->update-function/01
|
||||||
|
network-form->network/any
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-type (State a) (VariableMapping a))
|
(define-type (State a) (VariableMapping a))
|
||||||
|
@ -156,6 +157,24 @@
|
||||||
(define s (hash 'x 0 'y 1))
|
(define s (hash 'x 0 'y 1))
|
||||||
(define f (update-function-form->update-function/01 '(max x y)))
|
(define f (update-function-form->update-function/01 '(max x y)))
|
||||||
(check-equal? (f s) 1)))
|
(check-equal? (f s) 1)))
|
||||||
|
|
||||||
|
(: network-form->network/any (-> (NetworkForm Any) (Network Any)))
|
||||||
|
(define (network-form->network/any nf)
|
||||||
|
(network
|
||||||
|
(for/hash ([(x form) (in-hash (network-form-forms nf))])
|
||||||
|
: (VariableMapping (UpdateFunction Any))
|
||||||
|
(values x (update-function-form->update-function/any form)))
|
||||||
|
(network-form-domains nf)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "network-form->network/any"
|
||||||
|
(define bn (network-form->network/any
|
||||||
|
(network-form (hash 'a '(and a b)
|
||||||
|
'b '(not b))
|
||||||
|
(hash 'a '(#f #t)
|
||||||
|
'b '(#f #t)))))
|
||||||
|
(define s (hash 'a #t 'b #t))
|
||||||
|
(check-equal? ((hash-ref (network-functions bn) 'a) s) #t)))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require 'typed)
|
(require 'typed)
|
||||||
|
@ -172,8 +191,7 @@
|
||||||
[struct dynamics ([network network?]
|
[struct dynamics ([network network?]
|
||||||
[mode mode?])])
|
[mode mode?])])
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [network-form->network (-> network-form? network?)]
|
(contract-out [make-boolean-network-form (-> variable-mapping? network-form?)]
|
||||||
[make-boolean-network-form (-> variable-mapping? network-form?)]
|
|
||||||
[forms->boolean-network (-> variable-mapping? network?)]
|
[forms->boolean-network (-> variable-mapping? 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?)]
|
||||||
|
@ -321,23 +339,6 @@
|
||||||
|
|
||||||
(define update-function-form? any/c)
|
(define update-function-form? any/c)
|
||||||
|
|
||||||
;;; Build a network from a network form.
|
|
||||||
(define (network-form->network nf)
|
|
||||||
(network
|
|
||||||
(for/hash ([(x form) (in-hash (network-form-forms nf))])
|
|
||||||
(values x (update-function-form->update-function/any form)))
|
|
||||||
(network-form-domains nf)))
|
|
||||||
|
|
||||||
(module+ test
|
|
||||||
(test-case "network-form->network"
|
|
||||||
(define bn (network-form->network
|
|
||||||
(network-form (hash 'a '(and a b)
|
|
||||||
'b '(not b))
|
|
||||||
(hash 'a '(#f #t)
|
|
||||||
'b '(#f #t)))))
|
|
||||||
(define s (hash 'a #t 'b #t))
|
|
||||||
(check-equal? ((hash-ref (network-functions bn) 'a) s) #t)))
|
|
||||||
|
|
||||||
;;; Build a Boolean network form from a given mapping assigning forms
|
;;; Build a Boolean network form from a given mapping assigning forms
|
||||||
;;; to variables.
|
;;; to variables.
|
||||||
(define (make-boolean-network-form forms)
|
(define (make-boolean-network-form forms)
|
||||||
|
@ -354,7 +355,7 @@
|
||||||
;;; Build a Boolean network from a given mapping assigning forms
|
;;; Build a Boolean network from a given mapping assigning forms
|
||||||
;;; to variables.
|
;;; to variables.
|
||||||
(define forms->boolean-network
|
(define forms->boolean-network
|
||||||
(compose network-form->network make-boolean-network-form))
|
(compose network-form->network/any make-boolean-network-form))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-case "forms->boolean-network"
|
(test-case "forms->boolean-network"
|
||||||
|
@ -508,7 +509,7 @@
|
||||||
(define n-multi (hash 'x '(max (+ y 1) 2)
|
(define n-multi (hash 'x '(max (+ y 1) 2)
|
||||||
'y '(min (- y 1) 0)))
|
'y '(min (- y 1) 0)))
|
||||||
(define 123-doms (make-same-domains '(x y) '(0 1 2)))
|
(define 123-doms (make-same-domains '(x y) '(0 1 2)))
|
||||||
(define n2 (network-form->network (network-form n-multi 123-doms)))
|
(define n2 (network-form->network/any (network-form n-multi 123-doms)))
|
||||||
(check-false (interaction? n2 'x 'y))
|
(check-false (interaction? n2 'x 'y))
|
||||||
(check-true (interaction? n2 'y 'x))))
|
(check-true (interaction? n2 'y 'x))))
|
||||||
|
|
||||||
|
@ -573,7 +574,7 @@
|
||||||
'z '(- 2 y)
|
'z '(- 2 y)
|
||||||
't '(abs (- y 1))))
|
't '(abs (- y 1))))
|
||||||
(define 123-doms (make-same-domains '(x y z t) '(0 1 2)))
|
(define 123-doms (make-same-domains '(x y z t) '(0 1 2)))
|
||||||
(define n2 (network-form->network (network-form n-multi 123-doms)))
|
(define n2 (network-form->network/any (network-form n-multi 123-doms)))
|
||||||
(check-false (get-interaction-sign n2 'x 'y))
|
(check-false (get-interaction-sign n2 'x 'y))
|
||||||
(check-equal? (get-interaction-sign n2 'y 'x) 1)
|
(check-equal? (get-interaction-sign n2 'y 'x) 1)
|
||||||
(check-equal? (get-interaction-sign n2 'y 'z) -1)
|
(check-equal? (get-interaction-sign n2 'y 'z) -1)
|
||||||
|
@ -594,7 +595,7 @@
|
||||||
;;; Like build-interaction-graph, but accepts a network form and
|
;;; Like build-interaction-graph, but accepts a network form and
|
||||||
;;; converts it a to a network.
|
;;; converts it a to a network.
|
||||||
(define build-interaction-graph/form
|
(define build-interaction-graph/form
|
||||||
(compose build-interaction-graph network-form->network))
|
(compose build-interaction-graph network-form->network/any))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-case "build-interaction-graph"
|
(test-case "build-interaction-graph"
|
||||||
|
@ -635,7 +636,7 @@
|
||||||
;;; Like build-signed-interaction-graph, but takes a network form and
|
;;; Like build-signed-interaction-graph, but takes a network form and
|
||||||
;;; converts it a to a network.
|
;;; converts it a to a network.
|
||||||
(define build-signed-interaction-graph/form
|
(define build-signed-interaction-graph/form
|
||||||
(compose build-signed-interaction-graph network-form->network))
|
(compose build-signed-interaction-graph network-form->network/any))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(test-case "build-signed-interaction-graph"
|
(test-case "build-signed-interaction-graph"
|
||||||
|
|
|
@ -273,6 +273,18 @@ function operates on Boolean states.
|
||||||
(and-from-form/01 (hash 'x 1 'y 1))
|
(and-from-form/01 (hash 'x 1 'y 1))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(network-form->network/any [nf (NetworkForm Any)]) (Network Any)]{
|
||||||
|
|
||||||
|
Builds a network from a network form.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(network-form->network/any
|
||||||
|
(network-form (hash 'a '(and a b)
|
||||||
|
'b '(not b))
|
||||||
|
(hash 'a '(#f #t)
|
||||||
|
'b '(#f #t))))
|
||||||
|
]}
|
||||||
|
|
||||||
@section{Inferring interaction graphs}
|
@section{Inferring interaction graphs}
|
||||||
|
|
||||||
This section provides inference of both unsigned and signed interaction graphs.
|
This section provides inference of both unsigned and signed interaction graphs.
|
||||||
|
|
Loading…
Reference in a new issue