0% found this document useful (0 votes)
53 views

Alfonseca Et Al. - 2007 - A Simple Genetic Algorithm For Music Generation by Means of Algorithmic Informat

This document describes a genetic algorithm for generating music using algorithmic information theory. It uses the Normalized Compression Distance as a fitness function to generate computer-created music that resembles the style of a given human author. The paper tests different recombination operators in the genetic algorithm to improve music generation results, finding that the relative pitch envelope parameter works better than note length parameters. It aims to refine previous work on this topic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Alfonseca Et Al. - 2007 - A Simple Genetic Algorithm For Music Generation by Means of Algorithmic Informat

This document describes a genetic algorithm for generating music using algorithmic information theory. It uses the Normalized Compression Distance as a fitness function to generate computer-created music that resembles the style of a given human author. The paper tests different recombination operators in the genetic algorithm to improve music generation results, finding that the relative pitch envelope parameter works better than note length parameters. It aims to refine previous work on this topic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/221008730

A simple genetic algorithm for music generation by means of algorithmic


information theory

Conference Paper · September 2007


DOI: 10.1109/CEC.2007.4424858 · Source: DBLP

CITATIONS READS
11 701

3 authors:

Manuel Alfonseca Manuel Cebrian


Universidad Autónoma de Madrid Massachusetts Institute of Technology
181 PUBLICATIONS   944 CITATIONS    139 PUBLICATIONS   1,923 CITATIONS   

SEE PROFILE SEE PROFILE

Alfonso Ortega De la Puente


Universidad Autónoma de Madrid
70 PUBLICATIONS   463 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Complex systems and other things View project

Disaster Analytics: Disaster Preparedness and Management through Online Social Media View project

All content following this page was uploaded by Manuel Alfonseca on 16 May 2014.

The user has requested enhancement of the downloaded file.


A Simple Genetic Algorithm for Music Generation by means of
Algorithmic Information Theory
Manuel Alfonseca, Manuel Cebrián and Alfonso Ortega

Abstract— Recent large scale experiments have shown that been observed that this operator plays an important role in
the Normalized Information Distance, an algorithmic informa- this procedure.
tion measure, is among the best similarity metrics for melody This paper is organized thus: the second section pro-
classification. This paper proposes the use of this distance as
a fitness function which may be used by genetic algorithms to vides a short introduction to musical concepts needed to
automatically generate music in a given pre-defined style. The better understand the remainder, with a description of the
minimization of this distance of the generated music to a set of restrictions applied in our experiments and an enumeration
musical guides makes it possible to obtain computer-generated of different ways of representing music. The third section
music which recalls the style of a certain human author. The introduces the Normalized Compression Distance, which has
recombination operator plays an important role in this problem
and thus several variations are tested to fine tune the genetic been used to compute the distance from the results of the
algorithm for this application. The superiority of the relative genetic algorithm to the target musical pieces. The fourth
pitch envelope over other music parameters, such as the lengths section describes the genetic algorithm we have used for
of the notes, brought us to develop a simplified algorithm that music generation. In the fifth and sixth sections we describe
nevertheless obtains interesting results. our experiments, where we have compared the use of one or
I. I NTRODUCTION two target guides, and six different recombination procedures
for the genetic algorithm. Finally, the last section presents our
The automatic generation of musical compositions is a
conclusions and possibilities for future work.
long standing, multi disciplinary area of interest and research
in computer science, with over thirty years of history at its II. M USICAL REPRESENTATION : RESTRICTIONS
back. Melody, rhythm and harmony are considered the three fun-
Some of the current approaches try to simulate how the damental elements in music. In the experiments performed in
musicians play [1] or improvise [2] on the fly, while others this paper, we shall restrict ourselves to melody, leaving the
are not concerned with execution time and mainly try to management of rhythm and harmony as future objectives. In
generate some ‘good’ output. Many of them apply models this way, we can forget about different instruments (parts and
and procedures of theoretical computer science (cellular au- voices) and focus on monophonic music: a single performer
tomata [3], parallel derivation grammars [1], or evolutionary executing, at most, a single note on a piano at a given point in
programming [4], [5], [6], [7]) to the generation of complex time. Melody consists of a series of musical sounds (notes) or
compositions. The models are then assigned a musical mean- silences (rests) with different lengths and stresses, arranged
ing. In some cases, the music may be automatically found in succession in a particular rhythmic pattern, to form a
(composed) by means of genetic programming. recognizable unit.
In a previous paper [8] we proposed the use of the well- In the English notation for Western music the names of the
known Normalized Compression Distance [9], an algorithmic notes belong to the set {A, B, C, D, E, F, G}. These letters
information measure , as a fitness function which may be represent musical pitches and correspond to the white keys
used by genetic algorithms to automatically generate music on the piano. The black keys on the piano are considered as
in a given pre-defined style. The superiority of the relative modifications of the white key notes, and are called sharp
pitch envelope over other musical parameters, such as the or flat notes. From left to right, the key that follows a white
lengths of the notes, has been confirmed in [10], bringing us key is its sharp key, while the previous key is its flat key. To
to develop a simplified algorithm that nevertheless obtains indicate a modification, a symbol is added to the white key
interesting results. name (as in A# or A+ to represent A sharp, or in Bb or B-,
In this paper we start on the results of the previous work which represent B flat). The distance from a note to its flat
and refine them, trying to increase the efficiency of the pro- or sharp notes is called a half step and is the smallest unit
cedures described in the above mentioned paper. This is done of pitch used in the piano, where every pair of two adjacent
by testing several variations of the recombination operator to keys are separated by a half step, no matter their color. Two
fine tune the genetic algorithm for this application, as it has consecutive half steps are called a whole step. Instruments
M. Alfonseca, M. Cebrián and A. Ortega are with the Escuela Politécnica different from the piano may generate additional notes; in
Superior of the Universidad Autónoma de Madrid, Tomas y Valiente 11, P. fact, flat and sharp notes may not coincide; also, in different
O. Box 28049, Madrid, Spain (e-mail: {manuel.alfonseca, manuel.cebrian, musical traditions (such as Arab or Hindu music) additional
alfonso.ortega}@uam.es).
This work has been supported by grant TSI 2005-08255-C07-06 of the notes exist. However, in these experiments, we shall restrict
Spanish Ministry of Education and Science. to the Western piano lay-up, thus simplifying the problem to

