0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] half_two = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] half_zero = [-1 if x == 0 else x for x in half_zero] half_one = [-1 if x == 0 else x for x in half_one] half_two = [-1 if x == 0 else x for x in half_two] cellular_automaton = np.array([half_two]) hopfield_net = cpl.HopfieldNet(num_cells=35) hopfield_net.train(P) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=155, apply_rule=hopfield_net.apply_rule, r=hopfield_net.r) cpl.plot(hopfield_net.W) cpl.plot2d_animate(np.reshape(cellular_automaton, (155, 7, 5)))
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 cellpylib as cpl # implements the rule 60 sequential automaton from the NKS Notes on # Chapter 9, section 10: "Sequential cellular automata" # http://www.wolframscience.com/nks/notes-9-10--sequential-cellular-automata/ cellular_automaton = cpl.init_simple(21) apply_rule = cpl.AsynchronousRule(apply_rule=lambda n, c, t: cpl.nks_rule(n, 60), update_order=range(1, 20)) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=19*20, apply_rule=apply_rule) # get every 19th row, including the first, as a cycle is completed every 19 rows cpl.plot(cellular_automaton[::19])