Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
An Experiment with Algorithmic Composition
Jingwei Liu
Abstract
Many algorithmic composition methods are either developed by imitating the styles and struc-
tures of existing corpus, or only able to produce raw materials for composers or other systems to
utilize. In order to overcome these shortcomings, a conservative dynamical system – double pendu-
lum was modeled to generate compositions in its own right due to some modifications applied by
the algorithm itself. The original data sampled from a double pendulum system was transformed
into staff notes through a natural 2-D to 1-D mapping. This note sequence was then rhythmized
by pattern recognition methods and modified according to some basic rules in music theory. The
melody generated was accompanied by a chord progression in bass clef, which was generated auto-
matically by the rules of common chord progressions and voice leading of common tone approach.
The compositions produced by this method could achieve a high level of variety because firstly, the
chaotic system is sensitive to initial conditions, which means a subtle change of parameters could
change the melody dramatically; secondly, the model is highly adjustable – any key signatures and
time signatures can be specified. Due to the modifications, even sampled from the same system,
two compositions with different key signatures or time signatures can be distinct from each other
significantly.
Keywords: computer music, algorithmic composition, mathematical music, double pendulum,
computational creativity
Extenuating Circumstances Statement
I want to give some explanations about the circumstances of me writing this paper. One year
ago, I got enrolled in Basic Concepts of Music Theory at the UW-Madison. This was my first
music-theory course and also the cause for my career shift. Shortly after I got enrolled, I started
my algorithmic-composition experiment. At that time, I had little theoretical knowledge, but I
was excited, because I knew it was the thing I had been looking for and I desired to see what I
could do. Based on our textbook Theory Gizmos:Fundamental Tools to Understand, Analyze, and
Build Music (Henke, 2011), I started building my compositional system. As you can see, the book
only covers some basic concepts like rhythm, scales and chords. I didn’t even learn consonance
and dissonance at that time. I tried my best to use the knowledge I’ve learned, such as “starting
and ending a period on tonic”, “antecedent and consequent”, “common chord progressions” to set
up the framework of my algorithms. Some of the results look ridiculous now, but at that time it
worked for me. Actually, I sort of circumvented music theory on purpose, since my intention was to
explore computer creativity and see to what extent the computer could do. Besides, I was told that
there were no strict rules for music in the twentieth century. Therefore, I chose to minimize the
restrictions of music theory, allowing the system to reflect the model (chaotic system) properties as
much as possible. At that time, this project was a success for me. I adopted lots of methods from
various fields of study and they fitted right in place. My idea was implemented as imagined.
However, in the next semester, as soon as I got enrolled in another course, Musica Practica
1, I knew my project messed up. Those computer-generated compositions countered every rule I
learned in this course. I was too naive at that time. However, I was also glad that music is so
complicated and well-formed, so that I can exploit my other skills to study it, hopefully producing
more rigorous and meaningful results. When I was taking this course, unfortunately, my work on
algorithmic composition has been closed. Instead of going back and changing everything, I chose
to let it go. This paper has its own value, and what matters most, it is my first paper. I decided
to keep it as it was regardless of the imperfectness. Hope you can find something interesting here.
Please enjoy!
Content
Introduction 1
1 Previous Work Summary 2
2 Double Pendulum System 2
3 Rhythm Patterns Distribution 4
3.1 Time Series Data Mining Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.1 Local Pattern Recognition: Collision Matrix . . . . . . . . . . . . . . . . . . 5
3.1.2 Global Pattern Recognition: Perceptually Important Points (PIP) . . . . . . 8
3.2 Form Duration Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.1 Step 1: Identify Adjacent Similar Patterns . . . . . . . . . . . . . . . . . . . 10
3.2.2 Step 2: Identify Locally Distinct Motifs . . . . . . . . . . . . . . . . . . . . . 11
3.2.3 Step 3: Identify Globally Similar PIP Modes . . . . . . . . . . . . . . . . . . 12
3.2.4 Step 4: Randomize Rhythm for Remaining Parts . . . . . . . . . . . . . . . 14
3.2.5 Data Adjustment Based on Music Theory . . . . . . . . . . . . . . . . . . . 15
4 Building Chord Progression 16
4.1 Triads and Seventh Chords: Cyclic Group . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Common Chord Progression: Longest Weighted Tree . . . . . . . . . . . . . . . . . 18
4.3 Voice Leading of Common Tone Approach: Common Tone Distance . . . . . . . . . 21
5 Model Evaluation 22
5.1 Control Variable Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.2 Variety: Sensitive to Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.3 Generality: Highly-Adjustable System . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.4 Other Pros and Cons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
References 31
CONTENT An Experiment with Algorithmic Composition
Introduction
Inspired by (Beyls, 1991) and (Dubnov & Surges, 2014), in which a distinctive idea about
chaos and creativity was put forward, I started my journey in finding chaotic dynamical models for
musical composition. Many traditional channels in algorithmic composition are either developed
by imitating the styles and structures of existing corpus, or only able to produce raw materials for
composers or other systems to make use of. However, two observations led to the consideration of
totally different methods. First, expert systems are always biased by the knowledge of program-
mers. The biggest difference between art and science is, there is no standard or absolute solution
to a problem in the art field. Every work in art is a product of individual – it all depends on the
creator’s style, experience, preference, societal situation, etc. Even if there is a general formula,
artists would never give up on trying to break it and developing new rules. Second, in program
music, composers get their inspirations from everything in life – nature, poems, romantic experience
and even dreams. This follows the recurring concept along the history of mankind called ”Musica
Universalis” (Castilho, 2015). Everything can be translated into notes on staff papers by talented
composers. As science and technology have developed rapidly since the 20th century, new possi-
bilities are also open to different ways of composing music. Among all of the systems and models,
the complex dynamical system became an alternative due to its simple forms of expression and
surprisingly complex overall behavior.
The article is structured as follows: in the first section, I would briefly summarize the previous
work related to chaotic systems when composing and analyze the pros and cons of these models.
The second section is dedicated to the model we selected – double pendulum system. The system
would be described from the perspective of composition and a map from the 2-D data sampled from
the system to 1-D notes on the keyboard is defined. In the third section, two methods would be
introduced to recognize similar patterns in the note sequence. According to these patterns, four
steps would be devised to distribute durations to the note sequence by allocating the same durations
to similar patterns. The fourth section is meant to construct a chord progression accompanying
the melody generated by the last steps. Based on the principles of common chord progressions, a
chord sets tree would be built. By determining the longest weighted path from the root to a leaf of
this tree, we could find the desired chord progression for this piece. To place these chords, guided
by the voice leading of common tone approach, a new distance is defined to determine the chord
positions. In the last section, the model would be evaluated from multiple perspectives. Its shining
points would be pointed out and the further improvements would be discussed as well.
1
2 DOUBLE PENDULUM SYSTEM An Experiment with Algorithmic Composition
1 Previous Work Summary
Most of the work of musical composition involving chaotic systems makes use of dissipative
chaotic systems (Gogins, 1991) (Pressing, 1988) (Herman, 1993). As we know, chaotic systems can
be classified into two basic types – dissipative and conservative. The dissipative system dissipates
its energy to its surroundings as the system evolves, while the energy of a conservative system is
conserved as a constant no matter how the system evolves with time. Since dissipative systems
lose energy over time, their phase space - that is, the area or volume in which the possible states
of the system take place - shrinks with time. It is this shrinkage that leads to the formation of an
attractor after an initial transient phase. Among all the attractors, what draws the attention of
music researchers most is the chaotic strange attractor, which is sensitive to initial conditions. The
main reason why this particular type of attractor is popular is that they present self-similarity and
fractal structures. ”In general, self-similar musical patterns have multiple levels of structure, with
pleasing regularities but also dotted with sudden changes” (Fernández & Vico, 2013). However,
The methods rooted in dissipative systems are widely regarded as not suitable to produce melodies
or compositions in their own right, but as a source of inspiration or raw material (Bidlack, 1992).
This is mainly caused by the globally stable characteristic of strange attractors. Once passing the
transient phase, the sequence will stay around the attractor (or attractors). This phenomenon is
doomed to cluster the sampled notes, which would make them indistinguishable and unmusical.
However, conservative systems, on the other hand, maintain a constant phase space. Orbits
of conservative systems do not go through a transient phase, nor are they drawn to an attractor.
These properties give us an opportunity to generate compositions directly from the chaotic models.
2 Double Pendulum System
The conservative chaotic system used in this article is the double pendulum system. The orbits
of this system wander erratically almost throughout the phase space, which enables the system to
produce melodies in its own right as the notes won’t cluster. What’s more, this model is sort of
periodic in a rough sense but also has variations in details. These repetitions and variations are
exactly what we need in compositions. This section is dedicated to a brief introduction to the double
pendulum system and a detailed description of the sampling and mapping methods to illustrate
how to turn this dynamic system into a sequence of notes.
Here we apply the fourth Runge-Kutta method to simulate the motion of double pendulum.
When sampling from the trajectory of the lower pendulum, in order not to make the sampling points
too dense or too sparse, I chose to calculate the time for the upper mass to go from the leftmost
to rightmost(or vice versa) in its own motion for the first time. Then sample 6 points evenly in
2
2 DOUBLE PENDULUM SYSTEM An Experiment with Algorithmic Composition
respect to time in the lower pendulum path – which determines the time interval we use to sample
the points afterwards. Here are the first few points I sampled using this principle (Figure 1). As
we can see, these points would neither be too dense to distinguish when mapped to notes nor too
sparse to depict the original shape of its motion.
Figure 1: First Few Points from Sampling
Next we consider the mapping. The points we sampled are on the x-y plane, namely, they are
2-dimensional. However, the notes from keyboard are 1-dimensional. In order to define a reasonable
natural map from 2-D to 1-D, we consider as follows.
As the lower mass moving from left to right, we model this movement as it goes through
the keyboard, with pitches increasing. Under such consideration, we divide the interval [−(L1 +L2), (L1 + L2)] on x-axis evenly, to 12 parts for example, then map part of the keyboard which is
composed of 12 notes to the interval. In order to compose tonal music, we choose 12 notes only from
certain key signature sequentially, rather than 12 notes half step away from each other in chromatic
scale.
As for the y-axis, the intuitive sense reading the graph is – the pitch should go higher when
the value of y gets larger. However, the increase of pitches has been realized by x-axis. Here to
make use of values from y-axis and make the map natural, we consider a way to translate the note
sequence mapped to x-axis to different parts on the keyboard as y variates. To be specific, I divided
y-axis on interval [−(L1 +L2), (L1 +L2)] into several intervals, as the values of y of these samplingpoints change, for example, from an lower interval to its upper one, the corresponding part of the
keyboard mapped to x-axis will translate parallel to the right by 2 or 3 notes. In this way, we get
the mapping note sequence as Figure 2.
3
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Figure 2: Note Sequence from Sampling
3 Rhythm Patterns Distribution
Since the note sequence has been obtained, the next step is to modify it based on basic rules
of music theory, using tools borrowed from math and computer science, and to achieve our goal of
composing a complete piece fully automated and sounds musical.
The first task is to assign durations to every note. Rhythm is the vitality of music, we cannot
call a piece melody without rhythm. In order to make rhythm patterns fit the time signature (2/4
meter in this example), instead of using random duration allocation for each note (which turned
out to be a failure as it’s too difficult to put the composition produced into measures, letting alone
apply basic concept of music theory to modify it), I adopted a so called predefined rhythm pattern
set as shown in Figure 3.
In the predefined rhythm set, we give the rhythm patterns for 1,2,3,4 notes separately. For
patterns discovered consisting of more than four notes, it’s easy to generate their durations from
the combinations of these basic rhythm patterns. For example, the rhythm of a pattern including
5 notes can be generated by ”2 + 3” or ”3 + 2” pattern directly.
In this section, two time series data mining methods are introduced – collision matrix method
and perceptually important points method – to recognize similar patterns locally and globally
respectively. Then applying the characteristics we discovered from these two methods, four steps
are devised to form the duration array. These steps respectively are: identifying similar patterns,
discovering locally distinct motifs, identifying globally similar PIP modes and randomizing rhythm
4
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Figure 3: Predefined Rhythm Patterns
for remaining parts, which are ranked carefully due to certian principles. In the meantime, we
also applied some basic rules in music theory to modify the note sequence to make it classical and
melodious. The Accomplishment of the rhythm distribution process represents a piece of melody
has been successfully composed out of our model.
3.1 Time Series Data Mining Methods
It seems incredible to link time series data mining to the rhythm distribution at first glance
as they come from totally different systems. However, let’s plot a graph to joint these notes from
Figure 2 first. The graph is shown in Figure 4, as you may notice, there is a subtle difference
between the original note sequence and the notes represented here. We can tell that there are three
vertical lines in Figure 4 which give the tonic tones for this piece (E major) and the first note
in this graph starts on the tonic, which is not the case in Figure 2. Actually here we did some
preprocessing for the original data by truncating its first few notes to make it start from tonic while
keeping everything remaining the same. This conduct also can be seen in Algorithm 7 when we
discuss the data adjustments based on music theory.
Figure 4 somehow looks like the data sequence from stock market right? Inspired by this
discovery, and following the basic intuition in finding repetition and motifs in music, we adopted
two methods from time series data mining to distribute durations.
3.1.1 Local Pattern Recognition: Collision Matrix
Definition 3.1. (Time Series) A time series is a series of data points T =< t1, t2, . . . , tm > indexed
(or listed) in time order, where m is the length of the time series.
Suppose sp is a subsequence of the time series T with length w, i.e. |sp| = w. DenoteS = {s1, s2, . . . , sq} to be the set of all subsequences of T with length from 1 to m (Tang & Liao,2008). For any 1 ≤ i < j ≤ q, si, sj are the subsequences of T with equal length w, namely
5
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Figure 4: Math Representation of Note Sequence
si =< si, si+1, . . . , si+w−1 >
sj =< si, sj+1, . . . , sj+w−1 >
Since each subsequence is consecutive and of equal length, we can name it by its first element
without confusion. Now we observe that as patterns to be compared, these two subsequences
shouldn’t overlap with each other, namely j − i ≥ w.
Definition 3.2. (Collision Matrix ) The collision matrix of T is a q×q matrix, and for each elementof the matrix denoted as eij ∈ M , eij = collisionHit(si, sj) where collisionHit is the similaritydegree of two subsequences, for example, si and sj. In other words, the collision matrix records the
similarity degree between any two subsequences si, sj ∈ S, 1 ≤ i, j ≤ q.
However, in regard to comparison, we only define collisionHit between two sequences with
same length in this problem. Besides, as we mentioned before, without loss of generality, we assume
1 ≤ i < j ≤ q and in order to avoid overlapping, we set j − i ≥ w, where w is the length ofsubsequences si and sj. Consequently, all terms in the collision matrix not satisfying these criteria
would be dismissed (represented by NaN for example).
In this problem, the similarity degree is measured by the Euclidean distance – the difference
between sequential notes in mathematical representation. This intuition comes from a music concept
called sequence (Henke, 2011).
6
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Definition 3.3. (Motif (music)) A short rhythmic idea repeated in different ways throughout a
composition is called a motif.
Definition 3.4. (Sequence (music)) When a motif is repeated using the same pattern of intervals
but starting on a different pitch, it is called sequence.
Since the pattern doesn’t depend on which pitch it starts with, only the shape of each pattern
matters regardless of its position. The shape of each pattern can be depicted by the difference
of successive points. If the difference sequence is exactly the same between two patterns, their
similarity degree is accurate. However, we don’t need two patterns exactly the same to say they
have similar shapes. Here we define 3 similarity degrees: Accurate, medium-similar and loosely
similar. The difference sequence B = (b1, b2, . . . , bm−1) of the note sequence P = (p1, p2, . . . , pm) is
defined as: for ∀i, 1 ≤ i ≤ m− 1,bi = pi+1 − pi
The procedure to find collision matrices is described in Algorithm 1. Instead of forming a big
sparse matrix as described in Definition 3.2, we’d love to disassemble it into several small and dense
matrices according to the lengths and similarity degrees of similar patterns. The result is shown in
Table 1.
Algorithm 1 Collision Matrix
Input: Difference sequence B = (b1, b2, . . . , bm−1)
Output: Collision matrices of pattern length 2, 3, 4 . . . for each similarity degree accordingly
1: Give 3 similarity degrees: accurate, medium-similar and loosely similar
2: for each similarity degree do
3: Traverse B again and again to find all similar subsequences of length 2, 3, 4 . . . until there is
no similar subsequence in given length.
4: end for
Table 1: Collision Matrices Enumeration
Similarity Degree Collision Matrices (Pattern Length Subscript)
Accurate A2, A3, . . . , Am
Medium B2, B3, . . . , Bn
Loose C2, C3, . . . , Cl
Here all these matrices have 2 rows – the upper and lower terms of the same column represent
similar patterns (the length of the patterns are denoted by the subscript of the matrix), and the
number of columns are determined by the number of similar patterns of the given length.
7
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
3.1.2 Global Pattern Recognition: Perceptually Important Points (PIP)
The identification of Perceptually Important Point (PIP) is first introduced by (Chung, Fu, Luk,
& Ng, 2001) and used for pattern matching of technical (analysis) patterns in financial applications
(Fu, Chung, Luk, & Ng, 2008). The concept of data point importance is defined by the influence
of a data point on the shape of the time series. A data point that has a greater influence to the
overall shape of the time series is considered as more important. The data point with importance
calculation is named as perceptually important point (PIP) and the process to identify the PIPs
is as follows: given time series P , the first two PIPs are given by the first and last points in P .
The next PIP will be the point in P with the largest distance to the first two PIPs. The fourth
PIP will then be the point in P with the largest distance to its two adjacent PIPs, either between
the first and second PIPs or between the second and the last PIPs. The process of locating the
PIPs continues until we find enough number of PIPs we demand. The PIP identification process is
described as pseudo code in Algorithm 2.
Algorithm 2 PIP Identification
Input: Time series P = (p1, p2, . . . , pm)
Output: PIP list L = (l1, l2, . . . , ln), n ≤ mSet l1 ← p1, l2 ← pmrepeat
Traverse P to identify pi with maximum distance to its adjacent points in PIP list.
Append pi to L
until Length(L) = n
To calculate the distance of the points in between two adjacent PIPs to these two points,
there are three types of distance called Perpendicular Distance (PD), Vertical Distance (VD) and
Euclidean Distance (ED) as shown intuitively in the figures below. In this algorithm we use VD
to be our measurement, let pi(xi, yi) denotes the test point, pil(xil, yil), pir(xir, yir) represent its
left-adjacent point and right-adjacent point in the current PIP list, then the measure is written as
dist(pi; pil, pir) = |yil +yir − yilxir − xil
(xi − xil)− yi| (1)
Where dist(pi; pil, pir) denotes the distance of pi to pil and pir. Through this procedure, we
identified PIPs nearly every 8 points per PIP in our note sequence Figure 2, the result is shown in
Figure 8 where PIPs are represented by ”*”.
8
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Figure 5: Perpendicular Dis-
tance
Figure 6: Vertical Distance Figure 7: Euclidean Distance
Figure 8: PIP Identification
9
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
3.2 Form Duration Array
We initialize our duration Array d to be an array of the same length as the note sequence with
default values 0. Then we take the following 4 steps to fill in d gradually according to the pattern
characteristics we discovered in section 4.1.
3.2.1 Step 1: Identify Adjacent Similar Patterns
Among all the similar patterns found by collision matrices, we pay particular attention to
those adjacent ones. When we listen to music, it’s always the consecutive repetitions that draw our
attention mostly. Here we use this intrinsic property to distribute our rhythm. For two adjacent
similar patterns with default duration sequences, we randomize one duration sequence based on the
predefined rhythm set (Figure 3) and assign its value to the other one. See Algorithm 3.
Algorithm 3 Identify Adjacent Similar Patterns
1: for all collision matrices of 3 similarity degrees do
2: Find adjacent similar patterns in every matrix, e.g. s1 and s2
3: Make sure their corresponding duration subsequences d1 and d2 are in default setting.
4: Randomize d1 according to the predefined rhythm set.
5: Set d2 ← d16: end for
7: return The newly updated duration array d.
In Algorithm 3, step 3 seems too strict. For example, if d1 is determined previously while d2
is in default value, why not assign d1 to d2? The process wasn’t set to operate this way mainly for
two reasons:
• To insure the duration of d2 is generated by the predefined rhythm set so that it can be fitinto measures. Actually d1 can be a combination of the latter part of one measure and the
former part of its next measure, which may not belong to the predefined rhythm set. What’s
worse, giving the value of such a d1 to d2 would probably cause the rhythm mess up around
d2 and its following compositions.
• It doesn’t matter if we discovered some adjacent patterns but failed to assign same durationsto them. We can apply other characteristics using methods through later steps.
We also need to point out that in this duration array formation process, once the duration of a
note is assigned, it’s locked. In other words, the operations won’t change the existing values. Only
the default values would be modified through each step until every element in d is changed from
default value.
10
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
3.2.2 Step 2: Identify Locally Distinct Motifs
As defined in Definition 3.3, we want to locate the short rhythmic patterns recurring in a com-
position. Looking into the collision matrices we got earlier, it’s instinctive to see that patterns with
higher similarity degrees and longer lengths are more distinguishable than shorter, low-similarity
sequences in a melody. Guided by this discovery, we rearrange the matrices in Table 1 as
Am, Bn, Cl, Am−1, Bn−1, Cl−1, Am−2, Bm−2, . . . (2)
We enumerate these matrices from the longest length of every degree from high to low re-
spectively and decrease the lengths sequentially. We exclude the case of pattern length 2 here as
we don’t consider the similar patterns of length 2 to be distinct. Consequently, when one of the
subscripts in (2) decreases to 3, without loss of generality, we assume it’s A3. Then the sequence
would be
Am, Bn, Cl, . . . , A3, Bn−(m−3), Cl−(m−3), Bn−(m−3)−1, Cl−(m−3)−1, . . . (3)
As the rearrangement rotates within A,B and C in decreasing subscripts, when the subscript
reaches 3, this type of matrices disappear and the rotation continues within the remaining types
until the subscripts of all 3 types of matrices decrease to 3. The method of distributing durations by
using this rearranged matrices sequence is like what we did in step 1. We randomize the duration
for one pattern and assign its value to its similar pattern given the condition that they are both at
default settings. The detailed process is described in Algorithm 4.
Algorithm 4 Identify Locally Distinct Motifs
Input: All collision matrices found by Algorithm 1 as listed in Table 1
1: Rearrange these matrices to be Am, Bn, Cl, Am−1, Bn−1, Cl−1, Am−2, Bm−2, . . .
2: for every matrix in the rearranged order do
3: for every pair of similar patterns listed in the matrix do
4: Make sure their corresponding duration subsequences d1 and d2 are in default setting.
5: Randomize d1 according to the predefined rhythm set.
6: Set d2 ← d17: end for
8: end for
9: return The newly updated duration array d.
The reason for designing Step 4 in Algorithm 4 is the same as we mentioned in Algorithm 3.
11
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
3.2.3 Step 3: Identify Globally Similar PIP Modes
Observing the PIPs found in Figure 8, we notice that the shapes determined by PIPs are
somehow repeated. In other words, we can find pairs of PIPs of similar shapes around them. In this
way, we are able to distribute durations due to the global trend led by PIPs of the note sequence.
In implementation, we first apply sign function to the difference sequence B = (b1, b2, . . . , bm−1).
When defining shapes globally, we only care about the trend – it’s increasing, decreasing or invariant.
We ignore the information about how much it changes. It’s much relaxed than the similarity degrees
we gave above. In this way, we define similar PIPs only by the similarity of its sign shapes around
them. Then we are ready to assign durations from a looser requirement and global view to the
remaining default positions.
Through the operations in Step 1 and Step 2, the duration array is filled little by little. Maybe
it’s not rigorous to phrase this way. Due to the pattern recognition process and the predefined
rhythm set, the duration distribution is actually part by part but not note by note, which also
causes the remaining notes waiting to be assigned durations gathered together – they also appear
as patterns, several notes sequentially, not scattered. To assign durations to the remaining parts
according to similar PIPs, we design two steps.
• Find Patterns of Exact Length Fitting the Vacant Space
First of all, we need to locate these remaining default subsequences. From the perspective of
these vacant subsequences, for every one, we traverse the whole sequence to find the patterns
fitting the predefined rhythm set and of the same length as this vacant part. If the pattern
found and the given part are from the same segment of similar PIP shapes, we assign the
pattern’s duration to the default part. If no pattern satisfying the above requirements exists,
it’s ok to move on to the next vacant one and leave this part waiting for the following steps
to determine its values.
In order to find the patterns fitting the predefined rhythm set, namely, the patterns need to
be able to fit into measures themselves, we introduce a concept called ”Isolated Pattern”.
Definition 3.5. (Isolated Pattern) A subsequece of duration array with default values right
ahead and after it is defined as an isolated pattern. An isolated pattern is not adjacent to
any assigned values.
The method to find patterns of exact length fitting the blank space is described in Algorithm
5. We repeat this process several times before moving to the next stage.
12
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Algorithm 5 Patterns of Exact Length
1: Find the location and length of blank space e1, e2, . . . , en in duration array d.
2: for i = 1 : n do
3: repeat
4: Continue traversing d from current location (initial location: d(1)) until we find an isolated
pattern g of same length as ei.
5: if g doesn’t exist then
6: Break;
7: else
8: Find the PIPs pi, pj closest to g and ei respectively
9: if (pi and pj are similar PIPs) & (g and ei are at the same position w.r.t. pi and pj) &
(g has at least one nonzero element) then
10: Set ei ← g11: Break;
12: else
13: Continue;
14: end if
15: end if
16: until d is traversed.
17: end for
18: return The newly updated duration array d.
The method to find patterns of exact length fitting the blank space is described in Algorithm
5. We repeat this process several times then move to the next stage.
• Find Patterns of Shorter Length Fitting the Blank Space
There is an obvious omission in Algorithm 5. If there is a huge vacant sequence, for example,
a sequence of length 13 by chance, what should we do? It’s difficult to find an isolated pattern
of length 13 so this space would probably be left empty after the last step. In order to address
this problem, we choose to insert the longest isolated pattern shorter than 13, which comes
from the same segments of similar PIPs as the vacant part, into the most suitable part of
the vacant space to complete the rhythm distribution process. The procedure is described in
Algorithm 6. We repeat this process several times as well.
13
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
Algorithm 6 Patterns of Shorter Length
1: Find the location of blank space e1, e2, . . . , en in duration array d.
2: for i = 1 : n do
3: Set l = length(ei)
4: for q = l − 1 : −1 : 2 do5: repeat
6: Continue traversing d from current location (initial location: d(1)) until we find an
isolated pattern g of length q.
7: if g doesn’t exist then
8: Break;
9: else
10: Find the PIPs pi, pj closest to g and ei respectively
11: if (pi and pj are similar PIPs) & (g and ei are at the same position w.r.t. pi and pj)
& (g has at least one nonzero element) then
12: Insert g into ei. The position of g in ei is adjusted by its relative position to the
PIP.
13: Break the loop and continue from the next iteration of Step 2.
14: else
15: Continue;
16: end if
17: end if
18: until d is traversed.
19: end for
20: end for
21: return The newly updated duration array d.
3.2.4 Step 4: Randomize Rhythm for Remaining Parts
After all of the operations through Step 1-3, now our duration array d is almost full. For the
remaining sporadic default parts R = {r1, r2, . . . , rk}, we simply randomize their durations due tothe predefined rhythm set. Here we still split the operations into two steps:
• If two elements in R are of same length and they belong to the same segments of similar PIPs,we randomize the duration of one element by the predefined rhythm set (Figure 3) then give
its value to the other element.
• After performing the last step, if there still are elements left in R not assigned, we simply ran-domize their durations according to the predefined rhythm set. Then the rhythm distribution
14
3 RHYTHM PATTERNS DISTRIBUTION An Experiment with Algorithmic Composition
procedure is finally completed.
Remark. We have mentioned that through the duration distribution process, once one value
is assigned, it’s fixed, namely whatever operations we take afterwards, this value is not viable to be
changed. This property indicates that the order of operations is vital. We need to rank all these
operations reasonably to make sure the distribution process works methodically. In general, we
follow these principles: ranking from most important to least important, from local to global, from
scarce to plentiful, from strict to loose. We analyze the reasons why we design Steps 1-4 in the given
order in Table 2.
Table 2: Analyze the Rank of Each Step
Step 1: Identify adjacent similar patterns Adjacent similar patterns are rare and signifi-
cant; This is the characteristic we want to high-
light most
Step 2: Identify locally distinct motifs These motifs are local and important; This is
a very conspicuous local characteristic in note
sequence
Step 3: Identify globally similar PIP modes These modes are more general and of looser re-
quirements; It depicts the global feature of note
sequence
Step 4: Randomize duration for remaining parts This is the final complementary part; It applies
the fewest characteristics in note sequence
3.2.5 Data Adjustment Based on Music Theory
According to some basic concepts of music theory and composition (mostly by the general rules
of classical music), we made some adjustments to the note sequence P and duration array d, to get
the whole piece start from the tonic and end on the tonic at every period. We also accelerated the
third measure and retarded the forth measure of every phrase to build the contrast of tension and
peace as well as propelling the melody to move more smoothly. The details of conducting these
adjustments are listed in Algorithm 7.
15
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
Algorithm 7 Adjustment Based on Music Theory
1: Truncate first few points of data sequence P = (p1, p2, . . . , pm) s.t. P starts from tonic. Denote
the new sequence as P̃ .
2: Apply duration array forming procedure to P̃ to get duration array d. Then we accelerate the
third measure of every phrase to build the tension and retard the forth measure of each phrase
to cause a sense of rest or ending.
3: Add one tonic note to the end of each period. This note takes up the whole ending measure of
the period and its position is determined by minimizing the distance from its previous note.
4: We get a new note sequence P ∗ and the adjusted duration array d∗.
Figure 9 shows what we got from the original note sequence (depicted in Figure 2) after the
complete rhythm patterns distribution process .
Figure 9: Melody in Treble Clef
4 Building Chord Progression
The melody part has been completed as shown in Figure 9, the next step we’d love to add
chord progressions in bass clef to accompany the treble clef harmonically. The process of forming
the desired chord progression is accomplished through three steps. We first map the music scale to
Z7 group and use 7 elements of Z7 to represent all notes in the melody and all triads and seventhchords. Next, we use combination to find out all chord sets harmonizing with the melody in each
measure, then determine the best chord progression by picking up the longest weighted path in
16
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
the chord sets tree according to the common chord progression. Finally, in order to position these
chords properly, we applied a metric derived from the principle of voice leading of common tone
approach, and we adjusted these chords to be placed within one octave from the melody line, which
completed the chord progression building process.
4.1 Triads and Seventh Chords: Cyclic Group
It can be perceived directly that the structure of octave in tonal music is isomorphic to Z7cyclic group. If we use numerals 1 ∼ 7 to replace letters A-G which represent pitches in one octave,we can write all triads and seventh chords as following:
Mapping: tonic → 1; supertonic → 2; mediant → 3; subdominant → 4; dominant → 5; submedi-ant → 6; leading tone → 7
Triads: {1, 3, 5}; {2, 4, 6}; {3, 5, 7}; {4, 6, 1}; {5, 7, 2}; {6, 1, 3}; {7, 2, 4}
Seventh chords: {1, 3, 5, 7}; {2, 4, 6, 1}; {3, 5, 7, 2}; {4, 6, 1, 3}; {5, 7, 2, 4}; {6, 1, 3, 5}; {7, 2, 4, 6}
Here we use ”set” but not ”array” because the chords can be in any order due to inversions.
As to how to position these chords, we will discuss it later in Section 6.3.
Now we use this method to mark all the notes in our adjusted note sequence P ∗. They will
be represented by 1 ∼ 7 seven elements of Z7. Besides, according to duration array d∗, we woulddivide these notes into measures and put all notes in the same measure into one set (here we don’t
merge same elements in the set). As we accelerated the third measure in each phrase as described
in Algorithm 7 Step 2, we’d love to add two chords in the third measure, so here we divide the
notes in this measure into two sets of same durations. In this example, As shown in Figure 9, the
set of numeral sets for the first period is
S = {{1, 7, 2}, {5, 5}, {3, 2}, {4, 5, 5}, {2, 6}, {5, 2, 1}, {6, 2, 4, 1}, {4, 1, 3, 2}, {7, 5}, {1}} (4)
Then we use combination to find the triads or seventh chords that match each set in S. For
si ∈ S, we program to find the largest subsets of si that equal or belong to some triads sets orseventh chords sets. For example, the first set in S is {1, 7, 2}, whose largest subset is itself, so wetraverse the sets of triads to see if there is any match. However, there is no {1, 7, 2} in triads set. Itturns out that there is no set in seventh chords that takes the set {1, 7, 2} as a subset as well. Thenwe decrease the size of subsets to 2. There are 3 subsets {1, 7}, {1, 2}, {7, 2}. We match them tothe sets of triads. There is no match for {1, 7} and {1, 2}, but for {7, 2}
{7, 2} ∈ {5, 7, 2} & {7, 2} ∈ {7, 2, 4}
17
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
As a result, the chord set for the first measure {1, 7, 2} is {{5, 7, 2}, {7, 2, 4}}. However, if weonly have {1, 2} in this measure, there is no matching triads. Now we would look out for sets inseventh chords, then we found match {2, 4, 6, 1}, which is the only set that includes elements 1 and2. Notice that we can always find a match for any 2-element sets in seventh chords, so the chord
sets corresponding to every numeral measure set in S would never be empty. Besides, according
to our adjustment before (Algorithm 7), the ending measure of each period is formed just by one
tonic tone. We set its corresponding chord to be {1, 3, 5} always. The corresponding chord sets for(4) is listed in Table 3.
Table 3: Corresponding Chord Sets
Measure Chord Sets
{1, 7, 2} {5, 7, 2}, {7, 2, 4}{5, 5} {1, 3, 5}, {3, 5, 7}, {5, 7, 2}{3, 2} {3, 5, 7, 2}{4, 5, 5} {5, 7, 2, 4}{2, 6} {2, 4, 6}{5, 2, 1} {1, 3, 5}, {5, 7, 2}{6, 2, 4, 1} {2, 4, 6, 1}{4, 1, 3, 2} {2, 4, 6, 1}, {4, 6, 1, 3}{7, 5} {3, 5, 7}, {5, 7, 2}{1} {1, 3, 5}
4.2 Common Chord Progression: Longest Weighted Tree
In music theory, there is a chart called Common Chord Progression as shown in Figure 10.
The term ”common” means most chord progressions in classical music follow the rules listed in this
chart like I → IV → V → I. Besides, I chord can move to any chords as the dashed line in Figure10 shows.
The Roman numerals here correspond to the numeral representation we developed in the last
section directly. The numeral of the root for each chord (the first element of each chord set) indicates
its Roman numeral representation. For example, the chord {1, 3, 5} corresponds to Roman numeralI. We notice that the Roman numerals are case-sensitive. The reason why they present the way
shown in Figure 10 is that this example is in E major, so chords I, IV, V are major, ii, iii, vi are
minor and viio is diminished.
In order to determine the best chord progression for the piece, we devised an algorithm using
tree structure and we turned this optimization problem into finding the longest weighted path from
18
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
Figure 10: Common Chord Progression
root to leaf in the chord sets tree. To form the chord sets tree following the rules of common chord
progression, we first set the root to a triple (I, 1, 0), which represents the Roman numeral, repeated
times and weight separately. It’s possible for a chord to repeat itself especially when there are more
than 5 notes in one measure set. As we can tell, if one chord shows up more frequently than others,
it’s supposed to fit the melody better. Besides, there are chord progressions wider-used than others.
For example, the chord progression I → IV → V → I is more popular than the progression I → iii→ vi → I. As a result, we assign different weight to different chords according to its popularity incomposition. Thus, the repeated times and weight assigned to each chord are used as indicators of
the chord’s suitability for each measure.
Back to the construction of the chord sets tree. We set the root to (I, 1, 0), which indicates
that the chord for the first measure is forced to be I, which agrees with the melody part starting
at the tonic (Algorithm 7 Step 1). Then we move to the second measure. Since chord I can go
to any chords next, we concatenate all chords in the chord sets for this measure to the root as
its child notes, with repeated times and weight computed. Next, we move to the third measure.
Here we have to examine all chords concatenated in the last step, taking them as parent nodes,
then matching them with chords in the current measure according to the common chord progression
chart (Figure 10). If the progression is displayed in the chart, we concatenate it to its corresponding
parent node; if not, we leave the parent node alone and move to the next chord. Obviously, if there
is no matching chord in the current measure to one of the parent nodes, this node would be left as
a leaf thus this branch would be abandoned. However, if there is no matching chord for all of the
parent nodes, the tree would be cut off, which means the chords for the following measures cannot
be appended to the tree. To avoid this from happening, under such situation, we would concatenate
all chords in the current chord sets to every parent node, then continue the process above until the
last measure. Applying this procedure to our example in Table 3, we get the chord sets tree for the
first period of our melody as illustrated in Figure 11.
Now we want to determine the longest weighted path from root to leaf in the chord sets tree.
Utilizing the second and third terms of the triple, namely the repeated times and weight assigned
19
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
Figure 11: Chord Progression for the First Period
20
4 BUILDING CHORD PROGRESSION An Experiment with Algorithmic Composition
to each chord, we can easily compute the total weight of each complete path covering all measures
from root to leaf. Comparing all the weights computed, we find out the ”best” chord progression
with the biggest weight for this piece.
4.3 Voice Leading of Common Tone Approach: Common Tone Distance
Since we already determined the chord progression along the bass clef, now the only thing left
is to position these chords appropriately. Although we have triads and seventh chords, considering
the practical way of playing instruments (piano for example), we would only position 3 notes for
each chord in bass clef. For the seventh chords, as the first note in treble clef of each measure would
be played simultaneously with its accompanying chord, if this note belongs to this seventh chord,
we can simply take it as a component of the chord and position the rest 3 notes in the bass clef; if
not, we eliminate the fifth of this chord and display the rest 3 notes as a chord, which is generally
considered as a way to preserve the features of seventh chords mostly.
Here I want to follow the voice leading of common tone approach in composition and devise
an algorithm to achieve this rule to the greatest extent. In order to translate this approach into
mathematical language, we give the definition of common tone distance first.
Definition 4.1. (Common Tone Distance) The distance between a note and its previous chord is
defined as the minimum distance of the note to every note of this chord.
To be more specific, we denote our note as X and its previous chord composed of 3 notes as
(A,B,C). Then the distance between this note and the 3 chord notes can be represented as a vector
(a, b, c). To aggregate the distance vector as a scalar, the most common way would be
Arithmic Mean :|a|+ |b|+ |c|
3
or
Quadratic Mean :
√a2 + b2 + c2
3
However, the common tone approach means that we want to keep one tone invariant throughout
several measures. To achieve this goal, we introduce the distance as
Common Tone Distance : min{|a|, |b|, |c|}
In this way, once there is any possibility for the note to get to the same tone as one of the
chord’s notes, the distance would automatically be 0, which achieves the optimum since we would
minimize the distances to determine the best position for this note. This strategy gives a way to
realize the voice leading of common tone approach.
21
5 MODEL EVALUATION An Experiment with Algorithmic Composition
The common tone method gives the relative position among chords. Nevertheless, we still need
to figure out chord positions in relation to the melody line. We neither want these chords too close
to the melody line to separate from each other, nor see them too far apart to be an integral whole.
Based on the chord positions given by common tone approach, we modify them to fit our demands
in the way of putting the highest pitch of each chord within one octave of the lowest pitch of its
corresponding measure of the melody. In this way, the chords company part is finally completed.
Our final result is shown in Figure 12.
5 Model Evaluation
There are some distinctive advantages of this model – the generality and variety it achieved
are quite impressive. With respect to these properties, An thorough analysis with demonstrating
examples are provided in this section. As well, there are also other pros and cons of this method.
We will cover them in the last part.
5.1 Control Variable Method
For all examples given below, we followed the control variable method to the greatest extent.
The control group is given as Figure 13. This example is another composition generated by the
pre-described process with different parameters for the double pendulum system. These control
experiments provided the best demonstration for the generality and variety of our method.
5.2 Variety: Sensitive to Initial Conditions
The notes are sampled from chaotic system, one of whose most distinct features is sensitive to
initial conditions. This indicates that with a subtle change of initial data, we are promised to get a
totally different sequence of notes, which means the system can generate infinite distinctive pieces
of melodies.
For example, we only made a change to the initial positions of the double pendulum and
kept every other parameter unchanged, going through the same procedure, a new composition was
produced as shown in Figure 14.
5.3 Generality: Highly-Adjustable System
The model is highly adjustable. The users are allowed to choose any key signature (major and
minor), any time signature and change the predefined rhythm patterns. The users can also change
22
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Figure 12: Final Piece
23
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Figure 13: Control Group
24
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Figure 14: Contrast: Change of Initial Positions
25
5 MODEL EVALUATION An Experiment with Algorithmic Composition
the weight of chord progressions according to personal preference. All these functions have added
more flexibility to the possible melodies produced by the raw data sequence.
• Key Signature
Here we give an example of a composition generated by this model in D minor (harmonic
minor), in contrast with the original example which is in E major. Other conditions would
stay the same (Figure 15).
Figure 15: Contrast: Composition in D Minor
• Generalized Rhythm Set
We can change the predefined rhythm patterns as well. As you may notice, the rhythm
set we used in the original example (Figure 3) is quite limited. There are only a few of
the rhythm combinations composers often use in practice listed in this figure and they are
pretty conservative. Here we want to generalize the predefined rhythm set by adding more
26
5 MODEL EVALUATION An Experiment with Algorithmic Composition
syncopation into it to make our composition versatile. The generalized set is shown in Figure
16.
Figure 16: Generalized Rhythm Set
Here we eliminated the 4-note patterns since we want them to be more multifarious, thus
these patterns as well as patterns with more notes are going to be produced by combinations
of the fundamental 1,2,3-note patterns. For example, patterns consisting of 4 notes can be
generated by ”1+3” or ”2+2” modes.
A composition generated under the generalized rhythm patterns is given in Figure 17. As we
can see, there is a new pattern called triplet appearing in the melody and more syncopation,
which have added the composition’s diversity.
• Time Signature
Our original example is in 2/4 time signature. Here we give an example in 3/4 (Figure 18)
produced through the same process described in this article.
5.4 Other Pros and Cons
Another advantage of the model is automation. The composition process is totally automated,
which differentiate this method from many other algorithmic composition methods which require
expert knowledge and human creativity. The system itself is capable of composing a whole piece
without human intervention. In this way, the composition produced won’t be biased by personal
style and music taste, which means this method actually has delegated all creativity to the computer.
Besides, the principles from music theory used to adjust the sequence are indeed general and
widely accepted. In other words, these adjustments only give a frame to the piece but not a certain
specific style. These modifications are necessary to make the piece integral and musical but it won’t
affect the major role played by the original sampled data.
27
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Figure 17: Contrast: Composition of Syncopation
28
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Figure 18: Contrast: 3/4 Time Signature
29
5 MODEL EVALUATION An Experiment with Algorithmic Composition
Apart from all the superiorities above, however, some of the rules applied in the algorithm
are indeed rigid and determined to some extent, such as ending every period on the tonic. These
principles are widely used but not permanent. If the computer wants to compose master pieces,
it has to be taught to break the rules and to achieve the real level of creativity, which can be
considered as one of the possible improvements to the system in the future.
30
References An Experiment with Algorithmic Composition
References
Beyls, P. (1991). Chaos and creativity: The dynamic systems approach to musical composition.
Leonardo Music Journal , 31–36.
Bidlack, R. (1992). Chaotic systems as simple (but complex) compositional algorithms. Computer
Music Journal , 16 (3), 33–47.
Castilho, P. L. (2015). Chaotic systems as compositional algorithms mus-15.
Chung, F.-L., Fu, T. C., Luk, R., & Ng, V. (2001). Flexible time series pattern matching based on
perceptually important points.
Dubnov, S., & Surges, G. (2014). Delegating creativity: Use of musical algorithms in machine
listening and composition. In Digital da vinci (pp. 127–158). Springer.
Fernández, J. D., & Vico, F. (2013). Ai methods in algorithmic composition: A comprehensive
survey. Journal of Artificial Intelligence Research, 48 , 513–582.
Fu, T.-c., Chung, F.-l., Luk, R., & Ng, C.-m. (2008). Representing financial time series based on
data point importance. Engineering Applications of Artificial Intelligence, 21 (2), 277–300.
Gogins, M. (1991). Iterated functions systems music. Computer Music Journal , 15 (1), 40–48.
Henke, J. (2011). Theory gizmos:fundamental tools to understand, analyze, and build music. Text-
book Consortia.
Herman, M. (1993). Deterministic chaos, iterative models, dynamical systems and their application
in algorithmic composition. In Proceedings of the international computer music conference
(pp. 194–194).
Pressing, J. (1988). Nonlinear maps as generators of musical design. Computer Music Journal ,
12 (2), 35–46.
Tang, H., & Liao, S. S. (2008). Discovering original motifs with different lengths from time series.
Knowledge-Based Systems , 21 (7), 666–671.
31