Type build-all-states.

This commit is contained in:
Sergiu Ivanov 2022-05-15 14:52:47 +02:00
parent 8722d63d3e
commit eaabcd9a05
2 changed files with 36 additions and 26 deletions

View file

@ -23,6 +23,8 @@
network-form->network/01 make-boolean-network-form network-form->network/01 make-boolean-network-form
forms->boolean-network forms->boolean-network
build-all-states
list-syntactic-interactions build-syntactic-interaction-graph list-syntactic-interactions build-syntactic-interaction-graph
) )
@ -241,6 +243,26 @@
(check-equal? (network-domains n) (hash 'a '(#f #t) (check-equal? (network-domains n) (hash 'a '(#f #t)
'b '(#f #t))))) 'b '(#f #t)))))
(: build-all-states (All (a) (-> (DomainMapping a) (Listof (State a)))))
(define (build-all-states vars-domains)
;; TODO: Use hash-keys and hash-values when Typed Racket will have
;; caught up with the new argument try-order?.
(define vdlist (hash-map vars-domains (inst cons Variable (Domain a)) #t))
(define vars (map (inst car Variable (Domain a)) vdlist))
(define doms (map (inst cdr Variable (Domain a)) vdlist))
(for/list ([s (apply cartesian-product doms)])
(make-immutable-hash (map (inst cons Variable a) vars s))))
(module+ test
(test-case "build-all-states"
(check-equal? (build-all-states #hash((a . (#t #f)) (b . (1 2 3))))
'(#hash((a . #t) (b . 1))
#hash((a . #t) (b . 2))
#hash((a . #t) (b . 3))
#hash((a . #f) (b . 1))
#hash((a . #f) (b . 2))
#hash((a . #f) (b . 3))))))
(: list-syntactic-interactions (: list-syntactic-interactions
(All (a) (-> (NetworkForm a) Variable (Listof Variable)))) (All (a) (-> (NetworkForm a) Variable (Listof Variable))))
(define (list-syntactic-interactions nf x) (define (list-syntactic-interactions nf x)
@ -297,7 +319,6 @@
[build-interaction-graph/form (-> network-form? graph?)] [build-interaction-graph/form (-> network-form? graph?)]
[build-signed-interaction-graph (-> network? graph?)] [build-signed-interaction-graph (-> network? graph?)]
[build-signed-interaction-graph/form (-> network-form? graph?)] [build-signed-interaction-graph/form (-> network-form? graph?)]
[build-all-states (-> domain-mapping/c (listof state?))]
[build-all-boolean-states (-> (listof variable?) (listof state?))] [build-all-boolean-states (-> (listof variable?) (listof state?))]
[build-all-01-states (-> (listof variable?) (listof state?))] [build-all-01-states (-> (listof variable?) (listof state?))]
[make-asyn (-> (listof variable?) mode?)] [make-asyn (-> (listof variable?) mode?)]
@ -440,26 +461,6 @@
;;; Inferring interaction graphs ;;; Inferring interaction graphs
;;; ============================ ;;; ============================
;;; Given a hash-set mapping variables to generic sets of their
;;; possible values, constructs the list of all possible states.
(define (build-all-states vars-domains)
(let* ([var-dom-list (hash-map vars-domains (λ (x y) (cons x y)) #t)]
[vars (map car var-dom-list)]
[domains (map cdr var-dom-list)])
(for/list ([s (apply cartesian-product domains)])
(make-immutable-hash (for/list ([var vars] [val s])
(cons var val))))))
(module+ test
(test-case "build-all-states"
(check-equal? (build-all-states #hash((a . (#t #f)) (b . (1 2 3))))
'(#hash((a . #t) (b . 1))
#hash((a . #t) (b . 2))
#hash((a . #t) (b . 3))
#hash((a . #f) (b . 1))
#hash((a . #f) (b . 2))
#hash((a . #f) (b . 3))))))
;;; Builds all boolean states possible over a given set of variables. ;;; Builds all boolean states possible over a given set of variables.
(define (build-all-boolean-states vars) (define (build-all-boolean-states vars)
(build-all-states (make-boolean-domains vars))) (build-all-states (make-boolean-domains vars)))

View file

@ -330,6 +330,20 @@ Build a Boolean network from a given mapping assigning forms to variables.
'b '(not b))) 'b '(not b)))
]} ]}
@section{Dynamics of networks}
This section contains definitions for building and analysing the dynamics
of networks.
@defproc[(build-all-states [vars-domains (DomainMapping a)])
(Listof (State a))]{
Given a @racket[DomainMapping], constructs the list of all possible states.
@ex[
(build-all-states (make-boolean-domains '(a b)))
]}
@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.
@ -380,11 +394,6 @@ appears in @racket[(list-interactions y)].
(b . (- b)))))) (b . (- b))))))
]} ]}
@section{Dynamics of networks}
This section contains definitions for building and analysing the dynamics
of networks.
@section{Tabulating functions and networks} @section{Tabulating functions and networks}
@section{Constructing functions and networks} @section{Constructing functions and networks}