Anneal
dissmodel.models.ca.anneal.Anneal
Bases: CellularAutomaton
Cellular automaton implementing the Anneal rule.
The Anneal rule is a majority-vote variant that produces smooth,
blob-like regions. Each cell's next state depends on the count of
neighbors (including itself) in state L:
- count ≤ 3 →
R - count == 4 →
L - count == 5 →
R - count ≥ 6 →
L
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 regular_grid
>>> from dissmodel.core import Environment
>>> gdf = regular_grid(dimension=(20, 20), resolution=1, attrs={"state": 0})
>>> env = Environment(end_time=10)
>>> ca = Anneal(gdf=gdf)
>>> ca.initialize()
Source code in dissmodel/models/ca/anneal.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 | |
initialize()
Fill the grid with a random initial state.
Each cell is assigned L or R with equal probability.
Source code in dissmodel/models/ca/anneal.py
62 63 64 65 66 67 68 69 70 71 | |
rule(idx)
Apply the Anneal transition rule to cell idx.
Counts the number of cells in state L among the cell's
neighbors plus the cell itself, then applies the threshold rule.
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/anneal.py
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 | |
setup()
Build the Queen neighborhood for the grid.
Source code in dissmodel/models/ca/anneal.py
58 59 60 | |
dissmodel.models.ca.anneal.AnnealState
Bases: IntEnum
Possible states for a cell in :class:Anneal.
Attributes:
| Name | Type | Description |
|---|---|---|
L |
int
|
Left state (0). |
R |
int
|
Right state (1). |
Source code in dissmodel/models/ca/anneal.py
12 13 14 15 16 17 18 19 20 21 22 23 24 | |