Skip to content

Commit

Permalink
updating demo docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lantunes committed May 22, 2021
1 parent 5f2cb8b commit fd13c96
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions demos/animation_demo/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Animating Network Automata

Network Automata can be animated with the Netomaton `animate` function.
Network Automata can be animated with the Netomaton `animate_activities` function.

For example, the evolution of a 2D 60x60 Cellular Automaton can be
visualized using:
```python
ntm.animate(activities, shape=(60, 60), interval=150)
ntm.animate_activities(trajectory, shape=(60, 60), interval=150)
```
<img src="../../resources/animation2D.gif" width="40%"/>

The evolution of a 1D Celluar Automaton with 200 cells can be visualized
using:
```python
# note that the shape specified is a tuple containing only a single value
ntm.animate(activities, shape=(200,))
ntm.animate_activities(trajectory, shape=(200,))
```
<img src="../../resources/animation1D.gif" width="40%"/>

Expand All @@ -22,7 +22,7 @@ timestep, that vector can be reshaped and visualized however desired.
For example, the evolution of a 1D Cellular Automaton with 225 cells
can be visualized as if it were a 2D Cellular Automation, using:
```python
ntm.animate(activities, shape=(15, 15))
ntm.animate_activities(trajectory, shape=(15, 15), interval=100)
```
<img src="../../resources/animation1Db.gif" width="40%"/>

Expand Down
8 changes: 5 additions & 3 deletions demos/asynchronous_automata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ automaton from Wolfram's NKS Notes on Chapter 9, section 10:
```python
import netomaton as ntm

adjacency_matrix = ntm.topology.adjacency.cellular_automaton(n=21)
network = ntm.topology.cellular_automaton(n=21)

initial_conditions =[0]*10 + [1] + [0]*10

r = ntm.AsynchronousRule(activity_rule=ntm.rules.nks_ca_rule(60),
update_order=range(1, 20))

activities, adjacencies = ntm.evolve(initial_conditions, adjacency_matrix, timesteps=19*20,
activity_rule=r)
trajectory = ntm.evolve(initial_conditions=initial_conditions, network=network,
timesteps=19*20, activity_rule=r)

# plot every 19th row, including the first, as a cycle is completed every 19 rows
activities = ntm.get_activities_over_time_as_list(trajectory)
ntm.plot_grid(activities[::19])
```

<img src="../../resources/rule60async.png" width="40%"/>

The full source code for this example can be found [here](asynchronous_automata_demo.py).
9 changes: 5 additions & 4 deletions demos/ca_density_classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import netomaton as ntm
import numpy as np

# set r to 3, for a neighbourhood size of 7
adjacency_matrix = ntm.topology.adjacency.cellular_automaton(149, r=3)
network = ntm.topology.cellular_automaton(149, r=3)

initial_conditions = np.random.randint(0, 2, 149)

Expand All @@ -30,11 +30,12 @@ rule_number = 6667021275756174439087127638698866559

print("density of 1s: %s" % (np.count_nonzero(initial_conditions) / 149))

activities, adjacencies = ntm.evolve(initial_conditions, adjacency_matrix, timesteps=149,
activity_rule=ntm.rules.binary_ca_rule(rule_number))
trajectory = ntm.evolve(initial_conditions=initial_conditions, network=network,
activity_rule=ntm.rules.binary_ca_rule(rule_number), timesteps=149)

ntm.plot_grid(activities)
ntm.plot_activities(trajectory)
```

<img src="../../resources/density_classification.png" width="50%"/>

The full source code for this example can be found [here](ca_density_classification_demo.py).
Expand Down
13 changes: 7 additions & 6 deletions demos/continuous_automata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ from Wolfram's NKS book, found on page 157:
import math
import netomaton as ntm

adjacency_matrix = ntm.topology.adjacency.cellular_automaton(n=200)
network = ntm.topology.cellular_automaton(n=200)

initial_conditions = [0.0]*100 + [1.0] + [0.0]*99

# NKS page 157
# NKS page 157
def activity_rule(ctx):
activities = ctx.activities
activities = ctx.neighbourhood_activities
result = (sum(activities) / len(activities)) * (3 / 2)
frac, whole = math.modf(result)
return frac

activities, adjacencies = ntm.evolve(initial_conditions, adjacency_matrix, timesteps=150,
activity_rule=activity_rule)
trajectory = ntm.evolve(initial_conditions=initial_conditions, network=network,
activity_rule=activity_rule, timesteps=150)

ntm.plot_grid(activities)
ntm.plot_activities(trajectory)
```

<img src="../../resources/continuous_ca.png" width="40%"/>

The full source code for this example can be found [here](continuous_automata_demo.py).

0 comments on commit fd13c96

Please sign in to comment.