Add tabulate-network and tabulate-network+headers.
This commit is contained in:
parent
0e5334f5e1
commit
b9b224fc6a
2 changed files with 70 additions and 1 deletions
49
networks.rkt
49
networks.rkt
|
@ -4,6 +4,8 @@
|
||||||
(require "utils.rkt" "functions.rkt" "dynamics.rkt"
|
(require "utils.rkt" "functions.rkt" "dynamics.rkt"
|
||||||
typed/graph racket/random
|
typed/graph racket/random
|
||||||
syntax/parse/define)
|
syntax/parse/define)
|
||||||
|
(require/typed racket/syntax
|
||||||
|
[format-symbol (-> String Any * Symbol)])
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require typed/rackunit)
|
(require typed/rackunit)
|
||||||
|
@ -44,6 +46,7 @@
|
||||||
tabulate-state*+headers tabulate-state*+headers/boolean
|
tabulate-state*+headers tabulate-state*+headers/boolean
|
||||||
tabulate-state tabulate-state/boolean
|
tabulate-state tabulate-state/boolean
|
||||||
tabulate-state+headers tabulate-state+headers/boolean
|
tabulate-state+headers tabulate-state+headers/boolean
|
||||||
|
tabulate-network tabulate-network+headers
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-type (State a) (VariableMapping a))
|
(define-type (State a) (VariableMapping a))
|
||||||
|
@ -879,6 +882,52 @@
|
||||||
(#f #t #f)
|
(#f #t #f)
|
||||||
(#t #f #f)
|
(#t #f #f)
|
||||||
(#t #t #t)))))
|
(#t #t #t)))))
|
||||||
|
|
||||||
|
(: tabulate-network (All (a) (-> (Network a) (Listof (Listof a)))))
|
||||||
|
(define (tabulate-network network)
|
||||||
|
(define funcs (hash-map (network-functions network)
|
||||||
|
(λ (_ [fx : (UpdateFunction a)]) fx)
|
||||||
|
#t))
|
||||||
|
(tabulate-state* funcs (network-domains network)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "tabulate-network"
|
||||||
|
(define bn (forms->boolean-network (hash 'a '(not a) 'b 'b)))
|
||||||
|
(check-equal? (tabulate-network bn)
|
||||||
|
'((#f #f #t #f)
|
||||||
|
(#f #t #t #t)
|
||||||
|
(#t #f #f #f)
|
||||||
|
(#t #t #f #t)))))
|
||||||
|
|
||||||
|
(: tabulate-network+headers (All (a) (-> (Network a)
|
||||||
|
(Pairof (Listof Symbol)
|
||||||
|
(Listof (Listof a))))))
|
||||||
|
(define (tabulate-network+headers network)
|
||||||
|
(define-values (vars funcs)
|
||||||
|
(for/lists ([l1 : (Listof Variable)]
|
||||||
|
[l2 : (Listof (UpdateFunction a))])
|
||||||
|
([p (hash-map (network-functions network)
|
||||||
|
(inst cons Variable (UpdateFunction a))
|
||||||
|
#t)])
|
||||||
|
(values (car p) (cdr p))))
|
||||||
|
|
||||||
|
(define fnames : (Listof Variable)
|
||||||
|
(for/list ([v vars]) (format-symbol "f-~a" v)))
|
||||||
|
|
||||||
|
(match (tabulate-state*+headers funcs (network-domains network))
|
||||||
|
[(list headers tab ...)
|
||||||
|
(cons (append (take headers (length fnames)) fnames)
|
||||||
|
tab)]))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "tabulate-network+headers"
|
||||||
|
(define bn (forms->boolean-network (hash 'a '(not a) 'b 'b)))
|
||||||
|
(check-equal? (tabulate-network+headers bn)
|
||||||
|
'((a b f-a f-b)
|
||||||
|
(#f #f #t #f)
|
||||||
|
(#f #t #t #t)
|
||||||
|
(#t #f #f #f)
|
||||||
|
(#t #t #f #t)))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require 'typed)
|
(require 'typed)
|
||||||
|
|
|
@ -810,6 +810,26 @@ function instead of a list.
|
||||||
'(a b))
|
'(a b))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(tabulate-network [network (Network a)]) (Listof (Listof a))]{
|
||||||
|
|
||||||
|
Tabulates all the functions of @racket[network], producing an output
|
||||||
|
similar to that of @racket[tabulate-state*].
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(tabulate-network (forms->boolean-network (hash 'a '(not a) 'b 'b)))
|
||||||
|
]}
|
||||||
|
|
||||||
|
@defproc[(tabulate-network+headers [network (Network a)]) (Listof (Listof a))]{
|
||||||
|
|
||||||
|
Tabulates all the functions of @racket[network], producing an output
|
||||||
|
similar to that of @racket[tabulate-state*+headers] , except that the
|
||||||
|
function names in the corresponding column headers are of the form
|
||||||
|
@tt{f-x}, where @tt{x} is the name of the corresponding variable.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(tabulate-network+headers (forms->boolean-network (hash 'a '(not a) 'b 'b)))
|
||||||
|
]}
|
||||||
|
|
||||||
@section{Constructing functions and networks}
|
@section{Constructing functions and networks}
|
||||||
|
|
||||||
@section{Random functions and networks}
|
@section{Random functions and networks}
|
||||||
|
|
Loading…
Reference in a new issue