
       GPX/Abstractica by Walter Alden Tackett and Aviram Carmi
      with X routines pirated from Xavier "X-man" Bouyssounouse

WHAT THE HECK IS THIS THING?

In a Nutshell: 
Abstractica is a program which performs a guided stochatic
search of image space according to your aesthetic tastes, resulting
in abstract pictures with a wealth of complexity and variety.
   
From The Legal Point of View: 
DISCLAIMER: This code is provided free and is completely unsupported.
Neither Walter Tackett, Aviram Carmi, Xavier Bouyssounouse, USC,
Hughes Aircraft, CSUN, or the Santa Fe Institute make any warranty nor
take any responsibility for expenses you incur by using or misusing
it.  Have a nice day.

Administrata: 
This is executable code, and requires a Sun SparcStation with 8-bit
color in order to run.  Certain routines for user interface, image
manipulation, and memory management are not ours to give away freely,
hence source code cannot be distributed.  As a virus control measure,
the only legitimate source for obtaining this code is via anonymous
ftp to sfi.santafe.edu in the directory pub/Users/tackett.  There are
two files, abs.tar.Z and abs.static.tar.Z: the latter contains an
executable compiled with the -Bstatic option and will run even if you
have your sharable libraries installed funny.  It is about 5x bigger
than the executable in abs.tar.Z.  Try getting and running abs.tar.Z
first.  You will need to use the binary option when you ftp the
file.  You must uncompress the file:
uncompress abs.tar.Z
and then untar it: 
tar -xvf abs.tar
You will find the executable and several LISP files (*.lsp)
which produce interesting and/or tutorial imagery, as well as a sample
input parameter file sample.in.

MAIL

To: gpc-wat@ipld01.hac.com or gpc-avc@ipld01.hac.com
We cannot answer a lot of detailed questions personally, but we may
set up an autoreply FAQ.  PLEASE DO send us any really cool images you
may generate (in LISP form only, please!).  

QUICK-START

When you run the program, the first thing you see is the main panel.
Click on the "Set Parameters" button.  Enter 1 for "Number of
Populations" and HIT RETURN (a notice will appear- choose "Set"). Wait
about 10 seconds while the system initializes (a new field, "Set
Parameters for Population," will appear when the system is done
initializing).  Now enter 1 for "Number of Generations" and HIT RETURN
(the system only cares that the number is not <= 0).  Now click the
"Fitness" button: the Image panel will appear.  Press "Start."  It
will take between 1 and 5 minutes to generate the images depending on
your system and the enabled function set (a *lot* of computation is
involved- Sims' work was done on a CM-2!  Just go get a cup of coffee
or, god forbid, do the work you're being paid to do).  Click the mouse
on the images you like to increase their fitness- this will increase
the likelihood that images similar to them will occur in the next
generation.  To see the equation corresponding to a picture, first
click on the "Save Genotype" button, and then click on the picture.
The equation will be printed in LISP form on stdout.  To see an image
at higher resolution, click on the "Enlarge" button, and then click on
the image.  Again, this will take a bit of time.  NOTE: Because of
sampling phenomena, images can look strikingly different at higher
resolution, usually for the better.  When you are satified, click on
the "Next Generation" button (and wait).

THE DETAILS

GPX is our X version of GPC, which stands for "Genetic Programming in
C."  Genetic Programming (GP) uses the Genetic Algorithm (Fitness
Proportionate Selection, Sexual Recombination, and Random Mutation) to
manipulate the parse trees of LISP programs.  GPX/GPC is itself a C
program which manipuates "raw" parse-tree structures in order to
achieve rapid execution.  For convenience, these trees may be written
and read as LISP code.

The basic idea behind GP is that we construct a population of programs
at random, and then measure their "fitness" for some given task.
Those individuals which are particularly fit will have a higher
probability of being randomly selected as parents of offspring in the
next generation.  Offspring are formed by swapping subtrees
(subexpressions) between a pair of parents.  Rules of syntax are
obeyed during all tree operations so that all trees are syntactically
correct.  Trees are constructed from a "function set" (internal nodes
of the tree) and a "terminal set" (leaves).  The function and terminal
sets are specific to the problem being addressed.  For more
information about Genetic Programming see the book "Genetic
Programming" by John Koza, MIT Press, 1993.  There is also an
electronic mailing list, genetic-programming-request@cs.stanford.edu.

