Propagation
dissmodel.models.ca.propagation.Propagation
Bases: CellularAutomaton
Stochastic spatial propagation cellular automaton.
Active cells (ON) spread to inactive neighbors with probability
:attr:prob. Once a cell becomes active, it stays active permanently.
The neighborhood is based on K-nearest neighbors (KNN, k=4).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame with geometries and a |
required |
**kwargs
|
Any
|
Extra keyword arguments forwarded to
:class: |
{}
|
Examples:
>>> from dissmodel.geo import vector_grid
>>> from dissmodel.core import Environment
>>> gdf = vector_grid(dimension=(20, 20), resolution=1, attrs={"state": 0})
>>> env = Environment(end_time=15)
>>> prop = Propagation(gdf=gdf)
>>> prop.initialize()
Source code in dissmodel/models/ca/propagation.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
initialize()
Fill the grid with a random initial state.
Uses :attr:initial_density to determine the proportion of
cells that start as active. The remaining cells start as inactive.
Source code in dissmodel/models/ca/propagation.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
rule(idx)
Apply the stochastic propagation rule to cell idx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
any
|
Index of the cell being evaluated. |
required |
Returns:
| Type | Description |
|---|---|
int
|
New state for the cell:
|
Source code in dissmodel/models/ca/propagation.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
setup(prob=0.1, initial_density=0.4)
Configure the model and build the neighborhood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prob
|
float
|
Probability of activation per step for inactive cells adjacent to at least one active cell, by default 0.1. |
0.1
|
initial_density
|
float
|
Initial proportion of active cells, by default 0.4. |
0.4
|
Source code in dissmodel/models/ca/propagation.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
dissmodel.models.ca.propagation.PropagationState
Bases: IntEnum
Possible states for a cell in :class:Propagation.
Attributes:
| Name | Type | Description |
|---|---|---|
OFF |
int
|
Inactive cell, can be activated by neighbors. |
ON |
int
|
Active cell, spreads to neighbors. |
Source code in dissmodel/models/ca/propagation.py
12 13 14 15 16 17 18 19 20 21 22 23 24 | |