def _create_reversible_ca(self, expected, rule): rows, _ = expected.shape cellular_automaton = expected[0] r = cpl.ReversibleRule(cellular_automaton.tolist()[0], rule) return cpl.evolve(cellular_automaton, timesteps=rows, apply_rule=r.apply_rule)
import numpy as np import cellpylib as cpl # NKS page 437 - Rule 214R # run the CA forward for 32 steps to get the initial condition for the next evolution cellular_automaton = cpl.init_simple(63) r = cpl.ReversibleRule(cellular_automaton[0], 214) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=32, apply_rule=r.apply_rule) # use the last state of the CA as the initial, previous state for this evolution r = cpl.ReversibleRule(cellular_automaton[-1], 214) cellular_automaton = np.array([cellular_automaton[-2]]) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=62, apply_rule=r.apply_rule) cpl.plot(cellular_automaton)
import matplotlib.pyplot as plt import numpy as np import cellpylib as cpl # NKS page 442 - Rule 122R cellular_automaton = np.array([[0] * 40 + [1] * 20 + [0] * 40]) rule = cpl.ReversibleRule(cellular_automaton[0], 122) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=1000, apply_rule=rule) timestep = [] bientropies = [] shannon_entropies = [] average_cell_entropies = [] apentropies = [] for i, c in enumerate(cellular_automaton): timestep.append(i) bit_string = ''.join([str(x) for x in c]) bientropies.append(cpl.ktbien(bit_string)) shannon_entropies.append(cpl.shannon_entropy(bit_string)) average_cell_entropies.append( cpl.average_cell_entropy(cellular_automaton[:i + 1])) apentropies.append(cpl.apen(bit_string, m=1, r=0)) print("%s, %s, %s, %s" % (i, bientropies[-1], shannon_entropies[-1], apentropies[-1])) plt.figure(1) plt.title("KTBiEn") plt.plot(timestep, bientropies)
# Ajustado especificamente para a regra 90 e sua reversão # plot the resulting CA evolution try: import cellpylib as cpl except: !pip install cellpylib import cellpylib as cpl from cellpylib import * #import cellpylib as cpl # initialize a CA with 200 cells (a random initialization is also available) cellular_automaton = cpl.init_simple(200) # evolve the CA for 100 time steps, using Rule 30 as defined in NKS cellular_automaton = cpl.evolve(cellular_automaton, timesteps=100, apply_rule=lambda n, c, t: cpl.nks_rule(n, 90)) # plot the resulting CA evolution cpl.plot(cellular_automaton) cellular_automaton = cpl.init_random(200) r = cpl.ReversibleRule(cellular_automaton[0], 90) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=100, apply_rule=r.apply_rule) # plot the resulting reverse CA evolution cpl.plot(cellular_automaton)