example: Add some examples for random functions and networks.
This commit is contained in:
parent
5330336b6d
commit
b38bebb67b
1 changed files with 53 additions and 0 deletions
|
@ -523,6 +523,59 @@ tab
|
||||||
| #t | #t | #t | #t | #f | #f |
|
| #t | #t | #t | #t | #f | #f |
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
|
** Random functions and networks
|
||||||
|
To avoid having different results every time a code block in this
|
||||||
|
section is run, every code block seeds the random number generator
|
||||||
|
to 0.
|
||||||
|
|
||||||
|
=dds/networks= can generate random functions, given a domain for
|
||||||
|
each of its arguments and for the function itself. Consider the
|
||||||
|
following domains:
|
||||||
|
#+NAME: simple-domains
|
||||||
|
| a | (#f #t) |
|
||||||
|
| b | (1 2) |
|
||||||
|
| c | (cold hot) |
|
||||||
|
|
||||||
|
Here's a random function taking values in the codomain =(4 5 6)=:
|
||||||
|
#+BEGIN_SRC racket :results table drawer :var simple-domains=munch-sexp(simple-domains)
|
||||||
|
(random-seed 0)
|
||||||
|
(define rnd-func (random-function/state (unorg simple-domains) '(4 5 6)))
|
||||||
|
(tabulate-state rnd-func (unorg simple-domains))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
:RESULTS:
|
||||||
|
| a | b | c | f |
|
||||||
|
| #f | 1 | cold | 4 |
|
||||||
|
| #f | 1 | hot | 5 |
|
||||||
|
| #f | 2 | cold | 4 |
|
||||||
|
| #f | 2 | hot | 4 |
|
||||||
|
| #t | 1 | cold | 5 |
|
||||||
|
| #t | 1 | hot | 6 |
|
||||||
|
| #t | 2 | cold | 4 |
|
||||||
|
| #t | 2 | hot | 5 |
|
||||||
|
:END:
|
||||||
|
|
||||||
|
We can build an entire random network over these domains:
|
||||||
|
#+BEGIN_SRC racket :results table drawer :var simple-domains=munch-sexp(simple-domains)
|
||||||
|
(random-seed 0)
|
||||||
|
(define n (random-network (unorg simple-domains)))
|
||||||
|
(tabulate-network n (unorg simple-domains))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
:RESULTS:
|
||||||
|
| a | b | c | f-a | f-b | f-c |
|
||||||
|
| #f | 1 | cold | #t | 2 | cold |
|
||||||
|
| #f | 1 | hot | #t | 1 | cold |
|
||||||
|
| #f | 2 | cold | #f | 1 | hot |
|
||||||
|
| #f | 2 | hot | #t | 2 | hot |
|
||||||
|
| #t | 1 | cold | #t | 1 | cold |
|
||||||
|
| #t | 1 | hot | #f | 1 | hot |
|
||||||
|
| #t | 2 | cold | #t | 2 | cold |
|
||||||
|
| #t | 2 | hot | #f | 1 | hot |
|
||||||
|
:END:
|
||||||
|
|
||||||
|
|
||||||
* Reaction systems
|
* Reaction systems
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
|
Loading…
Reference in a new issue