Reversing Conway`s Game of Life by Multi

Reversing Conway’s Game of Life by
Multi-Layer Perceptron
Jonathan Goetz
University of Wisconsin-Madison
ECE/CS/ME 539 Project Paper
Not releasing code as public domain.
Introduction
Invented in 1970 by John Conway, “Conway’s Game of Life” was conceived as a simple game to simulate
some basic concepts of how populations grow and develop, played with a grid of ‘living’ and ‘dead’ cells
that function based on three simple rules based on the states of themselves and their horizontal,
vertical, and diagonal neighbors applied simultaneously to all cells [1]:
1. Any living cell with either one or less or 4 or more living neighbors dies (becomes a dead cell).
0 0 0
0 0 0
0 1 0 -> 0 0 0
0 0 0
0 0 0
2. Any living cell with two or three living neighbors survives (stays a living cell).
0 1 0
0 1 1
0 1 1 -> 0 0 1
1 1 0
1 1 1
3. Any dead cell with three living neighbors is born (becomes a living cell).
1 0 0
0 1 0
1 0 1 -> 0 1 0
0 0 0
0 0 0
While this in itself is not of particular use for any significant real world application, it is one of the
simplest variations of a set of problems called Cellular Automata [2] which do have practical applications
in fields like physics, biology, and mathematics among others. [3] One particularly important trait that
some of these cellular automata feature including Conway’s Game of Life is how they can map many
different input states to the same output state, resulting in a loss of information about the previous
states of the inputs.
1 0 1
0 1 0
0 0 0
V
0 0 0
0 1 0
0 0 0
1 0 1
0 0 0
0 1 0
V
0 0 0
0 1 0
0 0 0
1 0 0
0 1 0
0 0 1
V
0 0 0
0 1 0
0 0 0
1 0 1
0 0 0
1 0 0
V
0 0 0
0 1 0
0 0 0
Figure1: Four cell states that all result in the same output state shown below
This many to one mapping effect of such cellular automata makes it impossible to use direct
computations to determine the one particular predecessor used for such output states which makes
solving the question of ‘What was the previous state?’ impossible for this type of output state . Further
complicating matters are a type of state called ‘Gardens of Eden’ which are those states where there is
no possible input that results in their creation, which means that there are some occasions where there
cannot be a solution at all. [2] However, having an idea at what the previous states were most likely
would be extremely helpful for applications where determining the input to a system that can be
modeled with a cellular automata based solely on its output as it can be used to narrow the selection of
possible input permutations.
Reasoning
Using Conway’s Game of Life as an example of cellular automata to determine predecessors,
there are several aspects of the problem that would make a Multi-layered Perceptron (MLP) an ideal
approximator for the reverse application of the rules. The first of these aspects is the fact that for the
forward application of the game each output is a function of its own and its neighbors input values,
which is a principle that a MLP can use to determine approximated weights through training. Second,
due to the iterative application of these rules it is possible to break the problem down into multiple
steps using a properly structured MLP to allow its internal hidden states to generate an approximate for
each successive predecessor based on training data of the same number of back iterations. Third, the
input format for the reverse version of Conway’s Game of Life requires minimal preprocessing as it is
already split into discrete inputs, with the only necessary step is to remove those training samples with
completely dead inputs which are the most common descendent state and have lost all information
about their input state making them poor choices for training.
Data
Initially training, validation, and testing were to be performed with a dataset provided by Kaggle
Inc. as a part of their Conway’s Reverse Game of Life contest which featured 50,000 input samples for a
finite sized universe of 20x20 cells over 1 to 5 generations of the game, with the initial state having been
noise reduced by going through several previous generations of the game. However, this dataset
proved to be beyond the capability of the hardware to analyze leading to system failures. In order to
generate more reasonable sized data sets, a function was developed to create randomized input states
that would be prepared by running the state through several rounds of Conway’s Game of Life before
ensuring that at least some cells were still alive in order to get useful training data. Further a distinct set
of data was produced with the same approach to generate the final error values for comparison. In an
attempt to ensure that the inputs would work well with the MLP, tests were run separately with inputs
of [0, 1] and [-1, 1] to see if there was any effect.
Approach
The two approaches I am testing are:
1) Recursive application of a trained neural network for each iteration to step back in time, for a
5x5 result matrix back for a total of 3 iterations with rescaling between applications to see how
closely it matches with the input state, compared with a baseline approximator of .5 to see if the
approximator’s error is sufficiently small to not just result in noise.
2) Single application – Train a neural network to associate the final outputs with the input from 3
iterations prior to see if there is any improvement in the performance by eliminating the
multiple passes, at the cost of being unable to resolve the problem for any other number of
iterations. Using same variety of 5x5 input matrix as the recursive application.
Results
After training and validation on a divided data set of 500 samples expanded into 1500 step
samples, both runs of recursive application with different input scaling showed maximum improvements
over halfway approximation (assigning the midpoint of the range as a guess) of no more than 5.10% in
terms of the sum squared errors for each data point, with no optimal number of hidden nodes across all
layer counts or input ranges, though there were generally local minimums around 5-10 nodes, 25 nodes,
and 40 nodes per hidden layer. While both input ranges had similar maximum improvements, the [0, 1]
data in general performed better than the halfway approximation more consistently, with the [-1, 1]
values having more trials approximating worse than the halfway approximation. Using the second
approach of applying a single approximator to multiple stages at once proved to be completely
ineffective at an input set of 500 samples with the final trained approximator always predicting an
output around 1 regardless of the input with both input formats across multiple training and testing
sets. Further, the involved execution times for even an extremely limited input and small sample size
across a time displacement of only three generations was in excess of 5 minutes for both approaches.
Conclusions
While these trials did show some improvement over a halfway approximation of the input to
Conway’s game of life, the long execution times required for the entire process would likely outweigh
the benefits of performing this type of analysis. Increasing the size of the sample set used may help to
further increase the accuracy, but there is also the chance that there is simply too much information loss
in Conway’s Game of Life to make anything resembling an accurate prediction of an arbitrary input. The
numerous issues with handling large input sizes does suggest that for an actual practical implementation
of this approach to solving this problem the raw input is simply too large to use though it is in itself a
function of the desired result.
Appendix: Data and Graphs
Nodes/layer
50%
5
10
15
20
25
30
35
40
45
1 layer [0,1]
1250.0 1194.1 1200.9 1290.8 1254.7 1186.2 1243.1
1191.9 1199.6 1237.1
2 layer [0,1]
1250.0 1194.4 1234.3 1256.7 1372.2 1232.7 1251.3
1234.6 1216.0 1223.3
3 layer [0,1]
1250.0 1225.4 1243.9 1223.4 1241.3 1234.2 1226.7
1217.7 1260.8 1253.9
1 layer [-1,1]
6029.0 6073.8 5933.0 6159.1 6127.7 6247.5 6709.9
6167.3 5816.9 5896.3
2 layer [-1,1]
6044.9 6085.6 6192.6 6050.8 6010.4 5920.7 5991.4
6245.3 6090.6 6182.7
3 layer [-1,1]
6032.2 5775.0 5864.6 5969.5 6227.9 5924.3 6352.4
6006.8 5774.4 6348.1
d% 1 layer [0,1] 0.00% 4.47% 3.93%
-3.26% -0.38% 5.10%
0.55%
4.65%
4.03%
1.03%
d% 2 layer [0,1] 0.00% 4.45% 1.26%
-0.53% -9.78% 1.39%
-0.10%
1.23%
2.72%
2.13%
d% 3 layer [0,1] 0.00% 1.97% 0.49%
2.13%
0.69%
1.26%
1.86%
2.59%
-0.87% -0.32%
d% 1 layer [-1,1] 0.00% -0.74% 1.59%
-2.16% -1.64% -3.62% -11.29% -2.29% 3.52%
2.20%
d% 2 layer [-1,1] 0.00% -0.67% -2.44% -0.10% 0.57%
2.05%
0.89%
-3.32% -0.76% -2.28%
d% 3 layer [-1,1] 0.00% 4.26% 2.78%
1.04%
-3.25% 1.79%
-5.31%
0.42%
4.27%
-5.24%
Data collected for sum square error performance on a total of 500 trials of 5x5 input matrixes, d% values
are the percent improvements from the baseline values as calculated during runtime.
Plot of sum square error vs hidden layer size for 1 hidden layer and input range [0, 1]
50
1249.8
1260.9
1274.2
6042.0
6119.8
5880.5
0.02%
-0.87%
-1.94%
-0.22%
-1.24%
2.51%
Plot of sum square error vs hidden layer size for 2 hidden layer and input range [0, 1]
Plot of sum square error vs hidden layer size for 3 hidden layer and input range [0, 1]
Plot of sum square error vs hidden layer for 1 hidden layer and input range [-1, 1]
Plot of sum square error vs hidden layer for 2 hidden layer and input range [-1, 1]
Plot of sum square error vs hidden layer for 2 hidden layer and input range [-1, 1]
Plot for all single application approximators, layers had no effect and input changes just changed scale
from 1963 at [0, 1] to 3874 for [-1, 1]
Bibliography
[1] M. Gardner, "MATHEMATICAL GAMES: The fantastic combinations of John Conway's new solitaire
game "'life"," Scientific American, vol. 223, no. 4, pp. 120-123, 1970.
[2] E. W. Weisstein, ""Game of Life." From MathWorld--A Wolfram Web Resource," Wolfram Research,
Inc, [Online]. Available: http://mathworld.wolfram.com/GameofLife.html. [Accessed 10 Dec 2013].
[3] Kaggle Inc., "http://www.kaggle.com/c/conway-s-reverse-game-of-life," Kaggle Inc., 14 Oct 2013.
[Online]. Available: http://www.kaggle.com/c/conway-s-reverse-game-of-life. [Accessed 10 Dec
2013].