The Computational Beauty of Nature

Programs

Every example in the book is a small C program with a command-line interface and a plotting driver. The code is on GitHub; the programs that draw something also run in the browser here.

assoc — retrieve associative memories · run it live

bifur1d — plot bifurcations from a one-dimensional map · run it live

boids — simulate a flock of android birds from Brooklyn · run it live

ca — simulate arbitrary one-dimensional cellular automata · run it live

diffuse — simulate diffusion limited aggregation · run it live

eipd — simulate the ecological iterated Prisoner's Dilemma

gabump — find a bump's peak with a genetic algorithm

gaipd — breed IPD strategies with a genetic algorithm

gastring — breed strings with a genetic algorithm

gasurf — find a surfaces peak with a genetic algorithm

gatask — solve a task assignment problem via a genetic algorithm

gen1d — generate time series from a one-dimensional map

gsw — simulate a three species individual-based ecosystem · run it live

henbif — plot a bifurcation diagram for the Henon system

hencon — control the Henon system with the OGY control law

henon — plot the phase space of the Henon system

henwarp — warps a square into the phase space of the Henon system · run it live

hopfield — solve a task assignment problem via a Hopfield network

hp — simulate the hodgepodge machine · run it live

ifs — generate fractals with an IFS · run it live

julia — make a plot a Julia set · run it live

life — play Conway's Game of Life · run it live

lorenz — plot the phase space of the Lorenz system · run it live

lotka — integrate the Lotka-Volterra system

lsys — builds an L-system fractal from multiple rules · run it live

mandel — make a plot the Mandelbrot set · run it live

mg — plot the phase space of the Mackey-Glass system

mlp — train a multilayer perceptron with backprop · run it live

mrcm — generate fractals with the MRCM algorithm

phase1d — plot phase-space of a one-dimensional map

predprey — plot the phase space of a predator-prey system

rossler — plot the phase space of the Rossler system

sipd — simulate the spatial iterated Prisoner's Dilemma · run it live

stutter — a simple lisp interpreter

termites — simulate a population of termites · run it live

vants — simulate a population of generalized virtual ants · run it live

zcs — run a zeroth level classifier system on a terrain

zcscup — run a zeroth level classifier system on the cups problem

Overview

The programs below are listed in the order in which they appear in the text.

Computation

stutter

interprets simple lisp and only understands car, cdr, cons, if, set, equal, quote, and lambda, but is still Turing-complete. Uses stop-and-copy garbage collection and has an adjustable heap size. Examples that implement integer and floating-point arithmetic are provided. There is even an example stutter function to compute the square root of a floating-point argument with nothing but the primitives listed above.

Fractals

diffuse

Generates diffusion limited aggregate growth that looks like coral.

lsys

Builds L-system fractals. Accepts multiple rules so that complicated fractals (such as a Penrose tiling) can be expressed. Great for generating plantlike fractals.

mrcm

Uses the Multiple Reduction Copy Machine algorithm to generate affine fractals. Accepts an arbitrary number of transformations. Good for making snowflakes and mosaic patterns.

ifs

Similar to mrcm but uses Iterated Functional Systems for finer granularity.

mandel

Plots the famous Mandelbrot set. There are options for the displayed coordinates, zoom level, coloring schemes, etc.

julia

Generates Julia sets, which are related to the Mandelbrot set. Has options similar to mandel.

Chaos

gen1d

Generates a time series from a one-dimensional map. Nothing fancy; it just shows how chaos can be seen in simple systems.

bifur1d

Plots a bifurcation diagram for a one-dimensional map to illustrate how a change in a single parameter can move a system from fixed-point behavior, to periodic, and finally to chaos. Different regions can be zoomed in on.

phase1d

Plots the phase space and trajectories of a one-dimensional map. Showing trajectories in the phase space more clearly illustrates why fixed-points and limit cycles occur. This can also be used to show the exponential divergence of nearby trajectories.

henon

Plots the phase space of the Hénon map, a two-dimensional system with a fractal shape. Different regions can be zoomed in on.

henbif

Plots a bifurcation diagram for the Hénon system. This is similar to bifur1d but shows that bifurcations apply to multidimensional systems as well.

henwarp

Takes a square of a specified area and “warps” it a fixed number of times by the Hénon system. This illustrates the stretching and folding motion of chaotic systems as well as shows how points within an attractor's basin of attraction are eventually forced into a strange attractor.

