-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_pp_evolution.py
More file actions
52 lines (42 loc) · 1.46 KB
/
visualize_pp_evolution.py
File metadata and controls
52 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Run and visualize the PP model with evolving prey death rates.
Creates a 250x250 grid, enables per-cell evolution for `prey_death`, and
visualizes the grid every 5 iterations while running for 2500 steps.
"""
from models.CA import PP
def main():
params = {
"prey_birth": 0.2,
"prey_death": 0.05,
"predator_birth": 0.8,
"predator_death": 0.045,
}
pp = PP(
rows=250,
cols=250,
densities=(0.2, 0.05),
neighborhood="moore",
params=params,
cell_params=None,
seed=12345,
synchronous=True,
)
# Enable per-cell evolution for prey death rates. Use a small sd and
# reasonable clipping bounds so values remain in (0.001, 0.2).
pp.evolve("prey_death", sd=0.1, min_val=0.001, max_val=0.2)
# Start interactive visualization: update every 10 iterations
# Do not show neighbor histogram/percentile plots to reduce overhead
pp.visualize(interval=10, figsize=(12, 8), pause=0.1, show_cell_params=True, show_neighbors=True)
# Run the simulation (ensure the plot stays open afterwards)
try:
pp.run(2500)
finally:
# Block and show the final figure so the user can inspect it.
# Turn off interactive mode (visualize() enabled it) and show blocking.
import matplotlib.pyplot as plt
try:
plt.ioff()
except Exception:
pass
plt.show(block=True)
if __name__ == "__main__":
main()