Type apply-tbf-to-state.
This commit is contained in:
parent
d2e4ab854c
commit
fa88c15454
2 changed files with 41 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
#lang scribble/manual
|
||||
@(require scribble/example racket/sandbox
|
||||
(for-label typed/racket/base
|
||||
(submod "../tbn.rkt" typed)
|
||||
"../networks.rkt"
|
||||
"../utils.rkt"
|
||||
"../functions.rkt"
|
||||
|
@ -10,7 +11,7 @@
|
|||
(parameterize ([sandbox-output 'string]
|
||||
[sandbox-error-output 'string]
|
||||
[sandbox-memory-limit 50])
|
||||
(make-evaluator 'typed/racket #:requires '("tbn.rkt"))))
|
||||
(make-evaluator 'typed/racket #:requires '((submod "tbn.rkt" typed)))))
|
||||
|
||||
@(define-syntax-rule (ex . args)
|
||||
(examples #:eval tbn-evaluator . args))
|
||||
|
@ -23,10 +24,24 @@
|
|||
|
||||
@title[#:tag "tbn"]{dds/tbn: Threshold and Sign Boolean Networks (TBN and SBN)}
|
||||
|
||||
@defmodule[dds/tbn]
|
||||
@defmodule[(submod dds/tbn typed)]
|
||||
|
||||
This module defines threshold Boolean networks (TBN), as well as sign
|
||||
Boolean networks (SBN). The update functions in such networks are
|
||||
respectively @seclink["tbf" #:doc '(lib
|
||||
"dds/scribblings/dds.scrbl")]{threshold Boolean functions} and sign
|
||||
Boolean functions.
|
||||
|
||||
@defproc[(apply-tbf-to-state [a-tbf TBF] [st (State (U Zero One))])
|
||||
(U Zero One)]{
|
||||
|
||||
Applies a TBF to a state.
|
||||
|
||||
The values of the variables of the state are ordered by
|
||||
@racket[hash-map] and fed to the TBF in order. The number of the
|
||||
inputs of the TBF must match the number of variables in the state.
|
||||
|
||||
@ex[
|
||||
(require "functions.rkt")
|
||||
(apply-tbf-to-state (tbf #(1 1) 1) (hash 'x1 0 'x2 1))
|
||||
]}
|
||||
|
|
24
tbn.rkt
24
tbn.rkt
|
@ -4,6 +4,30 @@
|
|||
"functions.rkt" "networks.rkt"
|
||||
graph racket/random racket/hash)
|
||||
|
||||
(module typed typed/racket
|
||||
(require (except-in "utils.rkt" lists-transpose)
|
||||
"utils.rkt" "functions.rkt" "networks.rkt"
|
||||
typed/graph typed/racket/random)
|
||||
|
||||
(module+ test
|
||||
(require typed/rackunit))
|
||||
|
||||
(provide
|
||||
apply-tbf-to-state
|
||||
)
|
||||
|
||||
(: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One)))
|
||||
(define (apply-tbf-to-state tbf st)
|
||||
(apply-tbf tbf (list->vector
|
||||
(hash-map st (λ (_ [val : (U Zero One)]) val) #t))))
|
||||
|
||||
(module+ test
|
||||
(test-case "apply-tbf-to-state"
|
||||
(define st (hash 'x1 0 'x2 1))
|
||||
(define f (tbf #(1 1) 1))
|
||||
(check-equal? (apply-tbf-to-state f st) 0)))
|
||||
)
|
||||
|
||||
(module+ test
|
||||
(require rackunit))
|
||||
|
||||
|
|
Loading…
Reference in a new issue