Abstractica is an X application written on top of GPX.  It is copied after
the work of Karl Sims at Thinking Machines (see: K. Sims, "Artificial Evolution
for Computer Graphics," Computer Graphics (ACM), v25 #4, July 1991). Here,
we evolve equations (genotypes) which are expressed as images (phenotypes),
one equation per image.  Fitness is based upon aesthetic taste: we
increase the fitness of the images we like by clicking on them with the
mouse.  I could go on, but words cannot do justice to some of the pictures
you can generate.

The basics: each image is indexed from (-1.0,-1.0) (upper left) to (1.0,1.0)
(lower right).  The equations being generated are single-valued functions
of the image coordinates: they consist of terminals X, Y, and RANDOM-CONST.
When RANDOM-CONST is selected as a terminal, a random floating point number
is generated and inserted into the tree at that point.  The function set
consists of various math operations (e.g. +,*,sine) and some special functions
including noise, wavelets, and gradient operators.  Here is a typical
(although somewhat small for the norm) equation:

(WAVEVEN
  (SIN
    (+
      (CNOISE
        (COS
          X))
      (SIN
        (*
          (CNOISE
            0.452393)
          Y))))
  0.413472
  Y
  X)

(this one looks a lot like a watercolor painting of sunset over a hill).


ADVANCED DOODLING

Set Parameters Panel:
SET PARAMETERS FOR POPULATION 1.  When you place the cursor in this field and 
HIT RETRUN, the Population Parameters panel appears.  IMPORTANT NOTE: always
hit the "Done" button when you have changed values to ensure that the 
system is properly notified of the changes.

save_parameters_to_file: save all the current settings in this menu to the
	named file.  Enter the file name and HIT RETURN.  

load_parameters_from_file: load all the parameters from the named file.
	Enter the file name and HIT RETURN.  The new values will magically
	appear.

load_population_from_file: YOU CAN ONLY SET THIS BEFORE YOU HIT THE "Start"
	BUTTON.  Load the n stored LISP programs from the named file into
	the first n members of the population.  File will be loaded when
	you hit the Start button.  NOTE: you can save genotypes to files
	for later loading- see "IMAGE PARAMETERS PANEL" below.

seed: random seed for generating population, noise, etc.

population_size: YOU CAN ONLY SET THIS BEFORE YOU HIT THE "Start"
	BUTTON.  The number of members of the population (and hence the
	number of pictures).  This defaults to 16, but you will get better
	diversity and less inbreeding if you set it higher.

Other parameters: see Koza for rationale/details.  You can change these on
the fly to see their effects:

*_depth: max depths of tree segments generated initially, max depth of
	subtrees generated by mutation, and max depth allowed after crossover.

Grow Method: Selects whether trees are full or not, or if members of population
	are mixed.

Selection Method: Determines how parents are chosen.

Tournament K: Size of tournament if tournament selection is used.

parsimony factor: Size penalty which decreases fitness of large trees.
	0.01 is a very big value for this parameter.  Should be non-negative.

*_fraction: governs the probability of method used to generate one pair of 
	offspring.  One minus the sum of these three fractions is the
	probability that mutation occurs.  NOTE: although we keep mutation
	real low (<.001) in normal GP, for this application and relatively
	small population size I have found the 0.1-0.3 is not an unreasonable
	range for mutation.


IMAGE PARAMETERS PANEL

Click on the "Image Params" button on the Image Panel to access these
items.  For the numeric and text items, be sure to click the "Done"
button to ensure that the system is properly updated.

size: The size of the images in pixels.  You can change this on the fly, but
	strange things may happen. In general, you should do this before you
	hit the	Start button.

mag: magnification of images.  images on the screen are blown up by this
	factor for display purposes.  Again, you can change this on the fly
	if you really want to.

zoom: zoom factor for enlarging images.  You can change this any time with
	no problem.

Color Table: YOU MUST CHOOSE THIS BEFORE HITTING THE "Start" BUTTON. All my
	sample files assume you are using COLOR2, which is the default.

Save Genotypes to: When you hit the "Save Genotypes" button, this is where
	they go.  If stdout (the default) is selected, they go only to stdout.
	Otherwise they are echoed to stdout and appended to the named file
	as well.

Function Enabling/Disabling
When trees are generated, either initially or via mutation, we can disable
some functions from being inserted.  Below we list the functions which are
available as well as applicable caveats. NOTE: YOU CAN TURN THESE OFF AND
ON AT ANY TIME, BUT UNLESS YOU HAVE A VERY HIGH MUTATION RATE THERE
WILL NOT BE MUCH EFFECT IF YOU DO NOT SET THEM BEFORE YOU HIT THE "Start"
BUTTON.  Disabling functions has no effect on the operation of expressions
which contain them: i.e., you can read in an expression from a file which 
uses CNOISE while CNOISE is disabled, and that expression will operate 
normally.

(+ A B)	Return the result of adding expression A to expression B.

(- A B)	Return the result of subtracting expression B from expression A.

(* A B)	Return the result of multiplying expression A by expression B.

(% A B)	"Protected Division."  If B evaluates to 0.0, return 0.0, else
	return the result of dividing expression A by expression B.

(SIN A) Sine of expression A.

(COS A) Cosine of expression A.

NOTE: +, -, *, %, SIN, & COS probably yield the most bang for the CPU
	cycle-buck.

(WAVODD A B C D) Odd (sine) Wavelet centered at X=A, Y=B, with
	gaussian-envelope-sigma C and orientation D (in radians).
	Moderately expensive to compute, but makes some interesting 
	images (the "sunset" shown above is given remarkable structural
	complexity from a relatively simple expression with wavelets).

(WAVEVEN A B C D) Even (cosine) Wavelet centered at X=A, Y=B, with
	envelope-sigma C and orientation D (in radians).
	Same comments apply as above.

(CNOISE A) Noise, spatially correlated ("colored").  The bandlimiting
	of the coloring filter is governed by A.  When A is 0 (or any
	even integer) noise is zero-mean, spatially uncorrelated, and
	uniformly distributed on {-1.0,1.0}.  As A increases, correlation
	increases (visually, it changes from speckled to cloudy), variance
	decreases and distribution becomes more Gaussian.  Correlation
	is maximum at A==1.0 (or any odd integer), and decreases from
	there to the next even A value.  Note that CNOISE is the only
	function which spatially varies given a constant argument.
	Because it is generated via a convolutional process, Noise is
	expensive to compute for large values of A.  It is disabled
	by default, but it can certainly have an interesting effect.
	Try loading the expression (CNOISE (% (+ X 1.0) 2.0)) to see
	how noise can vary.

(HGRAD A) A gradient, or pseudo-first-derivative, in the X direction.
	It is like convolving the image created by expression A with the
	mask:
	-1.0 0.0 1.0
	-2.0 0.0 2.0
	-1.0 0.0 1.0
	This would be a really good place to do symbolic math, but since I'm 
	not that smart, I implement this as a "Macro" which evaluates the
	expression A six times with six different X and Y values in order
	to generate the values weighted by the filter coefficients.
	Very computationally expensive: slows things down a lot.  Haven't
	seen a really interesting image that depended on it (yet).

(VGRAD A) A gradient, or pseudo-first-derivative, in the Y direction.
	It is like convolving the image created by expression A with the
	mask:
	-1.0 -2.0 -1.0
	 0.0  0.0  0.0
	 1.0  2.0  1.0
	Same comments apply as above.

(LAPLACE A) Laplacian filtering (i.e., 2D 2nd derivative, nondirectional).  
	It is like convolving the image created by expression A with the
	mask:
	  0.0 -1.0  0.0
	 -1.0  4.0 -1.0
	  0.0 -1.0  0.0
	Same comments apply as above.
	
(IFLTE A B C D) Conditional: IF (A < B) evaluate C and return the result,
	ELSE evaluate D and return the result.  This is also a macro:
	only one of C or D is actually evaluated.  IFLTE makes some really
	interesting images with little computational overhead.


Enjoy.

-wt