3035
1-4244-1340-0/07$25.00 2007
c IEEE
just 88 different notes separated by half steps. An interval where K(x|y) is the conditional Kolmogorov complexity of
may be defined as the number of half steps between two string x given string y, whose value is the length of the
notes. shortest program (for some universal machine) which, when
Notes and rests have a length (a duration in time). There run on input string y outputs string x. K(x) is the degenerate
are seven different standard lengths (from 1, corresponding to case K(x|λ), where λ is the empty string; see [12] for a
a whole or round note, to 1/64), each of which has duration detailed exposition on the subject. Unfortunately it can be
double than the next (whole, half, quarter, ...). Intermediate proven that, due to the well-known halting problem, both
durations can be obtained by means of dots or periods, the conditional and the unconditional complexities happen
triplets and other constructs. The complete specification of to be incomputable functions.
notes and silences includes their lengths. In [9] a computable estimate of the NID, the Normalized
A piece of music can be represented in several different, Compression Distance (NCD), is presented:
but equivalent ways:
1) With the traditional Western bi-dimensional graphic
max{C(xy) − C(x), C(yx) − C(y)}
notation on a pentagram. NCD(x, y) = (2)
2) By a set of character strings: notes are represented by max{C(x), C(y)}
letters (A-G), silence by a P, sharp and flat alterations
by + and - signs, and the lengths of notes by a number where xy is the concatenation of strings x and y, and C(x)
(0 would represent a whole note, 1 a half note, and denotes the length of the text x compressed by some com-
so on). Adding a period provides intermediate lengths. pression algorithm which approximates K(x) from above.
Additional codes define the tempo, the octave and Distances near 0 indicate similarity between objects, while
the performance style (normal, legato or staccato). those near 1 reveal dissimilarity.
Polyphonic music is represented with sets of parallel
Li and Sleep have reported that this distance, together with
strings.
a nearest neighbor or a cladistic classifier, outperforms some
3) By numbering (1 to 88) the pitches of the notes in the
of the finest (more complex) algorithms for clustering music
piano keyboard. Note 0 would represent a silence. The
by genre [10]. An earlier research has also reported success
length of a note can be represented by a multiple of
of the same distance for clustering tasks [13]. These results
the minimum unit of time. A voice in a piece of music
suggest that the NCD, although not achieving the universality
would be a series of integer pairs representing notes
of its incomputable predecessor (the NID), works well at
and lengths. Polyphonic music may be represented by
extracting features shared between two musical pieces.
means of parallel sets of integer pairs.
4) Other coding systems are used to keep and reproduce On the other hand, genetic algorithms need to define a
music in a computer or a recording system, with or fitness function to compare different individuals, subject to
without compression, such as wave sampling, MIDI, simulated evolution, and classify them according to their
MP3, etc. degree of adaptation to the environment. In many cases,
fitness functions compute the distance from each individual
In our experiments, we represent melodies by the second
to a desired goal.
and third notation systems.
Assume we want to generate a composition that resembles
III. T HE N ORMALIZED C OMPRESSION D ISTANCE a Mozart symphony; in this situation, we can elaborate a
natural fitness measure: an individual (representing a com-
The search for a universal distance has been, for a long position) has a high fitness if it shares many features with
time, one of the main objectives of cluster theory. The as many as possible of Mozart’s symphonies. We propose
availability of such a distance would make it possible to to use a genetic algorithm (with musical compositions as
apply the same algorithms to widely different clustering individuals of the population) which uses the NCD as the
problems, such as the classification of music, texts, gene fitness measure. This measure may compute these shared
sequences, and so forth. features between the individuals and the target musical
A deep result from Algorithmic Information Theory is guides which, in this example, would be the set of Mozart’s
that there exists such a universal similarity distance, which symphonies.
summarizes all computable similarities: the Normalized In-
It remains to choose the compressor used to estimate the
formation Distance (NID) [11]. It is universal in the sense
NCD. Li and Sleep compute it by counting the number
that, when when a small distance is measured by any means
of blocks generated by executing the LZ78 compression
between any two given objects, the NID is also small between
algorithm [14] on an input. In our initial experiments, we
these objects. Thus, it is at least as good as any other
used both the LZ78 and LZ77 algorithms, and found that
computable similarity distance. The NID is mathematically
LZ77 performs better, which agrees with theoretical results
defined as follows:
from Kosaraju and Manzini [15]. Therefore, LZ77 has been
max{K(x|y), K(y|x)} used as our reference compressor in all the experimental
NID(x, y) = (1)
max{K(x), K(y)} results presented in this paper.

