Compare commits

...

3 Commits

Author SHA1 Message Date
Sergiu Ivanov 764b4612f1 Make the sandbox sizes 10 times bigger for all scribblings. 2023-04-03 16:19:57 +02:00
Sergiu Ivanov 72454c395c Add lists+vars->tbfs/state. 2023-04-03 16:00:37 +02:00
Sergiu Ivanov 7c5333555c Add sectioning to tbn.scrbl. 2023-04-03 15:35:12 +02:00
5 changed files with 40 additions and 4 deletions

View File

@ -7,7 +7,7 @@
@(define functions-evaluator
(parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit 50])
[sandbox-memory-limit 500])
(make-evaluator 'typed/racket #:requires '("functions.rkt"))))
@(define-syntax-rule (ex . args)

View File

@ -12,7 +12,7 @@
@(define networks-evaluator
(parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit 50])
[sandbox-memory-limit 500])
(make-evaluator 'typed/racket #:requires '("networks.rkt"))))
@(define-syntax-rule (ex . args)

View File

@ -10,7 +10,7 @@
@(define tbn-evaluator
(parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit 50])
[sandbox-memory-limit 500])
(make-evaluator 'typed/racket #:requires '((submod "tbn.rkt" typed)))))
@(define-syntax-rule (ex . args)
@ -26,6 +26,8 @@
@defmodule[(submod dds/tbn typed)]
@section{TBFs and states}
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
@ -112,3 +114,19 @@ input values.
(apply-tbf/state (tbf/state (hash 'a 2 'b -2) 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)))
]}

View File

@ -10,7 +10,7 @@
@(define utils-evaluator
(parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit 50])
[sandbox-memory-limit 500])
(make-evaluator 'typed/racket #:requires '("utils.rkt"))))
@(define-syntax-rule (ex . args)

18
tbn.rkt
View File

@ -24,6 +24,8 @@
(struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state
sbf/state? apply-tbf/state
lists+vars->tbfs/state
)
(: 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))
(check-equal? (apply-tbf/state tbf st1) 1)
(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