Skip to content

Commit 126307d

Browse files
committed
Added evolution of parameters
1 parent ab445a2 commit 126307d

2 files changed

Lines changed: 325 additions & 27 deletions

File tree

docs/prompts.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Create base CA class
1+
## Base CA class
22
For the start of this project, we need a strong baseline. This prompt creates a basic cellular automaton class with general logic. This can then be filled in by overriding the update function and adding visualizations.
33

44
### prompt
@@ -156,7 +156,7 @@ class CA:
156156
### changes
157157
Removed a few unnecessary lines.
158158

159-
## Add predator-prey model and asynchronous updating
159+
## Predator-prey model and asynchronous updating
160160
Now the basic predator-prey update rules need to be defined. This is done by creating a predator-prey class inheriting the CA class and overriding the update function. We will create the possibility for either synchronous and asynchronous updating. We will start with only implementing the asynchronous rules here, as those are easier to implement. Later, we can implement the faster synchronous updating based on the asynchronous rules.
161161

162162
### prompt
@@ -298,8 +298,9 @@ class PP(CA):
298298
self.update_async()
299299

300300
### changes
301+
Changed default behavior to synchronous updating after it was implemented. Added default behavior for all arguments.
301302

302-
## Add synchronous updating
303+
## Synchronous updating
303304
Now we add the asyncrhonous updating, making sure the functionality is the vectorized equivalent of the asynchronous function.
304305

305306
### prompt
@@ -415,7 +416,7 @@ Implement the synchronous updating for the PP class as a vectorized (optimized)
415416
### changes
416417
Swapped the order of birth and death checks. This results in the same behavior, but removes the need to check whether the post-birth grid matches the reference grid.
417418

418-
## Add basic visualisations
419+
## Basic visualisations
419420
Basic tests pass and the grid updates seem plausible, but to see it in better detail we need to add visualisation. A first step in this is an imshow plot which updates every N iterations.
420421

421422
### prompt
@@ -527,6 +528,16 @@ For both classes, ensure that the matplotlib library is not needed to run the si
527528

528529
### changes
529530

531+
## Evolution of parameters
532+
Now we need to add functionality allowing parameters to evolve. Specifically, we are interested in the prey death rates. To do this we track another grid with values for the death rate of each prey on the grid. When a prey reproduces, we add Gaussian noise to the death rate inherited from the parent.
533+
534+
### prompt
535+
In the PP class, create functionality for evolving / mutating parameters. Create a new function called evolve which takes a str which will be the parameter to evolve. This should correspond to any of the known parameters. Then, create an array in cell_params, filling the cells occupied by the relevant species (prey for "prey_death", predator for "predator_birth", etc.) with the global parameter in params. The other cells (either empty or occupied by the other species) should be either zero or NaN. Additionally, the function should take a standard deviation, minimum, and maximum for the parameter. These values should have defaults: 0.05, 0.01, and 0.99.
536+
537+
In the asynchronous and synchronous update functions, make the following changes. When the relevant species reproduces, the newly born predator or prey inherits the parameter value from their parent, with Gaussian noise of the standard deviation defined in the evolve function. Clip the parameter between the minimum and maximum. Place this new value into its cell_params grid. When a predator or prey dies, or when a prey gets eaten, remove their parameter values from the cell_params grid, such that the only non-zero (or non-NaN) elements in the cell_params grid correspond to a cell occupied by the relevant species.
538+
539+
Ensure that if the cell_params grids are set (by the evolve function), the cell-specific parameters are used in the updates. For instance, the deaths of the prey should be calculated based on the values in the cell_params grid, not the global params value. Since the cell_params grid's only non-zero (or non-NaN) entries are active cells of the relevant species, there is no need to get the occupied prey / predator cells from PP.grid.
540+
530541

531542
### Mean Field class
532543

0 commit comments

Comments
 (0)