lorenz

Plots the phase space of the Lorenz system, a three-dimensional system described by differential equations with a fractal shape. Both plain phase-space plots and delayed state-space plots are possible.

rossler

Similar to lorenz, but uses the Rossler system.

mg

Plots a two-dimensional embedding of the phase space of the Mackey-Glass system, a delay-differential system, with arbitrary parameters.

gsw

Simulates an individual-based three-species predator-prey ecosystem according to the specified parameters. The three species consist of plants, herbivores, and carnivores (grass, sheep, and wolves; hence the name, gsw). Updates are done synchronously, and each species has several parameters which can control their life cycles, from the ability to give birth, to the likelihood of starvation. Population statistics of the three species can be calculated over a subset of the entire grid.

predprey

Plots the phase space of a three-species predator-prey system (described by differential equations) which may be fractal in shape. Both plain phase-space plots and delayed state-space plots are possible.

lotka

Simulates the two-species Lotka-Volterra predator-prey system with a second-order Euler's method. This program serves as a simple introduction to differential equations.

hencon

Controls the Hénon system with the OGY control law for arbitrary choices of the system parameters. The control law is analytically calculated based on the system parameters. The user can select times in which control is turned on and off so that time-to-control and transients can be observed. Gaussian noise can be injected into the system.

Complex Systems

ca

Simulates arbitrary one-dimensional cellular automata with an arbitrary choice of simulation parameters. Random rules can be generated and used with a desired lambda value.

life

Simulates Conway's Game of Life with an arbitrary set of initial conditions. Input files need to be in the PBM file format.

hp

Simulates and plots the time evolution of the hodgepodge machine according to specified parameters. With a proper choice of parameters, this system resembles the Belousov-Zhabotinsky reaction which forms self-perpetuating spirals in a lattice.

termites

Simulates a population of termites which do a random walk while possibly carrying a wood chip. Under normal circumstances, the termites will self-organize and move the wood chips into piles without a global leader. The termites' behavior is dictated by the following set of rules: If a termite is not carrying anything and it bumps into a chip, then it picks it up, reverses direction, and continues with the random walk. If it is carrying a chip and bumps into another, it drops the chip, turns around, and starts walking again. Otherwise, it just does a random walk whether it is carrying a chip or not.

vants

Simulates and plots a population of generalized virtual ants (vants). The behavior of the vants is determined by a bit string with length equal to the number of states that each cell in the vants' grid world can take. If a vant walks on a cell in state s, then the vant turns right if the s'th bit of the rule string is 1 and left if it is 0. As it leaves the cell the vant changes the state of the old cell to (s + 1) modulo the number of states.

boids

Simulates a flock of boids according to rules that determine their individual behaviors as well as the “physics” of their universe. A boid greedily attempts to apply four rules with respect to its neighbors: It wants to fly in the same direction, be in the center of the local cluster of boids, avoid collisions with boids too close, and maintain a clear view ahead by skirting around others that block its view. Changing these rules can make the boids behave like birds, gnats, bees, fish, or magnetic particles.

sipd

Simulates and plots the spatial iterated Prisoner's Dilemma over time according to the specified parameters. Each cell in a grid plays a specific strategy against its eight neighbors for several rounds. At the end of the last round, each cell copies the strategy of its most successful neighbor, which is then used for the next time step. Possible strategies include “Always-Cooperate,” “Always-Defect”, “Random,” “Pavlov,” and “Tit-for-Tat.”

eipd

Simulates the ecological iterated Prisoner's Dilemma over time according to the specified parameters. At every time step the population of each strategy is calculated as a function of the expected scores earned against all strategies weighted by the populations of the opponents. Possible strategies include “Always-Cooperate,” “Always-Defect,” “Random,” “Pavlov,” and “Tit-for-Tat.”

Adaptation

assoc

Attempts to reconstruct a corrupted image with a McCulloch-Pitts feedback neural network that acts as an associative memory. The weights of the network are determined via Hebb's rule after reading in multiple patterns. Weights can be pruned either by size, by locality, or randomly.

hopfield

Solves a task assignment problem via a Hopfield neural network while plotting the activations of the neurons over time. The program uses the k-out-of-n rule for setting the external inputs and synapse strength of the neurons.

gastring

Uses a genetic algorithm to breed strings that match a user-specified target string. This program illustrates how GAs can perform a type of stochastic search in a space of discrete objects. Reproduction of strings entails crossover and mutation with strings being selected based on fitness.

