example: Update Random functions and networks.

This commit is contained in:
Sergiu Ivanov 2020-11-28 22:55:44 +01:00
parent 5fc4875adf
commit ce2d10526a
3 changed files with 91 additions and 49 deletions

View file

@ -130,7 +130,7 @@
<g id="edge9" class="edge">
<title>node4&#45;&gt;node4</title>
<path fill="none" stroke="black" d="M866.46,-816.69C879.83,-815.94 889.32,-813.79 889.32,-810.24 889.32,-806.69 879.83,-804.54 866.46,-803.79"/>
<text text-anchor="middle" x="915.82" y="-806.54" font-family="Times-Roman" font-size="14.00">{c}{b}</text>
<text text-anchor="middle" x="915.82" y="-806.54" font-family="Times-Roman" font-size="14.00">{b}{c}</text>
</g>
<!-- node4&#45;&gt;node6 -->
<g id="edge16" class="edge">

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View file

@ -4,42 +4,80 @@
<!-- Generated by graphviz version 2.43.0 (0)
-->
<!-- Title: G Pages: 1 -->
<svg width="413pt" height="44pt"
viewBox="0.00 0.00 413.24 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<svg width="335pt" height="270pt"
viewBox="0.00 0.00 335.32 269.60" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 265.6)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-40 409.24,-40 409.24,4 -4,4"/>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-265.6 331.32,-265.6 331.32,4 -4,4"/>
<!-- node0 -->
<g id="node1" class="node">
<title>node0</title>
<ellipse fill="none" stroke="black" cx="378.24" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="378.24" y="-14.3" font-family="Times-Roman" font-size="14.00">c</text>
<ellipse fill="none" stroke="black" cx="272.32" cy="-243.6" rx="27" ry="18"/>
<text text-anchor="middle" x="272.32" y="-239.9" font-family="Times-Roman" font-size="14.00">c</text>
</g>
<!-- node2 -->
<g id="node3" class="node">
<title>node2</title>
<ellipse fill="none" stroke="black" cx="205.6" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="205.6" y="-14.3" font-family="Times-Roman" font-size="14.00">a</text>
</g>
<!-- node0&#45;&gt;node2 -->
<!-- node0&#45;&gt;node0 -->
<g id="edge1" class="edge">
<title>node0&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M350.89,-18C321.72,-18 275.34,-18 242.85,-18"/>
<polygon fill="black" stroke="black" points="242.83,-14.5 232.83,-18 242.83,-21.5 242.83,-14.5"/>
<text text-anchor="middle" x="290.37" y="-21.8" font-family="Times-Roman" font-size="14.00">+</text>
<title>node0&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M297.76,-250.29C308.35,-250.75 317.32,-248.52 317.32,-243.6 317.32,-238.67 308.35,-236.44 297.76,-236.9"/>
<text text-anchor="middle" x="322.32" y="-239.9" font-family="Times-Roman" font-size="14.00">0</text>
</g>
<!-- node1 -->
<g id="node2" class="node">
<title>node1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times-Roman" font-size="14.00">b</text>
<ellipse fill="none" stroke="black" cx="27" cy="-214.2" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-210.5" font-family="Times-Roman" font-size="14.00">b</text>
</g>
<!-- node0&#45;&gt;node1 -->
<g id="edge2" class="edge">
<title>node0&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M245.6,-240.39C198.41,-234.74 100.85,-223.05 53.69,-217.4"/>
<text text-anchor="middle" x="144.64" y="-232.7" font-family="Times-Roman" font-size="14.00">0</text>
</g>
<!-- node2 -->
<g id="node3" class="node">
<title>node2</title>
<ellipse fill="none" stroke="black" cx="175.3" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="175.3" y="-14.3" font-family="Times-Roman" font-size="14.00">a</text>
</g>
<!-- node0&#45;&gt;node2 -->
<g id="edge5" class="edge">
<title>node0&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M268.62,-225.53C255.48,-185.59 214.61,-89.85 191.36,-43.69"/>
<polygon fill="black" stroke="black" points="194.38,-41.91 186.69,-34.63 188.16,-45.13 194.38,-41.91"/>
<text text-anchor="middle" x="224.99" y="-138.41" font-family="Times-Roman" font-size="14.00">1</text>
</g>
<!-- node1&#45;&gt;node1 -->
<g id="edge3" class="edge">
<title>node1&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M52.44,-220.89C63.03,-221.36 72,-219.13 72,-214.2 72,-209.28 63.03,-207.05 52.44,-207.51"/>
<text text-anchor="middle" x="79.5" y="-210.5" font-family="Times-Roman" font-size="14.00">&#45;1</text>
</g>
<!-- node1&#45;&gt;node2 -->
<g id="edge2" class="edge">
<g id="edge6" class="edge">
<title>node1&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M54.13,-18C84.64,-18 134.37,-18 168.47,-18"/>
<polygon fill="black" stroke="black" points="168.52,-21.5 178.52,-18 168.52,-14.5 168.52,-21.5"/>
<text text-anchor="middle" x="104.8" y="-21.8" font-family="Times-Roman" font-size="14.00">+</text>
<path fill="none" stroke="black" d="M43.1,-199.56C72.52,-166.38 133.83,-85.56 161.49,-43.8"/>
<polygon fill="black" stroke="black" points="164.51,-45.58 167,-35.28 158.63,-41.77 164.51,-45.58"/>
<text text-anchor="middle" x="97.29" y="-125.48" font-family="Times-Roman" font-size="14.00">1</text>
</g>
<!-- node2&#45;&gt;node0 -->
<g id="edge7" class="edge">
<title>node2&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M179,-36.07C192.15,-76 233.01,-171.75 256.26,-217.9"/>
<polygon fill="black" stroke="black" points="253.24,-219.68 260.94,-226.96 259.46,-216.47 253.24,-219.68"/>
<text text-anchor="middle" x="212.63" y="-130.78" font-family="Times-Roman" font-size="14.00">0</text>
</g>
<!-- node2&#45;&gt;node1 -->
<g id="edge8" class="edge">
<title>node2&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M159.2,-32.65C129.78,-65.82 68.47,-146.65 40.82,-188.4"/>
<polygon fill="black" stroke="black" points="37.79,-186.63 35.3,-196.92 43.67,-190.43 37.79,-186.63"/>
<text text-anchor="middle" x="95.01" y="-99.32" font-family="Times-Roman" font-size="14.00">0</text>
</g>
<!-- node2&#45;&gt;node2 -->
<g id="edge4" class="edge">
<title>node2&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M200.75,-24.69C211.33,-25.15 220.3,-22.92 220.3,-18 220.3,-13.08 211.33,-10.85 200.75,-11.31"/>
<text text-anchor="middle" x="225.3" y="-14.3" font-family="Times-Roman" font-size="14.00">0</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -725,7 +725,7 @@ tab
#+END_SRC
#+RESULTS:
:RESULTS:
:results:
| a | b | c | f |
| #f | 1 | cold | 4 |
| #f | 1 | hot | 5 |
@ -735,17 +735,17 @@ tab
| #t | 1 | hot | 6 |
| #t | 2 | cold | 4 |
| #t | 2 | hot | 5 |
:END:
: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 (unorgv simple-domains)))
(tabulate-network n (unorgv simple-domains))
(tabulate-network n)
#+END_SRC
#+RESULTS:
:RESULTS:
:results:
| a | b | c | f-a | f-b | f-c |
| #f | 1 | cold | #f | 2 | hot |
| #f | 1 | hot | #f | 2 | cold |
@ -755,7 +755,7 @@ tab
| #t | 1 | hot | #t | 1 | cold |
| #t | 2 | cold | #f | 2 | hot |
| #t | 2 | hot | #t | 1 | cold |
:END:
:end:
Let's snapshot this random network and give it a name.
#+NAME: rnd-network
@ -769,16 +769,16 @@ tab
| #t | 2 | cold | #f | 2 | hot |
| #t | 2 | hot | #t | 1 | cold |
Here's how we can read back this table as a Boolean network:
Here's how we can read back this table as a network:
#+HEADER: :var rnd-network=munch-sexp(rnd-network)
#+BEGIN_SRC racket :results output drawer
(string->any rnd-network)
#+END_SRC
#+RESULTS:
:RESULTS:
:results:
'(("a" "b" "c" "f-a" "f-b" "f-c") ("#f" 1 "cold" "#f" 2 "hot") ("#f" 1 "hot" "#f" 2 "cold") ("#f" 2 "cold" "#t" 1 "cold") ("#f" 2 "hot" "#t" 2 "hot") ("#t" 1 "cold" "#f" 2 "cold") ("#t" 1 "hot" "#t" 1 "cold") ("#t" 2 "cold" "#f" 2 "hot") ("#t" 2 "hot" "#t" 1 "cold"))
:END:
:end:
You can use =table->network= to convert a table such as [[rnd-network][rnd-network]]
to a network.
@ -788,19 +788,23 @@ tab
#+END_SRC
#+RESULTS:
:RESULTS:
'#hash((a . #<procedure:...dds/networks.rkt:518:4>) (b . #<procedure:...dds/networks.rkt:518:4>) (c . #<procedure:...dds/networks.rkt:518:4>))
:END:
:results:
(network '#hash((a . #<procedure:...ds/functions.rkt:145:4>) (b . #<procedure:...ds/functions.rkt:145:4>) (c . #<procedure:...ds/functions.rkt:145:4>)) '#hash((a . (#f #t)) (b . (1 2)) (c . (cold hot))))
:end:
Here's the state graph of [[rnd-network][rnd-network]].
#+NAME: rnd-network-sg
#+HEADER: :var rnd-network=munch-sexp(rnd-network)
#+HEADER: :var simple-domains=munch-sexp(simple-domains)
#+BEGIN_SRC racket :results silent drawer
(define n (table->network (unorg rnd-network)))
(define rnd-asyn (make-asyn-dynamics n))
(define states (list->set (build-all-states (unorgv simple-domains))))
(dotit (pretty-print-state-graph (dds-build-state-graph-annotated rnd-asyn states)))
((compose
dotit
pretty-print-state-graph
build-full-state-graph-annotated
make-asyn-dynamics
table->network
unorg)
rnd-network)
#+END_SRC
#+BEGIN_SRC dot :file dots/exampleHc023j.svg :results raw drawer :cmd sfdp :noweb yes
@ -808,17 +812,21 @@ tab
#+END_SRC
#+RESULTS:
:RESULTS:
:results:
[[file:dots/exampleHc023j.svg]]
:END:
:end:
Here's the signed interaction graph of [[rnd-network][rnd-network]].
#+NAME: rnd-network-ig
#+HEADER: :var rnd-network=munch-sexp(rnd-network)
#+HEADER: :var simple-domains=munch-sexp(simple-domains)
#+BEGIN_SRC racket :results silent drawer
(define n (table->network (unorg rnd-network)))
(dotit (build-signed-interaction-graph n (unorgv simple-domains)))
((compose
dotit
build-signed-interaction-graph
table->network
unorg)
rnd-network)
#+END_SRC
#+BEGIN_SRC dot :file dots/examplePIN5ac.svg :results raw drawer :cmd sfdp :noweb yes
@ -826,13 +834,9 @@ tab
#+END_SRC
#+RESULTS:
:RESULTS:
:results:
[[file:dots/examplePIN5ac.svg]]
:END:
Note that =build-signed-interaction-graph= only includes the + and
the - arcs in the graph, as it does not have access to the symbolic
description of the function.
:end:
** Standalone threshold Boolean functions (TBF)
/Note:/ Before using the objects described in this section,