Function Repository Resource:

AdaptiveCellularAutomaton (2.0.0) current version: 4.0.0 »

Source Notebook

Run an adaptive search for cellular automata

Contributed by: Willem Nielsen

ResourceFunction["AdaptiveCellularAutomaton"][<|"AdaptiveIterations"n|>]

returns n steps in an adaptive search, starting from the 3-color null rule and searching for rules that give longer finite length patterns.

ResourceFunction["AdaptiveCellularAutomaton"][<|"AdaptiveIterations"n, "InitialRule"{0,k,r}|>]

returns n steps in an adaptive evolution, starting from the k-color null rule and searching for rules that give longer finite length patterns.

ResourceFunction["AdaptiveCellularAutomaton"][evospec,"FinalState"]

returns only the final iteration in the adaptive evolution.

ResourceFunction["AdaptiveCellularAutomaton"][evospec,"BreakthroughStates"]

returns only the breakthrough iterations in the adaptive evolution.

ResourceFunction["AdaptiveCellularAutomaton"][evospec,sequencespec,"Plot"]

returns the plotted cellular automata for each step specified by the sequence specification.

ResourceFunction["AdaptiveCellularAutomaton"][evospec,sequencespec,"Fitness"]

returns only the fitness values.

ResourceFunction["AdaptiveCellularAutomaton"][evospec,sequencespec,propertyspec]

returns all the information specified by the property specification.

Details and Options

The following arguments can be given for the sequence specification sequencespec:
All(default) returns all the iterations in the evolution
"FinalState"returns the final iteration in the evolution
"BreakthroughStates"returns the breakthrough iterations in the evolution
The following arguments can be given for the property specification propertyspec:
AllAssociation with all the properties listed below
"BestRule"most fit rule found so far
"BestInitialCondition"most fit initial condition found so far
"BestFitness"highest fitness value found so far
"Rule"rule that was tried at each step
"InitialCondition"initial condition that was tried at each step
"Fitness"fitness at each step
"Lifetime"number of steps before the automaton reaches the all-white state
"Width"maximum length non-zero range in the pattern
"AspectRatio""Width" metric divided by the "Lifetime"
"Index"iteration index
{"BestRule", "BestFitness"}(default) returns an Association with best rule and fitness found so far
{propertyspec1, propertyspec2 , propertyspecn }Association with the specified properties
The following keys can be used for the evolution specification:
"InitialRule"{0, 3, 1}the initial rule, and the color-space and radius to use
"InitialCondition"{{1}, 0}the initial condition
"MaxSteps"100the number of steps to search to determine if the rule halts
"AdaptiveIterations"1000the number of iterations to do in the search
"MutationFunction"1the type and number of mutations to do
"FitnessFunction""Lifetime"the fitness function to use
"SelectionFunction"#1>=#2&the selection function to use
The fitness function specification can have the following values:
"Lifetime"evolve to a longer finite lifetime
"Width"evolve to a wider pattern that still halts
"AspectRatio"evolve to a larger aspect ratio defined as the width over the lifetime
typetargetevolve to a target value for the given fitness type
funfunction taking the rule and initial condition and returning the fitness to assign
The mutation function specification can have the following values:
nrandomly mutate n cases in the rule
"Rule" -> nrandomly mutate n cases in the rule
"InitialCondition" -> nrandomly mutate a single bit in the initial condition
funa function taking the rule and returning the mutated version
<|"Rule"funrule, "InitialCondition"funic|>mutates the rule and initial condition using the specified functions
The following keys can be used for the evolution specification:
"InitialRule"{0, 3, 1}the initial rule, and the color-space and radius to use
"InitialCondition"{{1}, 0}the initial condition
"MaxSteps"100the number of steps to search to determine if the rule halts
"AdaptiveIterations"1000the number of iterations to do in the search
"MutationFunction"1the type and number of mutations to do
"FitnessFunction""Lifetime"the fitness function to use
"SelectionFunction"#1>=#2&the selection function to use
The following are all the unique options for AdaptiveCellularAutomaton. It also accepts RandomSeeding and any options for ArrayPlot:
"PlottingRegion""Lifetime"accepts any time and offset specification for the CellularAutomaton function
"PlotSizingFunction"({Automatic,30Sqrt[#Height]}&)takes arguments "Height" and "Width" and returns an ImageSize specification
"PlottingFunction"Automatictakes arguments from the state and returns a plot
"HorizontalPadding"1the number of white cells to add on either side of the pattern
"PlotLabels"Nonetakes "Lifetime", "Width", "AspectRatio" or a function that is applied to the state
"VerticalPadding"1the number of blank rows to add to the bottom of the pattern
"LabelSize"11size of the labels given to the Style function

Examples

Basic Examples (1) 

Run a search for 3 steps starting from the null k=3, r=1 rule and return every step in the search:

In[1]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"AdaptiveIterations" -> 3|>]
Out[1]=

Scope (7) 

Evolve for 500 steps and plot the breakthrough mutation steps:

In[2]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", RandomSeeding -> 1110]
Out[2]=

Evolve for 500 steps and plot the breakthrough mutation steps:

In[3]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", RandomSeeding -> 1110]
Out[3]=

Plot the progressive fitness values showing the mutations that weren't selected:

In[4]:=
Show[ListStepPlot[#BestFitness & /@ #], ListPlot[#Fitness & /@ #, PlotStyle -> Red]] &[
 ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"AdaptiveIterations" -> 500|>, All, {"Fitness", "BestFitness"}, RandomSeeding -> 1110]]
Out[4]=

Plot the progressive fitness values for 10 evolutions:

In[5]:=
ListStepPlot[
 Table[ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"AdaptiveIterations" -> 500|>, All, "Fitness"], 10], PlotRange -> All]
Out[5]=

Plot the final states of 10 different evolutions:

In[6]:=
Table[ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"AdaptiveIterations" -> 500|>, "FinalState", "Plot", RandomSeeding -> 1110 + i], {i, 10}]
Out[6]=

Evolve a k = 4 cellular automata:

In[7]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 4, 1}, "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", RandomSeeding -> 1112]
Out[7]=

Evolve for longer automata using "MaxSteps":

In[8]:=
SeedRandom[1118]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 4, 1}, "AdaptiveIterations" -> 500, "MaxSteps" -> 200|>, "BreakthroughStates", "Plot", "PlotSizingFunction" -> (30 #Height^.1 &)]
Out[8]=

Evolve to a specific target lifetime:

In[9]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 4, 1}, "AdaptiveIterations" -> 2000, "FitnessFunction" -> "Lifetime" -> 50, "MaxSteps" -> 200|>, "BreakthroughStates", "Plot", "PlotLabels" -> "Lifetime", RandomSeeding -> 1121]
Out[9]=

10 separate evolutions to a target lifetime of 50:

In[10]:=
ParallelTable[
 ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 4, 1}, "AdaptiveIterations" -> 2000, "FitnessFunction" -> "Lifetime" -> 50, "MaxSteps" -> 200|>, "FinalState", "Plot", "PlotLabels" -> "Lifetime", "PlotSizingFunction" -> ({Automatic, 20 #Height^.5} &), RandomSeeding -> 1118 + i], {i, 10}]
Out[10]=

See the fitness progressions:

In[11]:=
ListStepPlot[
 ParallelTable[
  ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 4, 1}, "AdaptiveIterations" -> 2000, "FitnessFunction" -> "Lifetime" -> 50, "MaxSteps" -> 200|>, All, "BestFitness", RandomSeeding -> 1118 + i], {i, 10}]]
Out[11]=

Evolve the initial conditions of a cellular automata:

In[12]:=
SeedRandom[444330]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {1246491453600, 3, 1},
   "InitialCondition" -> {CenterArray[1, 20], 0}, "MutationFunction" -> ("InitialCondition" -> 1), "AdaptiveIterations" -> 2000|>, "BreakthroughStates", "Plot"]
Out[12]=

The default selection function accepts neutral mutations by default, make it so that it accepts mutations that decrease fitness by 1:

In[13]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<| "Depth" -> 1000, "SelectionFunction" -> (#2 - #1 <= 1 &)|>, "BreakthroughStates", "Plot", "PlottingRegion" -> 50, RandomSeeding -> 445550]
Out[13]=

Use a fitness function that looks for repeating automata rather than terminating ones:

In[14]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {256, 4, 1}, "AdaptiveIterations" -> 4000,
  "MutationFunction" -> {1, "Symmetric" -> True}, "FitnessFunction" -> (If[# === 201, -Infinity, #] &[
      Length[Last[
        FindTransientRepeat[CellularAutomaton[#1, {{1}, 0}, 200], 1]]]] &)|>, "BreakthroughStates", "Plot", "PlottingRegion" -> (2 #Fitness &), RandomSeeding -> 100035]
Out[14]=

Write a mutation function that has a higher probability flipping a rule to white or blue:

In[15]:=
ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|"InitialRule" -> {0, 3, 1}, "AdaptiveIterations" -> 500,
  "MutationFunction" -> ({FromDigits[
       MapAt[RandomChoice[{0.75, 0.25} -> DeleteCases[Range[0, 2], #]] &, IntegerDigits[First[#BestRule], 3, 27], RandomInteger[{1, Length[IntegerDigits[First[#BestRule], 3, 27]] - 1}]], 3], 3, 1} &)|>, "BreakthroughStates", "Plot", RandomSeeding -> 100035]
Out[15]=

Options (4) 

Use a custom plot sizing function:

In[16]:=
SeedRandom[1110]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", "PlotSizingFunction" -> (3 #Height &)]
Out[16]=

When "Plot" is specified AdaptiveCellularAutomaton will use any ArrayPlot options given:

In[17]:=
SeedRandom[1110]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", Mesh -> True]
Out[17]=

Plot with a specified region:

In[18]:=
SeedRandom[1110]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", "PlottingRegion" -> 30]
Out[18]=

Specify the width and height of the region:

In[19]:=
SeedRandom[1110]; ResourceFunction["AdaptiveCellularAutomaton", ResourceVersion->"2.0.0"][<|
  "AdaptiveIterations" -> 500|>, "BreakthroughStates", "Plot", "PlottingRegion" -> {30, {-5, 5}}]
Out[19]=

Publisher

Willem Nielsen

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 4.0.0 – 16 March 2026
  • 3.0.0 – 25 February 2026
  • 2.3.0 – 05 January 2026
  • 2.2.0 – 03 October 2025
  • 2.1.0 – 17 September 2025
  • 2.0.0 – 05 September 2025
  • 1.0.0 – 27 June 2025

Related Resources

Author Notes

The most recent version of AdaptiveCellularAutomaton is incompatible with version 1.0.0. You can use ResourceFunction["AdaptiveCellularAutomaton",ResourceVersion->"1.0.0"] to use the old version.

License Information