gabump

Uses a genetic algorithm to find the maximum of a single-humped function that is centered at a user-specified location. This program serves as an example of how GAs can be used to optimize functions which take a floating-point argument.

gasurf

Uses a genetic algorithm to find the maximum of a multi-humped function. This program serves as an example of how GAs can be used to optimize functions which take multiple floating-point arguments.

gatask

Uses a genetic algorithm to solve a task assignment problem with user-specified costs. This program illustrates how GAs can perform combinatorial optimization. Reproduction of strings entails special crossover and mutation operations which preserve constraints on the form of feasible solutions.

gaipd

Uses a genetic algorithm to evolve iterated Prisoner's Dilemma (IPD) strategies according to user-specified constraints. This program illustrates how GAs can demonstrate coevolution since IPD strategies can only be successful within the context of their likely opponents.

zcs

Adapts a zeroth level classifier system (ZCS) with the implicit bucket brigade algorithm and a genetic algorithm so that the ZCS can traverse a two-dimensional terrain, avoid obstacles, and find food. At the beginning of each step the ZCS is placed at a random location of its world. It interacts with its environment until it finds food, which yields a reward. The simulation then restarts with the ZCS placed at a new random location. The progress of the ZCS is continuously plotted, while the statistics on the time to find food are calculated and displayed. At the end of the simulation the classifiers that make up the final ZCS are saved to a log file.

zcscup

Trains a zeroth level classifier system (ZCS) to solve the cups problem with the implicit bucket brigade algorithm and a genetic algorithm. Solving this problem requires the ZCS to learn to remember important features from previous states, which makes this problem very challenging. The ZCS always starts in the same initial position. It interacts with its environment until it finds both cups, which (only at that point) yields a reward. The simulation then restarts with the ZCS placed at the original location. The progress of the ZCS is continuously plotted, while the statistics on the time to find both cups are calculated and displayed. At the end of the simulation the classifiers that make up the final ZCS are saved to a log file.

mlp

Trains a multilayer perceptron with a single hidden layer of neurons on a set of data contained in a file using the backpropagation learning algorithm with momentum. Output units can be linear or sigmoidal, allowing you to model both discrete and continuous output target values.

Downloads (historical)

Newsflash (17 Apr 00): If you have had any trouble running the Mac or Windows ports of the code, read the FAQ list.

Newsflash (18 Dec 98): the Mac port is here! Special thanks to Mike Miller, hacker extraordinare and the author of the CBofN Java applets, for making this possible.

Newsflash (26 Oct 98): the Windows port is here! Also, the X Windows and Windows graphic drivers now have a nice color map. See the “miscellany / errata” section for how the new graphic capabilities have changed the command-line options.

The source code is currently available many flavors:

NB: the links above use HTTP protocol (not FTP), just in case this web server doesn't support FTP. This means that you will need to SHIFT-click the links to save them to a file.

While the code is known to work under Solaris, I currently don't have access to a Solaris machine, so a binary distribution for it will have to wait.

Java ports (historical)

Mike Miller's Java applets from 1998 no longer run in any browser; the JavaScript versions above replace them.

Mike Miller graciously coded up a set of Java classes to simplify porting the source code from the book. Using this framework, Mike has ported about half of the programs from the original C source into Java. His framework is in keeping with the philosophy behind the design of the original C source in that all of the details for the GUI are more or less extracted away from the main source. This means that the heart of the code, i.e., the interesting stuff, is pretty easy to understand from looking at the class definitions.

Of course, the java source code is freely available, with and without the class files precompiled. If you don't have a Java compiler or you are not sure, get the package with the class files included.

Since the Java applets closely resemble the C programs, you may wish to consult the online documentation of the original programs.

While using the applets, note that you can often interact with the main viewer. For example, some applets will allow you to zoom in and/or rotate an image, depending on what is appropriate; so try your mouse on the viewer and see what happens.

Depending on the size of your screen and the amount of processing power that you have, you should choose one links below to run the applets.

NB: Netscape under Linux and Solaris has a strange update policy for the screen that I can't quite figure out. If the graphics take a long time to update, try moving your mouse around or clicking the menu. Anyone know what's the deal here?

The original page embedded the CBNapplet Java applet (../legacy/classes/); the javasmall/javamed/javalarge pages were applet-only and are not converted.