example: Explain how to read back and explore networks from Org tables.

This commit is contained in:
Sergiu Ivanov 2020-05-08 23:33:43 +02:00
parent 036b9b7973
commit 32b2e41634
3 changed files with 296 additions and 0 deletions

View file

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.0 (0)
-->
<!-- Title: G Pages: 1 -->
<svg width="1026pt" height="907pt"
viewBox="0.00 0.00 1025.62 907.34" 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 903.34)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-903.34 1021.62,-903.34 1021.62,4 -4,4"/>
<!-- node0 -->
<g id="node1" class="node">
<title>node0</title>
<ellipse fill="none" stroke="black" cx="543.41" cy="-293.39" rx="77.19" ry="18"/>
<text text-anchor="middle" x="543.41" y="-289.69" font-family="Times-Roman" font-size="14.00">a:#f b:1 c:cold</text>
</g>
<!-- node0&#45;&gt;node0 -->
<g id="edge3" class="edge">
<title>node0&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M615.75,-299.79C629.25,-299.01 638.75,-296.87 638.75,-293.39 638.75,-289.91 629.25,-287.78 615.75,-286.99"/>
<text text-anchor="middle" x="652.25" y="-289.69" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
<!-- node5 -->
<g id="node6" class="node">
<title>node5</title>
<ellipse fill="none" stroke="black" cx="339.8" cy="-18" rx="77.19" ry="18"/>
<text text-anchor="middle" x="339.8" y="-14.3" font-family="Times-Roman" font-size="14.00">a:#f b:2 c:cold</text>
</g>
<!-- node0&#45;&gt;node5 -->
<g id="edge1" class="edge">
<title>node0&#45;&gt;node5</title>
<path fill="none" stroke="black" d="M530.05,-275.32C493.07,-225.3 389.67,-85.45 352.95,-35.78"/>
<text text-anchor="middle" x="427.5" y="-159.35" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
<!-- node7 -->
<g id="node8" class="node">
<title>node7</title>
<ellipse fill="none" stroke="black" cx="899.18" cy="-482.68" rx="73.39" ry="18"/>
<text text-anchor="middle" x="899.18" y="-478.98" font-family="Times-Roman" font-size="14.00">a:#f b:1 c:hot</text>
</g>
<!-- node0&#45;&gt;node7 -->
<g id="edge2" class="edge">
<title>node0&#45;&gt;node7</title>
<path fill="none" stroke="black" d="M574.67,-310.02C642.24,-345.97 801.21,-430.56 868.37,-466.29"/>
<text text-anchor="middle" x="708.52" y="-391.96" font-family="Times-Roman" font-size="14.00">{c}</text>
</g>
<!-- node1 -->
<g id="node2" class="node">
<title>node1</title>
<ellipse fill="none" stroke="black" cx="227.61" cy="-346.49" rx="77.19" ry="18"/>
<text text-anchor="middle" x="227.61" y="-342.79" font-family="Times-Roman" font-size="14.00">a:#t b:2 c:cold</text>
</g>
<!-- node1&#45;&gt;node1 -->
<g id="edge6" class="edge">
<title>node1&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M299.95,-352.89C313.45,-352.1 322.95,-349.97 322.95,-346.49 322.95,-343.01 313.45,-340.87 299.95,-340.08"/>
<text text-anchor="middle" x="336.95" y="-342.79" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
<!-- node1&#45;&gt;node5 -->
<g id="edge5" class="edge">
<title>node1&#45;&gt;node5</title>
<path fill="none" stroke="black" d="M233.8,-328.36C253.42,-270.93 314.04,-93.43 333.63,-36.07"/>
<text text-anchor="middle" x="270.22" y="-186.02" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
<!-- node6 -->
<g id="node7" class="node">
<title>node6</title>
<ellipse fill="none" stroke="black" cx="397.23" cy="-767.75" rx="73.39" ry="18"/>
<text text-anchor="middle" x="397.23" y="-764.05" font-family="Times-Roman" font-size="14.00">a:#t b:2 c:hot</text>
</g>
<!-- node1&#45;&gt;node6 -->
<g id="edge4" class="edge">
<title>node1&#45;&gt;node6</title>
<path fill="none" stroke="black" d="M234.9,-364.59C262.74,-433.72 362.18,-680.69 389.97,-749.71"/>
<text text-anchor="middle" x="299.43" y="-560.95" 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="166.36" cy="-546.59" rx="77.19" ry="18"/>
<text text-anchor="middle" x="166.36" y="-542.89" font-family="Times-Roman" font-size="14.00">a:#t b:1 c:cold</text>
</g>
<!-- node2&#45;&gt;node0 -->
<g id="edge13" class="edge">
<title>node2&#45;&gt;node0</title>
<path fill="none" stroke="black" d="M191.98,-529.39C258.08,-485 434.41,-366.59 509.16,-316.39"/>
<polygon fill="black" stroke="black" points="511.4,-319.1 517.75,-310.62 507.5,-313.29 511.4,-319.1"/>
<text text-anchor="middle" x="337.07" y="-426.69" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
<!-- node2&#45;&gt;node1 -->
<g id="edge14" class="edge">
<title>node2&#45;&gt;node1</title>
<path fill="none" stroke="black" d="M171.91,-528.48C182.63,-493.45 206.28,-416.19 219.04,-374.49"/>
<polygon fill="black" stroke="black" points="222.46,-375.29 222.04,-364.7 215.76,-373.24 222.46,-375.29"/>
<text text-anchor="middle" x="181.47" y="-455.28" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
<!-- node2&#45;&gt;node2 -->
<g id="edge7" class="edge">
<title>node2&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M238.7,-552.99C252.2,-552.2 261.71,-550.07 261.71,-546.59 261.71,-543.11 252.2,-540.97 238.7,-540.19"/>
<text text-anchor="middle" x="274.71" y="-542.89" font-family="Times-Roman" font-size="14.00">{c}</text>
</g>
<!-- node3 -->
<g id="node4" class="node">
<title>node3</title>
<ellipse fill="none" stroke="black" cx="73.44" cy="-881.34" rx="73.39" ry="18"/>
<text text-anchor="middle" x="73.44" y="-877.64" font-family="Times-Roman" font-size="14.00">a:#t b:1 c:hot</text>
</g>
<!-- node3&#45;&gt;node2 -->
<g id="edge15" class="edge">
<title>node3&#45;&gt;node2</title>
<path fill="none" stroke="black" d="M78.44,-863.34C93.75,-808.17 140.12,-641.12 158.62,-574.48"/>
<polygon fill="black" stroke="black" points="162.04,-575.25 161.34,-564.68 155.3,-573.38 162.04,-575.25"/>
<text text-anchor="middle" x="105.53" y="-722.71" font-family="Times-Roman" font-size="14.00">{c}</text>
</g>
<!-- node3&#45;&gt;node3 -->
<g id="edge8" class="edge">
<title>node3&#45;&gt;node3</title>
<path fill="none" stroke="black" d="M142.04,-887.79C155.4,-887.04 164.89,-884.89 164.89,-881.34 164.89,-877.79 155.4,-875.64 142.04,-874.89"/>
<text text-anchor="middle" x="191.89" y="-877.64" font-family="Times-Roman" font-size="14.00">{b}{a}</text>
</g>
<!-- node4 -->
<g id="node5" class="node">
<title>node4</title>
<ellipse fill="none" stroke="black" cx="797.87" cy="-810.24" rx="73.39" ry="18"/>
<text text-anchor="middle" x="797.87" y="-806.54" font-family="Times-Roman" font-size="14.00">a:#f b:2 c:hot</text>
</g>
<!-- node4&#45;&gt;node4 -->
<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>
</g>
<!-- node4&#45;&gt;node6 -->
<g id="edge16" class="edge">
<title>node4&#45;&gt;node6</title>
<path fill="none" stroke="black" d="M730.36,-803.08C659.76,-795.59 549.09,-783.85 474.9,-775.98"/>
<polygon fill="black" stroke="black" points="475,-772.47 464.68,-774.9 474.26,-779.43 475,-772.47"/>
<text text-anchor="middle" x="589.13" y="-793.33" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
<!-- node5&#45;&gt;node5 -->
<g id="edge10" class="edge">
<title>node5&#45;&gt;node5</title>
<path fill="none" stroke="black" d="M412.14,-24.4C425.64,-23.61 435.15,-21.48 435.15,-18 435.15,-14.52 425.64,-12.39 412.14,-11.6"/>
<text text-anchor="middle" x="448.15" y="-14.3" font-family="Times-Roman" font-size="14.00">{c}</text>
</g>
<!-- node6&#45;&gt;node3 -->
<g id="edge17" class="edge">
<title>node6&#45;&gt;node3</title>
<path fill="none" stroke="black" d="M354.9,-782.6C295.8,-803.33 188.65,-840.92 124.98,-863.26"/>
<polygon fill="black" stroke="black" points="123.8,-859.96 115.53,-866.57 126.12,-866.57 123.8,-859.96"/>
<text text-anchor="middle" x="225.94" y="-826.73" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
<!-- node6&#45;&gt;node6 -->
<g id="edge11" class="edge">
<title>node6&#45;&gt;node6</title>
<path fill="none" stroke="black" d="M465.82,-774.2C479.19,-773.45 488.68,-771.3 488.68,-767.75 488.68,-764.2 479.19,-762.05 465.82,-761.3"/>
<text text-anchor="middle" x="502.18" y="-764.05" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
<!-- node7&#45;&gt;node4 -->
<g id="edge18" class="edge">
<title>node7&#45;&gt;node4</title>
<path fill="none" stroke="black" d="M893.59,-500.76C876.78,-555.12 826.6,-717.36 806.42,-782.61"/>
<polygon fill="black" stroke="black" points="803.06,-781.63 803.45,-792.21 809.74,-783.7 803.06,-781.63"/>
<text text-anchor="middle" x="836" y="-645.48" font-family="Times-Roman" font-size="14.00">{b}</text>
</g>
<!-- node7&#45;&gt;node7 -->
<g id="edge12" class="edge">
<title>node7&#45;&gt;node7</title>
<path fill="none" stroke="black" d="M967.77,-489.13C981.13,-488.38 990.62,-486.23 990.62,-482.68 990.62,-479.13 981.13,-476.98 967.77,-476.23"/>
<text text-anchor="middle" x="1004.12" y="-478.98" font-family="Times-Roman" font-size="14.00">{a}</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.9 KiB

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- 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)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-40 409.24,-40 409.24,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>
</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 -->
<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>
</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>
</g>
<!-- node1&#45;&gt;node2 -->
<g id="edge2" 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>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -576,6 +576,82 @@ tab
| #t | 2 | hot | #t | 1 | cold | | #t | 2 | hot | #t | 1 | cold |
:END: :END:
Let's snapshot this random network and give it a name.
#+NAME: rnd-network
| 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 |
Here's how we can read back this table as a Boolean network:
#+HEADER: :var rnd-network=munch-sexp(rnd-network)
#+BEGIN_SRC racket :results output drawer
(string->any rnd-network)
#+END_SRC
#+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:
You can use =table->network= to convert a table such as [[rnd-network][rnd-network]]
to a network.
#+HEADER: :var rnd-network=munch-sexp(rnd-network)
#+BEGIN_SRC racket :results output drawer
(table->network (unorg rnd-network))
#+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:
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)))
#+END_SRC
#+BEGIN_SRC dot :file dots/exampleHc023j.svg :results raw drawer :cmd sfdp :noweb yes
<<rnd-network-sg()>>
#+END_SRC
#+RESULTS:
:RESULTS:
[[file:dots/exampleHc023j.svg]]
: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)))
#+END_SRC
#+BEGIN_SRC dot :file dots/examplePIN5ac.svg :results raw drawer :cmd sfdp :noweb yes
<<rnd-network-ig()>>
#+END_SRC
#+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.
* Reaction systems * Reaction systems
:PROPERTIES: :PROPERTIES: