A Novel Approach toAutomatic Music Composing:
Using Genetic Algorithm
Paper by: Zad, D. D. and B. N. Araabi,C. Lucas. 2007.
Presented by: Adam Jenkins
First off…
♣What’s the deal with Genetic Algorithms?
Genetic Algorithm (GA):♣ GA is an evolutionary
algorithm whichcreates a populationof possible solutions(a.k.a individuals)based on a set ofparameters (a.k.achromosomes).
♣ It selects the best ormost “fit” solutionsand breeds themtogether.
♣ Random mutation canalso occur.
♣ This process ofbreeding (a.k.acrossover) andmutation continuesuntil a satisfactorysolution is found.
GA Terminology
♣Genes
♣Chromosomes
♣ Individuals
♣Crossover
♣Mutation
♣ Fitness
♣ Gene:
♣ A region of DNA that controls a hereditary characteristic.♣ It usually corresponds to a sequence used in the
production of a specific protein or RNA.
♣ Chromosome:
♣ Paired threadlike "packages" oflong segments of DNAcontained within the nucleus ofeach cell.
♣ E.g. Humans have 46 (23 pairs)chromosomes in each cell. 23from each parent. The 23rd pairdetermines the sex.Female = 2 X-ChromosomesMale = X and a Y-Chromosome
Genes / Chromosomes / IndividualsPart 1 - In Biology
Genes / Chromosomes / IndividualsPart 2 - In Biology
♣ Individual
Genes / Chromosomes / IndividualsPart 3 - In The Paper
♣Gene:♣A midi note
♣ Individual:♣A song
♣ (a series ofchromosomes)
♣Chromosome:♣A string of midi notes
♣ (a string of genes)
Crossover / MutationPart 1 - In Biology
♣Crossover function♣Breeding♣ The chromosomes of 2
individuals merge to formnew chromosomes.
+ =
LeopardPanthera pardus
Domestic catFelis catus
????
Crossover / MutationPart 2 - In Genetic Algorithms
♣ Crossover function♣ One-point crossover ♣ Two-point crossover
♣ Uniform crossover (used in paper)♣ Each gene of the offspring is selected with a probability
(called the mixing ratio) from the genes of its parents.♣ E.g.
♣ Parent 1 = 11110000♣ Parent 2 = 00001111♣ Mixing ratio = 0.5 (50%)♣ Offspring = 00111010
Crossover / MutationPart 3 - In Biology
♣Mutation function♣A random change in a gene within the
chromosome of the newly bred individual.Example: Eye colour• “Originally, we all had brown eyes”, saidProfessor Eiberg from the Department of Cellularand Molecular Medicine. “But a genetic mutationaffecting the OCA2 gene in our chromosomesresulted in the creation of a ‘switch’, which literally‘turned off’ the ability to produce brown eyes”. *•The OCA2 gene codes for the so-called Pprotein, which is involved in the production ofmelanin, the pigment that gives colour to our hair,eyes and skin. *
• The ‘switch’ reduces the production of melanin inthe iris, effectively diluting brown eyes to blue. *
* http://www.sciencedaily.com/releases/2008/01/080130170343.htm
Crossover / MutationPart 4 - In The Paper
♣ Crossover function♣ Occurs on songs. (I.e. 2 songs with each other).♣ Performs a uniform crossover pattern.♣ Constraint:
♣ Prevent segmentations in the middle of a melodic sequence.♣ Melodic sequence: a string of ascending or descending notes.
♣ While a string of notes is ascending or descending, thecrossover function cannot break the chromosome.
♣ If the crossover function attempts to break a melodic sequence,the break is rejected.♣ And the crossover will be performed again.
Crossover / MutationPart 5 - In The Paper
♣ Mutation function♣ Mutation occurs with genes (midi notes)♣ The mutation is based on harmonic and
melodic rules1. Determine key (one of 12 major or 12 minor scales)
♣ E.g. ‘C’ major scale
2. Each note can be mutatedto a different pitch
3. Each note can be mutatedto a different octave
♣ How is this done?
Crossover / MutationPart 6 - In The Paper
♣ Mutation function♣ Determining key:
♣ Used Krumhansl & Schmuckler (1990) key-findingalgorithm.
♣ A pitch-class distribution is created with each pitchweighted according to their duration.
♣ From this, one of 24 scales are chosen(24 scales = the 12 major and 12 minor scales)
Self-organizing map (SOM) of thetonality in Bach’s C-major Prelude,Wohltemperierte Klavier II
Crossover / MutationPart 7 - In The Paper
♣ Mutation function♣ Mutate the pitch of the midi note (the gene)♣ Based on harmonic and melodic rules
1. Use a random number generated from a normal distribution♣ RANDNUM = random value between 0 to 1
2. If RANDNUM < 0.25♣ No pitch change
3. If 0.25 < RANDNUM < 0.75♣ If key is a major scale:
♣ Change pitch to 4th note of relative minor♣ A.k.a.: Change pitch to 2nd (9th) of the main chord
♣ If key is a minor scale:♣ Change pitch to 4th (11th) of main chord
4. If RANDNUM > 0.75♣ Change pitch to 7th of the main chord.♣ E.g. If scale = C major
‘E’ pitch shifted to ‘D’‘C’ pitch shifted to ‘B’
Crossover / MutationPart 8 - In The Paper
♣ Mutation function♣ Mutate the octave of the midi note (the gene)♣ Goal:
♣ Prevent big jumps and discontinuity in melodywithout totally restricting jumps.
♣ Method:1. Use a random number generated from a normal distribution
♣ RANDNUM = random value between 0 to 1
2. If RANDNUM < 0.1♣ Note is transposed random octaves BELOW original octave.
3. If 0.1 < RANDNUM < 0.25♣ Note is transposed 1 octave BELOW original octave.
4. If 0.25 < RANDNUM < 0.75♣ No octave change
5. If 0.75 < RANDNUM < 0.90♣ Note is transposed 1 octave ABOVE original octave.
6. If RANDNUM > 0.90♣ Note is transposed random octaves ABOVE original octave.
FitnessPart 1 - In Biology
♣ Fitness function♣ Defines which individuals and thus which chromosomes will
continue in the next generation.♣ It defines how ‘attractive’ or ‘unattractive’ the individual is to
reproduce:♣ E.g.: Hot chick (fit): Ugly cow (not fit):
FitnessPart 2 - In The Paper
♣ Fitness function♣ Author claims it “plays a great role for accepting the
best song…” “…and to diminish the dissonant notesfrom the resulting songs.”
♣ Major factor of fitness function:♣ The song’s entropy (randomness) of distribution of notes
♣ If entropy is over-maximizied (Song has too much entropy):♣ The song is too random♣ The song is unpredictable♣ The listener cannot predict upcoming (repeated) melodies♣ The listener cannot follow along♣ The song is unpleasant and disturbing
♣ If entropy is under-maximized (Song doesn’t have enoughentropy):♣ The song is too predictable♣ The song is mechanical, elementary and boring
♣ Therefore, the program tries to keep the entropy close to theinitial population’s entropy.
FitnessPart 3 - In The Paper
♣ Fitness function1. Calculate of fitness function by:
♣ Minimizing the distance of the generated songs’ entropyfrom the Mean-Square of the initial population’s entropies.♣ Mean-Square Distance:
♣ MSD =1/N Σ[n = 1 to N] (ESn - EGS)2
♣ N = Number of songs in initial population
♣ EGS = Entropy of the generated song
♣ ESn = Entropy of song ‘n’ from the initial population
♣ Therefore, the lower the fitness value the more the song is‘fit’ or ‘attractive’ for future generations.
2. Effect of dissonant notes:♣ Dissonant notes are to be avoided in a song.♣ If a generated song has dissonant notes:
♣ Its fitness value is multiplied by a fixed number (e.g. 1.5)♣ This ensures it would have a higher fitness value than that of a
song without dissonant notes.
ResultsPart 1 - Bob Dylan
♣ Initial population from Bob Dylan (dylantest.mid)♣ Initial population containing 20 Bob Dylan MIDI songs♣ 100 generations♣ Fitness values of generations with dissonance notes
are multiplied by 1.5
Opinions of 50random students
ResultsPart 2 - J.S. Bach
♣ Initial population from J.S. Bach (Preludetest.mid)♣ Initial population containing 20 J.S. Bach’s MIDI songs♣ 500 generations♣ Fitness values of generations with dissonance notes
are multiplied by 1.5
Opinions of 50random students
Questions?