# Guess and Test (GAT)

Genetic Algorithms

So now that we have a bunch of notes that have no relationship to each other, what do we do? Test them. What we need to do is look at a note and the notes surrounding it and try to make them obey rules. What rules? Music theory rules. Things like parallel thirds and sixths sound good while parallel fifths and octaves sound bad. How do we do that well? Enter genetic algorithms.

A genetic algorithm is essentially a process by which a program checks the input, scores how well it conforms to a set of rules, then tries for better results by cutting and pasting the best sets of input in a fasion similar to how genes are spliced when an egg is fertalized. Please see the link above, as a more complete discription is not waranted here, and it really is very interesting.

The genetic algorithm that You can download the source for below is searching for a melody that sounds good when played forward and backward at the same time. That is to say, the program answers this question: If You took the output of this program and flipped it so the first note was last and the last note was first, then played it at the same time as the original melody, would it sound good, musically speaking?

Here is the format for the output of the program:

Numbers in the range of 0-28. For the sake of simplicity, everything is done in the key of C major. 0 is interpreted as the C below the bass staff (low C). 28 is interpreted as the C above the treble staff (high C).

I will refer to the original melody as the "melody" and the flipped melody as the "harmony." The applet searches for and either rewards or penalizes:

• A cadence every 16 notes
• Authentic cadence (V - I)
• Plagal cadence (IV - I)
• Deceptive cadence (V - anything but I)
• Parallel thirds and sixths
• Parallel fifths and octaves
• If the harmony and melody are in a triad together at every note
• If the melody begins on the tonic
• If the melody ends on the tonic
• If the melody ends on the dominant
• If the melody ends on neither the tonic nor the dominant
• Too much repetition of a single note
• Non-chordal tones
• Passing tones
• Neighboring tones
• Suspensions
• Escape tones
• Pedal tones
• Step-wise movement

The above list highlights one of the reasons why a genetic algorithm is better than the most simplistic method of GAT: "If it doesn't work, throw it out and try another one." If we took that approach, almost everything would be thrown out. There are so many rules to break. There are so many contradictions. A genetic algorithm doesn't throw a note away when it doesn't work. It scores it. Melodies with low scores will eventually die away. Melodies with higher scores will rise to the top, even though they may break some rules in some places. The overall effect is a compromise.

There are more primative versions of GAT (like the one mentioned above), but they are very simplistic. We had the program already written for something else, so we decided to use it again. There are also far better ways to write this program - make it check for more things, make it deal with more notes, etc. For this demonstration, nothing more is necessary than what we have. We also do not have the time to write another version.

If You would like to see and/or play with the program...

Futher Reference

Biethahn, Jörg, and Volker Nissen, eds. Evolutionary Algorithms in Management Applications. Berlin: Springer, 1995.
This is actually a book on applications of genetic algoithms (and other techniques) to management. However, it has a very good introduction that describes evolutionary algorithms in general. The whole book is about applications of the algorithms, and that should be very informative.