3036 2007 IEEE Congress on Evolutionary Computation (CEC 2007)


IV. T HE GENETIC ALGORITHM USED TO GENERATE 3) The genotypes are ordered by their increasing distance
MUSIC to the guide set, i.e. decreasing fitness.
Our genetic algorithm generates music coded as pairs of 4) If some predetermined fitness has been reached, the
integers, the third format described in section II, which is genetic algorithm stops. The notes in the target geno-
specially fitted for our purpose. This notation can then be type are paired with a function of the lengths of the
transformed to a note string (the second representation) for guide piece(s).
reproduction. 5) The 16 genotypes with lowest fitness are removed. The
As we have previously stated (see sect. II), we also decided 16 genotypes with highest fitness are paired randomly.
to start with monophonic music, leaving harmony for a later Each pair generates a pair of children, a copy of
phase and working with melodies. the parents modified by four genetic operators. The
Finally, we made the decision, in this first stage of exper- children are added to the population to make again 64,
iments, to apply the genetic algorithm only to the relative and their fitness is computed as in step 2.
pitches of the notes in the melody (i.e. we only consider 6) Go to step 3.
the relative pitch envelope), ignoring the absolute pitches We need to say some words about our coding choice.
and the note lengths. The reason is that our own studies The use of only two octaves for the notes (i.e. [24,48])
and others’ [10] suggest that a given piece of music remains does not represent an important restriction (actually many
recognizable by a human being when the lengths of its notes real melodies comply with it), while it reduces significantly
are replaced by random lengths, while the opposite does not the size of the search space. The fact that absolute notes
happen (the piece becomes completely unrecognizable if its are later converted to intervals has the consequence that a
notes are replaced by a random set, while maintaining their piece of music becomes invariant under transposition, which
lengths). is proper, because human ear recognizes transposed pieces
The proposed genetic algorithm scheme is now described. as very similar.
It includes a previous pre-process step, made of the following The second number, belonging to the [1,16] interval in
parts: each pair, represents the length of the note and is currently
• One or more (M ) musical pieces of the same ignored (remember that these lengths are replaced by a
style/author are selected as targets or guides for music function of the lengths of the guide pieces). In this way,
generation. We define each of the guides as gi and the however, the system is ready for the future objective of
M
guide set as G = {gi }i=1 . automatically generating the lengths.
• All the guides are coded as pairs of integers, as de- The four genetic operators mentioned in the algorithm are:
scribed above. In our experiments, the set of guides • Recombination (applied to all generated genotypes).
may include pieces of music of unequal (but not too The genotypes of both parents are combined using
dissimilar) lengths. different procedures to generate the genotypes of the
• The individuals in the population are coded in the same progeny. Different recombination procedures have been
way as the guides. tested in this set of experiments to find the best strategy
• The fitness function for an individual x and a guide set (see sect. VI):
G is defined as – Single point crossover, adjusted for variable
⎛ ⎞−1
 length genomes: given a pair of genotypes,
f (x) = ⎝ NCD(x, gi )⎠ (3) (x1 , x2 , . . . , xn ) and (y1 , y2 , . . . , ym ), a random
gi ∈G integer is generated in the interval [0, min(n, m)],
let it be i. The resulting recombined geno-
By maximizing f (x) (minimizing the sum of the dis- types are: (x1 , x2 , . . . , xi−1 , yi , yi+1 , . . . , ym ) and
tances), we expect to maximize the number of features (y1 , y2 , . . . , yi−1 , xi , xi+1 , . . . , xn ).
shared by the evolving individuals with the guide set. – Modified two-point crossover for variable
The remaining steps of the genetic algorithm are: length genomes: given a pair of genotypes,
1) The program generates an initial random population (x1 , x2 , . . . , xn ) and (y1 , y2 , . . . , ym ), two random
of 64 vectors of N pairs of integers, where N is the integers are generated in the interval [0, n] (let
length of the first piece of music in the guide set. us call them i, j, i < j) and another two in the
The first integer in each pair is in the [24,48] interval interval [0, m] (let us call them p, q, p < q).
and represents the note interval. The second is in the The resulting recombined genotypes are:
[1,16] interval and represents its length as multiple of (x1 , x2 , . . . , xi−1 , yp , yp+1 , . . . , yq−1 , xj , xj+1 , . . . , xn )
the minimum unit of time. Each vector represents a and
genotype. (y1 , y2 , . . . , yp−1 , xi , xi+1 , . . . , xj−1 , yq , yq+1 , . . . , ym ).
2) The fitness of the genotypes is computed as in eq. 3,
where x is the relative pitch envelope, i.e. the set of – Recombination based on a four point crossover:
running differences between each note and the next, given a pair of genotypes, (x1 , x2 , . . . , xn ) and
while lengths are ignored. (y1 , y2 , . . . , ym ), four random ordered integers are

2007 IEEE Congress on Evolutionary Computation (CEC 2007) 3037


Fig. 1. A piece generated with Yankee Doodle as the only guide (NCD 0.43).

generated in the interval [0, n], [0, m] for each par- First, we used Yankee Doodle as the guide a single piece
ent genotype. Each genotype is then cut into the five of music, described by the following string with the second
corresponding pieces, which are shuffled together representation defined in sect. II:
(one of them is reversed). Finally, the genotypes of M2T2O3L2C+4C+4D+4F4C+4F4D+4O2G+4O3C+4C+4D+4F4
the progeny are obtained by concatenating five of C+3C4P4C+4C+4D+4F4F+4F4D+4C+4C4O2G+4A+4O3C4C+
the pieces in the shuffled 3C+4P4O2A+4.O3C5.O2A+4G+4A+4O3C4C+4P4O2G+4.A+
– Recombination based on a three point crossover: 5.G+4F+4F3G+4P4A+4.O3C5.O2A+4G+4A+4O3C4C+4O2A
similar to the preceding one, but only three ran- +4G+4O3C+4C4D+4C+3C+3
dom ordered integers are used to divide the parent The corresponding WAV formatted file, Yankee.wav, to-
genotypes into four pieces, which are then joined, gether with all the musical pieces mentioned in this paper,
shuffled, and used (four at a time) to generate the can be found at:
genotypes of the progeny. www.eps.uam.es/˜mcebrian/music
• Mutation (one mutation was applied to every generated After applying the genetic algorithm, the succession of
genotype, although this rate may be modified in dif- notes obtained was completed by adding length information
ferent experiments). It consists of replacing a random in the following way: each note was assigned the length of
element of the individual genotype by a random integer the note in the same position in the guide piece (the guide
in the same interval. piece was shortened or circularly extended, if needed, to
• Fusion (applied to a certain percentage of the gener- make it the same length as the generated piece, which could
ated genotypes, which in our experiments was varied be shorter or longer).
between 5 and 10). The genotype is replaced by a In successive executions of the algorithm, we obtained
catenation of itself with a piece randomly broken from different melodies at different distances from the guide. It
either itself or its paired genotype. was observed that a lower distance made the generated music
• Elision (applied to a certain percentage of the generated more recognizable to the ear, as related to the guide piece For
genotypes, in our experiments between 2 and 5). One instance, the distance to the guide of the following generated
integer in the vector (in a random position) is elimi- piece. (see also figure 1, where the same music appears in
nated. standard musical notation), named Yankee NEW.wav is 0.43:
The last two operations, together with some recombination T5O3D+2O2G+2O3C+2C+2D+2F2F+2F2E2C2D2E2O2F1D2E
procedures, allow longer or shorter genotypes to be obtained 2D2C2D2E2F+2G2G2A2B2O3C2O2B2O3D2E1O2F2D+2F2.G
from the original vectors. 3.G+2F2D+2G+2F+2E2F+2.F3.C+2C2D+1C+2C+2A+2.O3
C3.C+2O2G+2A+2G+2F+2O3D+2B2O3D+2C+2
V. T ESTING DIFFERENT NUMBER OF GUIDE PIECES The number of generations needed to reach a given
In our first experiments, we selected the simplest recombi- distance to the guide depends on the guide length and
nation procedure (strategy 1 in sect. VI) and tested the effect the random seed used in each experiment, and follows an
of varying the number of guide pieces and the functions approximate Poisson curve, as shown in figure 2, which
which generate the lengths of the notes in the best output represents the result of one experiment.
pieces. In our second experiment, we used two guide pieces

