Tuesday, November 28, 2006

Genetic Algorithm and Art



Biography

Michael Gold is President of Microgold Software Inc., makers of the WithClass UML Tool. His company is a Microsoft VBA Partner and Borland Partner. He has a BSEE and MEng EE from Cornell University and has consulted for Chase Manhattan Bank, Merrill Lynch. Currently, he is a senior consultant at JP Morgan Bank. He has been involved in several .NET book projects, and is currently working on a book for using .NET with embedded systems

What is Genetic Algorithm?

As defined from Wikipedia.org, genetic algorithm is “is a search technique used in computing to find true or approximate solutions to optimization and search problems, and is often abbreviated as GA. Genetic algorithms are categorized as global search heuristics. Genetic algorithms are a particular class of evolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover (also called recombination).”


A number of people in the art world are experimenting with what is known as evolutionary art and even sold a few of their works. Basically, genetic Art is a subset of evolutionary art and uses genetic algorithms to generate the art.

Computing Process

Michael has created this art to show and provide the users a head start on preparing their own art one day with genetic algorithm. He create his art using C# and .NET. He has experimented a bit with genetic algorithms and creating fitness functions that produce art on a Windows Form.

The basic idea behind creating art from mathematical equations, is to produce a color from a formula operating on an x,y coordinate. (In three dimensions you would produce a color from an (x,y,z) coordinate.). In the given art, Michael has
geared up formulas to produce 4 possible colors from results ranging from 0-3.

The first dataset for comparing our art was derived from the simple formula is (a + b) mod 4. This formula forces all the simulated results to values between 0 and 3 The genetic algorithm will produce genes that try to converge on a formula that approximates the formula. It is better that the algorithm not converge to the correct answer (a+b) mod 4, because the approximation to the formula is what produces the original art.

Here are some examples of the above code in resulting artworks produced after 1000 generations of converging on the formula.

Simply, multiplying the above formula [(a * b) mod 4], you can see the following result. This is a bit more sophisticated than the first example.

And finally, Micheal has also powered b to a [(a^b) mod 4] and this will give the most complicated art of them all. Changing the color scheme a bit, by producing a different set of colors from the results of (0-4) and running the algorithm on a 1000 generations against the ab mod 5 data, we get the art textures


public void Plot(Form1 TheForm, Graphics g)
{
// Fill the whole form with a light gray color to erase old drawing
g.FillRectangle(Brushes.LightGray, TheForm.ClientRectangle);

// go through each x,y coordinate and plug it into the equation
// produced by the genome to derive an integer representing a
// color
for (int i = 0; i < color="blue">
for (int j = 0; j < color="blue">
double calc1 = PerformCalculation(i, j); // do calculation
if (calc1 > 4)
g.DrawLine(Pens.LightBlue, i, j, i+1, j);

else if (calc1 > 3)
g.DrawLine(Pens.Purple, i, j, i, j+1);

else if (calc1 > 2)
g.DrawLine(Pens.Red, i, j, i+1, j);

else if (calc1 > 1)
g.DrawLine(Pens.Yellow, i, j, i, j+1);

else
g.DrawLine(Pens.Navy, i, j, i+1, j);
}
}

The data points for the fitness function ab mod 5 are shown in listing 2a. The first 2 numbers in each triple set are a and b respectively. The last number is the resulting value of the equation ab mod 5.


Comparison

Comparing the above pieces of artwork done by Micheal Gold, I would rate the most recent one the highest because I believe it has more varity and color combinations than the rest. The more complicated the equation or formula maybe, the better output it will have, even though it may take much longer to process. The final picture also has the best effect than the others as it creates a flow of colors and lines.

References: Micheal Site, Wikipedia

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home