Compare commits
3 Commits
e8ebab58ca
...
764b4612f1
Author | SHA1 | Date | |
---|---|---|---|
|
764b4612f1 | ||
|
72454c395c | ||
|
7c5333555c |
|
@ -7,7 +7,7 @@
|
||||||
@(define functions-evaluator
|
@(define functions-evaluator
|
||||||
(parameterize ([sandbox-output 'string]
|
(parameterize ([sandbox-output 'string]
|
||||||
[sandbox-error-output 'string]
|
[sandbox-error-output 'string]
|
||||||
[sandbox-memory-limit 50])
|
[sandbox-memory-limit 500])
|
||||||
(make-evaluator 'typed/racket #:requires '("functions.rkt"))))
|
(make-evaluator 'typed/racket #:requires '("functions.rkt"))))
|
||||||
|
|
||||||
@(define-syntax-rule (ex . args)
|
@(define-syntax-rule (ex . args)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
@(define networks-evaluator
|
@(define networks-evaluator
|
||||||
(parameterize ([sandbox-output 'string]
|
(parameterize ([sandbox-output 'string]
|
||||||
[sandbox-error-output 'string]
|
[sandbox-error-output 'string]
|
||||||
[sandbox-memory-limit 50])
|
[sandbox-memory-limit 500])
|
||||||
(make-evaluator 'typed/racket #:requires '("networks.rkt"))))
|
(make-evaluator 'typed/racket #:requires '("networks.rkt"))))
|
||||||
|
|
||||||
@(define-syntax-rule (ex . args)
|
@(define-syntax-rule (ex . args)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
@(define tbn-evaluator
|
@(define tbn-evaluator
|
||||||
(parameterize ([sandbox-output 'string]
|
(parameterize ([sandbox-output 'string]
|
||||||
[sandbox-error-output 'string]
|
[sandbox-error-output 'string]
|
||||||
[sandbox-memory-limit 50])
|
[sandbox-memory-limit 500])
|
||||||
(make-evaluator 'typed/racket #:requires '((submod "tbn.rkt" typed)))))
|
(make-evaluator 'typed/racket #:requires '((submod "tbn.rkt" typed)))))
|
||||||
|
|
||||||
@(define-syntax-rule (ex . args)
|
@(define-syntax-rule (ex . args)
|
||||||
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
@defmodule[(submod dds/tbn typed)]
|
@defmodule[(submod dds/tbn typed)]
|
||||||
|
|
||||||
|
@section{TBFs and states}
|
||||||
|
|
||||||
This module defines threshold Boolean networks (TBN), as well as sign
|
This module defines threshold Boolean networks (TBN), as well as sign
|
||||||
Boolean networks (SBN). The update functions in such networks are
|
Boolean networks (SBN). The update functions in such networks are
|
||||||
respectively @seclink["tbf" #:doc '(lib
|
respectively @seclink["tbf" #:doc '(lib
|
||||||
|
@ -112,3 +114,19 @@ input values.
|
||||||
(apply-tbf/state (tbf/state (hash 'a 2 'b -2) 1)
|
(apply-tbf/state (tbf/state (hash 'a 2 'b -2) 1)
|
||||||
(hash 'a 1 'b 0 'c 1))
|
(hash 'a 1 'b 0 'c 1))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@section{Reading TBFs and SBFs}
|
||||||
|
|
||||||
|
@defproc[(lists+vars->tbfs/state [vars (Listof Variable)]
|
||||||
|
[lsts (Listof (Listof Real))])
|
||||||
|
(Listof TBF/State)]{
|
||||||
|
|
||||||
|
Reads a list of @racket[TBF/State] from a list of list of
|
||||||
|
@racket[Real]s.
|
||||||
|
|
||||||
|
The last element of each list is taken to be the threshold of the
|
||||||
|
TBFs, and the rest of the elements are taken to be the weights.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2)))
|
||||||
|
]}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
@(define utils-evaluator
|
@(define utils-evaluator
|
||||||
(parameterize ([sandbox-output 'string]
|
(parameterize ([sandbox-output 'string]
|
||||||
[sandbox-error-output 'string]
|
[sandbox-error-output 'string]
|
||||||
[sandbox-memory-limit 50])
|
[sandbox-memory-limit 500])
|
||||||
(make-evaluator 'typed/racket #:requires '("utils.rkt"))))
|
(make-evaluator 'typed/racket #:requires '("utils.rkt"))))
|
||||||
|
|
||||||
@(define-syntax-rule (ex . args)
|
@(define-syntax-rule (ex . args)
|
||||||
|
|
18
tbn.rkt
18
tbn.rkt
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
(struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state
|
(struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state
|
||||||
sbf/state? apply-tbf/state
|
sbf/state? apply-tbf/state
|
||||||
|
|
||||||
|
lists+vars->tbfs/state
|
||||||
)
|
)
|
||||||
|
|
||||||
(: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One)))
|
(: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One)))
|
||||||
|
@ -75,6 +77,22 @@
|
||||||
(define tbf (make-tbf/state '((a . 2) (b . -2)) 1))
|
(define tbf (make-tbf/state '((a . 2) (b . -2)) 1))
|
||||||
(check-equal? (apply-tbf/state tbf st1) 1)
|
(check-equal? (apply-tbf/state tbf st1) 1)
|
||||||
(check-equal? (apply-tbf/state tbf st2) 0)))
|
(check-equal? (apply-tbf/state tbf st2) 0)))
|
||||||
|
|
||||||
|
(: lists+vars->tbfs/state (-> (Listof Variable) (Listof (Listof Real))
|
||||||
|
(Listof TBF/State)))
|
||||||
|
(define (lists+vars->tbfs/state vars lsts)
|
||||||
|
(for/list ([lst (in-list lsts)])
|
||||||
|
(define-values (ws θ) (split-at-right lst 1))
|
||||||
|
(make-tbf/state (for/list ([x (in-list vars)]
|
||||||
|
[w (in-list ws)])
|
||||||
|
(cons x w))
|
||||||
|
(car θ))))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "lists+vars->tbfs/state"
|
||||||
|
(check-equal? (lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2)))
|
||||||
|
(list (tbf/state '#hash((x . 1) (y . 2)) 3)
|
||||||
|
(tbf/state '#hash((x . 1) (y . 1)) 2)))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user