3038 2007 IEEE Congress on Evolutionary Computation (CEC 2007)


Fig. 3. Beginning of a piece generated with two songs by Cole Porter as guides (NCD 0.67 from Begin the beguine and 0.72 from My heart belongs to
daddy).

G+2F+3A3A+3G+3.F+1D+3.C+3.C3.O2A+3.A+0A+3.O3C
3.O2A+3.O3C3.C+0D3.C3.O2C3.

To obtain the preceding piece, we completed the succes-


sion of notes generated by the genetic algorithm with the
required length information, in the following way: each note
was assigned the average lengths of the two notes in the
same position in the two guide pieces (the guide pieces were
shortened or circularly extended to make them the same
length as the generated piece). This approach happens to
provide a more esthetically appealing result than the one
obtained when the length of only one of the guide pieces
is used.
In our third experiment, Chopin’s prelude number 4
(Chopin4.wav) and prelude number 7 (Chopin7.wav)
Fig. 2. Number of generations needed to reach a given distance to the were used as simultaneous guides. The result
target (only one guide).
(Chopin47 NEW.wav, see also the first notes in figure
4) came to be at distances of 0.61 and 0.74 from the two
simultaneously: Begin the beguine (Begin.wav), and My heart guide pieces, which are separated from one another by a
belongs to daddy (Heart.wav), both by Cole Porter. distance of 0.96. The length of the notes was generated in
The following represents one of the results we obtained the same way as in the preceding experiment. Compared
(figure 3 shows the first notes in standard musical notation), with this, the piece obtained using as guides two works by
which we named as Porter NEW.wav, which happens to be Cole Porter has a distinctly lighter sound.
at a distance of 0.67 from the first guide piece, and 0.72 T5O3G+2.O2A+2O3G1.O2A+1O3G0O3F+1.O3C0O2B2.O3D
from the second, while the NCD between both guide pieces +1.O3F+1O2F+0O2F+1.O2G0O2F+2.O2F1.O2E2.O2E2O2
E0O2B1.O3C2O3D+3.O3D+2.O3D+2.O3D1O3C+2.O2A+1.
is 0.81, i.e. the generated piece was nearer to both guides
O2A2O2G+0O2G+2O2A1O3C2.O3E2O3G3.O2B2.O3D2.O3C
than they are among themselves: 1O4C2.O4C2O2C3O2D0O2F1O2D+0O2A1O3F+1.O3G2O3E2
T5O3C+3.D3.O2A3.O3F+1.F+3.D+3.O2G+3.O3C+1O2G+ .O2F+2O2B1.O2B2O2B3.O2D+4O2G+2O2F1O2G+1O2F2O2
3.C+3.D+3.D3.F1D+3.C+3.C3.C3.C+3.D+1O3C3.D3.F F+2O2A+3.O2A+2.O2A+2.O2C+1O2A+2.O2A+2O2A3.O2A
3.D1F3.E3.O2G+3.O3D+2C2O2A+1O3C3.O2A+3.A+3.A+ +2.O3C+2.O3F1O2B2O2B2O3C+2.O2B2.O3B0O3B1O2B2.
1A+1G+3.E1.F+3.O4C3.O3F3.G1.F+3.C+3.D+3.E1G+3 O3F+1.O3G2O3B2O2B0O3C+1.O2B0O3C+2.
.E3.E3.O2C3.D+1C+3.D+3.O3C3.C3.G+3.C+1D+2E2F+
3.E1.O2B3.O3G+3.O2C3.C+3.C+1C+3.F3.G3.G1F1D+3 We performed another two experiments which the reader
.O3C1C3.O2A3.D3.A+3.O3C1D3.O2F+3.F+3.D3.G3.F1 can also find online. One of them generates a piece
O3D3.E2D+2E1.D+3.G+3.O2D+3.D+1G3.A3.G+3.O3C3. (Chopin7 NEW.dat, see figure 5) at a 0.39 distance from its
O2A1A3.E3.F+3.G3.B3.G1D+3.D+3.F3.A+3.B1O3D+3. guide, Chopins’s seventh prelude. The lengths were generated
C+3.F+3.F+1.E3.D+3.D+3.C2O2B1O3D+3.C3.O2B2O3E as in the first experiment:
2O2A1A2G+3.G+3.E2.F+3.F3.D+2F1D3.D+3.O3F2D+3.
F+3.D1O2A2G+3.O3C+3.G+2F2C+2O2A2F1O3F+3.B2.O2 T5O4C1O3E2.C+3A+1A+1A+0O2A+1O3C+2.O2B3O3B1B1B
F+3.E3.G3.F+1E3.E3.D+3.C+3.O3C+1.O+2G+1C+3.C+ 0D+1D+2.E3G+1O4C1O3E0C+1D2.F3F1F1O2B0C+1A+2.B
1D+3.F3.A+2G+2G+3.F+1D+2E3D0D+2F3.D+3O3G3.D2B 3G+1G+1G+0O3G+1G+2.G+3O2B1O3E1E0E1O2B2.O3F+3D
2O2D+2O3C3C3C3.C2O2B0A3.A3A3.B2.O3C3.F+1G3.A+ +1E1A0A1A2.
3.G+3F+3A3.F1.C2O2G+3.G+3.O3G+0A+3.B3.B0B3.O2
E3A+3B3.O3D3.D3.O2A+1O3D+3F+3F0F+3.D+3F3G3.G3 Finally, in the last experiment, two pieces by Mozart
.G3.G+2A+3O4C3O3A3A+2G+0O2F+3G+3F+3.F3.F+3.O3 were used as simultaneous guides: a few bars of the first

2007 IEEE Congress on Evolutionary Computation (CEC 2007) 3039


Fig. 4. Beginning of a piece generated with two Chopin preludes as guides (NCD 0.61 from prelude number 4 and 0.74 from prelude number 7).

Fig. 5. A piece generated using Chopin’s seventh prelude as the only guide (NCD 0.39).

movement in symphony 40 (Mozart40.wav), and a part of the In order to fine tune the genetic algorithm for this appli-
second movement in sonata KV545 (KV545.wav). The result cation, we devote a section to discuss several variations we
(Mozart NEW.wav), which sounds like a mixture of both have tested experimentally. We analyzed four strategies that
sources to the ear in some parts, happens to be at distances use respectively the four types of recombination described
of 0.65 and 0.58 from the two guide pieces, which on the in section III: strategy 1 (single point crossover, adjusted for
other hand differ from one another by a distance of 0.90: variable length genomes) is the base case (the simplest re-
T5O4G+0F+3B3.A+3A3G+2.G+3B1F1G+1.F3.D+3D+3D3.
combination strategy) which was used in all the experiments
C3O3A+3O4F2.G+3F1C+1F+2.D+3.F+2E2D2C+2O3F2.F+ described in the preceding section, strategy 2 (modified two-
3.G+1O4C1O3A3.F3.O4F3.G3F3F3.G3E3G3.B3O3E3G3. point crossover for variable length genomes), strategy 3,
F2.G+3G4G+2A2O4G2G+2G1G+3.F3.G+3.O5C3O4A+3G+3 (recombination based on a four point crossover) and strategy
.A+3.A+2.G+3.G3.G3.E3D+3O3F+3F3F+3.G3.G+3.A3. 4 (recombination based on a three point crossover)
A3.G3F+3F+3.D+3.D3.O4D3.C+2C+3E2O3A+2O4C+3C2O
3B2G1B1O4D3.C3.O3G3.O4D+3G3D3.D+3D3D+3.D3E3F3
.G3.F3.E3F3G1O3D+3E3D+3.D+3B3B3.A+3.O4F3.G2.G
The one-point crossing-over strategy 1 has the property
+3A+3.G3 that the lengths of the parent genomes are invariant under
recombination in the progeny. Since mutation also keeps the
The length of the notes was generated in the same way as length of the genome, only fusion and elision change it.
in the second experiment. In fact, we did notice that, in our preceding experiments,
fusion almost never leads to a fitter genome, while elision
VI. T ESTING DIFFERENT RECOMBINATION PROCEDURES
sometimes does, which means that the version of our genetic
We have evidence that the recombination operator plays a algorithm described in the previous section, which starts with
key role in our approach, both in the quality of the generated a genome length copied from one of the target pieces of
musical pieces and in the time the algorithm takes to generate music, leads to genome lengths usually reduced by a little
it. from their initial value.

3040 2007 IEEE Congress on Evolutionary Computation (CEC 2007)


