Input:
collection of rules
width, time [ initial rule array ]
loss function (applied to final state)
sequence of initial conditions [or just one]
collection of rules
width, time [ initial rule array ]
loss function (applied to final state)
sequence of initial conditions [or just one]
Parameters:
Number of individuals to maintain
Branching factor at each step [number of mutated outputs]
(( Batch size (i.e. number of initial conditions to try for each individual in computing the loss) ))
Branching factor at each step [number of mutated outputs]
(( Batch size (i.e. number of initial conditions to try for each individual in computing the loss) ))
<|"PopulationSize"->XXXX,"MutationsPerStep"->XXXX(*couldberandomnumber*),"MutationsPerStepFunction"->Automatic|>
ICATrain[{rulelist_,initrulearray_},{init->final,init->final,....},LossFunction->XXXXX,"NumberOfMutationsToTry"->XXXX,"PopulationToMaintain"->XXXXX]
(Number of mutations is roughly like LearningRate)
In[]:=
ica[rules_,state_]:=MapIndexed[CellularAutomaton[rules[[First[#2]]]][#][[2]]&,RotateLeft[Partition[state,3,1,1],-1]]
In[]:=
cainf[ra_,init_]:=Fold[ica[#2,#1]&,init,ra]
In[]:=
cainflist[ra_,init_]:=FoldList[ica[#2,#1]&,init,ra]
In[]:=
icaplotshift[ra_,init_,opts___]:=ArrayPlot[MapThread[List,{Most[cainflist[ra,init]],ra},2],ColorRules->{{1,170}->Darker[Pink,.5],{0,170}->Lighter[Pink,.7],{1,240}->Darker[Yellow,.5],{0,240}->Lighter[Yellow,.7]}]
In[]:=
icaplotgen[{rules_,ra_},init_,opts___]:=ArrayPlot[MapThread[List,{Most[cainflist[Map[rules[[#]]&,ra,{2}],init]],ra},2],ColorRules->{{1,1}->Darker[Pink,.5],{0,1}->Lighter[Pink,.7],{1,2}->Darker[Yellow,.5],{0,2}->Lighter[Yellow,.7]}]
In[]:=
icaplotgenx[{rules_,ra_},init_,opts___]:=With[{arr=cainflist[Map[rules[[#]]&,ra,{2}],init]},ArrayPlot[Append[MapThread[List,{Most[arr],ra},2],{#,1}&/@Last[arr]],opts,ColorRules->{{1,1}->Darker[Pink,.5],{0,1}->Lighter[Pink,.7],{1,2}->Darker[Yellow,.5],{0,2}->Lighter[Yellow,.7]}]]
In[]:=
icagenfinal[{rules_,ra_},init_]:=cainf[Map[rules[[#]]&,ra,{2}],init]
In[]:=
randupdate[array_]:=MapAt[{2,1}[[#]]&,array,RandomInteger[{1,#}]&/@Dimensions[array]]
In[]:=
randupdate[array_,n_]:=MapAt[{2,1}[[#]]&,array,Table[RandomInteger[{1,#}]&/@Dimensions[array],n]]
In[]:=
NestList[First@TakeSmallestBy[Table[randupdate[#],100],Abs[Total[icagenfinal[{{170,240},#},CenterArray[Table[1,10],20]]]-10]&,1]&,RandomChoice[{1,2},{40,20}],10];