TABLE I
A COMPARISON OF THE PERFORMANCE OF DIFFERENT RECOMBINATION STRATEGIES FOR A TYPICAL MUSIC GENERATION EXPERIMENT. NP STANDS
FOR ‘N OT P ERFORMED .’

number of strategy strategy strategy strategy mixed


generations 1 2 3 4 strategy 1
1 0.930 0.930 0.930 0.930 0.930
100 0.782 (-0.148) 0.766 (-0.164) 0.807 (-0.123) 0.791 (-0.139) 0.766 (-0.164)
200 0.734 (-0.048) 0.710 (-0.056) 0.756 (-0.051) 0.744 (-0.047) 0.697 (-0.069)
300 0.714 (-0.020) 0.692 (-0.018) 0.740 (-0.016) 0.712 (-0.032) 0.676 (-0.021)
400 0.702 (-0.012) 0.692 (-0.000) 0.722 (-0.018) 0.704 (-0.008) 0.659 (-0.017)
500 0.690 (-0.012) 0.689 (-0.003) 0.722 (-0.000) 0.704 (-0.000) 0.648 (-0.011)
600 0.681 (-0.009) 0.683 (-0.006) 0.716 (-0.006) 0.704 (-0.000) 0.643 (-0.005)
1000 0.663 (-0.018) 0.682 (-0.001) NP NP NP
1500 0.658 (-0.005) 0.666 (-0.016) NP NP NP
2000 0.656 (-0.002) 0.658 (-0.008) NP NP NP
2500 0.644 (-0.012) 0.652 (-0.006) NP NP NP

Fig. 6. Two different experiments with a comparison of three recombination strategies. ‘Mixed strategy’ refers to the mixed strategy 1.

Strategies 2, 3 and 4, however, all lead to progeny genomes the algorithm uses the second strategy (the two point
with lengths usually quite different from those of their par- recombination procedure with four different crossing-over
ents (even when both parent genomes had the same length), points between both parents). During all the remaining
which provides the population with a larger genome length generations, the first strategy is used instead (i.e. the one
diversity than strategy 1. point recombination procedure with a single crossing-over
After performing several experiments we noticed that, at point for both parents).
the beginning of the evolution, the second recombination
strategy converges more quickly towards the target, but after Mixed strategy 2: In the first 200 generations, the program
a certain number of generations (usually between 150 and uses the second strategy; between generations 200 and 500
200), the first and fourth strategies behave better, while it switches to the fourth strategy, and above 500 generations
beyond about 500 generations after the beginning of the it uses the first strategy.
process the first strategy is clearly the best. Above 1000
generations, the first two strategies tend to converge, i.e. to
The data in table I correspond to a typical experiment
obtain similar distances to the goal after the same number of
in which two Mozart’s pieces were used as the guide set:
generations.
Symphony 40 and KV545. The results of the combined
This brought us to add two new strategies to the testbed, strategies are much better than those of any of the four
which are simple combinations of the four described above: strategies applied separately. It can be observed that the
mixed strategy 1 reaches, in just 600 generations, target
Mixed strategy 1: In the first 150 to 200 generations, distances similar to those attained by the first two strategies

2007 IEEE Congress on Evolutionary Computation (CEC 2007) 3041


after 2500 generations. a future work, we intend to add a component to the system
Tabulated values for mixed strategy 2 are not shown in that allows and encourages outliers as well.
table I because they are quite similar to the performance Although we have introduced the information about note
of mixed strategy 1. In case of strategy 3 and 4, no data duration in the genetic process, it has been ignored so far. We
are shown for more than 600 generations; the reason is that intend to experiment with different strategies (such as setting
they are clearly outperformed by strategy 1 and 2 in all all the notes to the same length). Furthermore, as the NCD
executions before that point, and no further improvement was can easily deal with integers representing note lengths, we
experimentally observed. intend to let the note length information evolve together with
Figure 6 shows a graphical representation of two exper- the melody. We shall also experiment with richer systems of
imental results with three strategies on the same guide set. music representation, such as MIDI.
Summarizing, the improvement of the mixed strategies is This paper serves as a proof-of-concept. As future re-
quite impressive. On the other hand, the two mixed strategies search, we plan to provide a comparison with state-of-the-art
attain comparable results. music composition techniques based on machine learning, to
In our analysis of the reasons for this behavior, we come reveal both the strengths and the weaknesses of our proposal.
to the conclusion that, with the first strategy, the population
R EFERENCES
has a small genetic variability where favorable mutations
have a great probability of appearing. On the other hand, [1] J. McCormack, “Grammar based music composition,” Complex Sys-
tems, 1996.
the second strategy generates a large genetic variability, both [2] J. Biles, “GenJam: A Genetic Algorithm for Generating Jazz Solos,”
with respect to genome lengths and contents, where favorable Proceedings of the 1994 International Computer Music Conference,
mutations are harder to come by. This means that, on the pp. 131–137, 1994.
[3] E. Bilotta and P. Pantano, “Synthetic Harmonies: An Approach to
long range, the first strategy should work better than the Musical Semiosis by Means of Cellular Automata,” LEONARDO,
second, which on the other hand, gets faster results during vol. 35, no. 2, pp. 153–159, 2002.
the first part of the process by evolving simultaneously in [4] D. Lidov and J. Gabura, “A melody writing algorithm using a formal
language model,” Computer Studies in the Humanities, vol. 4, no. 3-4,
many directions and testing widely different genomes at the pp. 138–148, 1973.
same time. Thus, the mixed strategies make the best use of [5] P. Laine and M. Kuuskankare, “Genetic algorithms in musical style
both recombination procedures, which is the reason for their oriented generation,” Evolutionary Computation, 1994. IEEE World
Congress on Computational Intelligence., Proceedings of the First
outstanding performance success. IEEE Conference on, pp. 858–862, 1994.
The number of experiments performed was not large (tens, [6] D. Horowitz, “Generating rhythms with genetic algorithms,” Proceed-
ings of the twelfth national conference on Artificial intelligence (vol.
rather than hundreds), but the results obtained are consistent 2), 1994.
and show a small variability, which makes it unlikely that [7] B. Jacob, “Composing with genetic algorithms,” Proceedings of the
they may be a statistical fluke. 1995 International Computer Music Conference, pp. 452–455, 1995.
[8] M. Alfonseca, M. Cebrian, and A. Ortega, “Evolving Computer-
Generated Music By Means of the Normalized Compression Distance,”
VII. C ONCLUSIONS AND FUTURE WORK WSEAS Transactions on Information Science and Applications, vol. 2,
no. 9, pp. 1367–1372, 2005.
We have found that that the Normalized Compression [9] R. Cilibrasi and P. Vitani, “Clustering by Compression,” Information
Distance is a promising fitness function for genetic algo- Theory, IEEE Transactions on, vol. 51, no. 4, pp. 1523–1545, 2005,
rithms used in automatic music generation. Some of the software available at http://www.complearn.org.
[10] M. Li and R. Sleep, “Melody Classification using a Similarity Metric
pieces of music thus generated recall the style of well-known Based on Kolmogorov Complexity,” Sound and Music Computing,
authors, in spite of the fact that the fitness function only takes 2004.
into account the relative pitch envelope. Qualitative response [11] M. Li, X. Chen, X. Li, B. Ma, and P. Vitányi, “The Similarity Metric,”
Information Theory, IEEE Transactions on, vol. 50, p. 12, 2004.
by human audiences confirms that the results described in [12] M. Li and P. Vitanyi, An Introduction to Kolmogorov Complexity and
this paper are superior to those obtained previously with a Its Applications. Springer, 1997.
different fitness function [16]. [13] R. Cilibrasi, P. Vitanyi, and R. de Wolf, “Algorithmic clustering of
music,” Proceedings of the Fourth International Conference on Web
Several recombination operators have been tested to fine Delivering of Music, 2004. WEDELMUSIC 2004., pp. 110–117, 2004.
tune the genetic algorithm for this application, finding that [14] J. Ziv and A. Lempel, “A universal algorithm for sequential data
mixed strategies which promote diversity in the first gen- compression,” Information Theory, IEEE Transactions on, vol. 23,
no. 3, pp. 337–343, 1977.
erations and then change to a more exploitative strategy [15] S. Kosaraju and G. Manzini, “Some entropic bounds for Lempel-Ziv
give the best results. This scheme of initial exploration algorithms,” Proceedings of the Conference on Data Compression,
and posterior exploitation is analogue to the idea behind 1997.
[16] A. Ortega, R. Alfonso, and M. Alfonseca, “Automatic composition of
Simulated Annealing [17]. music by means of grammatical evolution,” Proceedings of the 2002
In the future we intend to combine our results with those of conference on APL: array processing languages: lore, problems, and
other authors [10], [13] and use as the target for the genetic applications, pp. 148–155, 2002.
[17] S. Kirkpatrick, C. Gelatt Jr, and M. Vecchi, “Optimization by Simu-
algorithm, not one or two pieces of music by a given author, lated Annealing,” Science, vol. 220, no. 4598, p. 671, 1983.
but a cluster of pieces by the same author, thus trying to
capture the style in a more general way.
Our current experiments focus the search on melodies
which can be considered an average of the target pieces. In

3042 2007 IEEE Congress on Evolutionary Computation (CEC 2007)

View publication stats

You might also like