100% found this document useful (1 vote)
82 views17 pages

A Musical Learning Algorithm

Artículo acerca de la generación de un algoritmo mediante el cual un programa de computador es capaza de componer música en un estilo definido.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
82 views17 pages

A Musical Learning Algorithm

Artículo acerca de la generación de un algoritmo mediante el cual un programa de computador es capaza de componer música en un estilo definido.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

A Musical Learning Algorithm

Author(s): David Cope


Source: Computer Music Journal , Autumn, 2004, Vol. 28, No. 3 (Autumn, 2004), pp. 12-
27
Published by: The MIT Press

Stable URL: https://www.jstor.org/stable/3681506

JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide
range of content in a trusted digital archive. We use information technology and tools to increase productivity and
facilitate new forms of scholarship. For more information about JSTOR, please contact [email protected].

Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at
https://about.jstor.org/terms

The MIT Press is collaborating with JSTOR to digitize, preserve and extend access to Computer
Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
David Cope
University of California at Santa Cruz
A Musical Learning
Music Center, 242
University of California Algorithm
1156 High Street
Santa Cruz, CA 95064 U.S.A.
[email protected]

In this article I describe a computer program called study, instruction, or experience" (Costello 1991,
Gradus (after Johann Joseph Fux's 1725 treatise p. 772). Few computer programs actually learn, al-
Gradus ad Parnassum) that initially analyzes a set though the word "learn" is often freely used when
of model two-voice, one-against-one, first-species describing programs such as spelling checkers and
counterpoints in order to produce a series of com- Internet search engines. The program I present in
positional goals. Gradus then attempts to compose this article actually changes its behavior by modi-
goal-correct counterpoints similar to the models fying its own approaches to solving musical prob-
using a given fixed voice called a cantus firmus. lems, becoming faster and more accurate over time.
Initial notes for the new lines of these counter-
This program also chooses its own originating
points are drawn from pre-compositional seed notes and produces specific and generic rules that
notes, the choice of which are optimized by con- can be instructive for teaching users themselves to
sulting the program's previously saved successful create better results when working with two-voice,
compositions.
one-against-one, species counterpoint.
The article then describes how Gradus, in order
Although significant research in machine learn-
to compose more quickly and mistake-free, back-
ing has taken place in the artificial intelligence
tracks from the "dead ends" it encounters, catalogs
community (see for example Mackintosh 1983;
the conditions that led to these dead ends as rules,
Michalski 1986; Mitchell 1997; Cherkassky 1998;
and avoids these conditions on subsequent runs
Hinton and Sejnowski 1999; Baldi 2001; Cesa-
with the same cantus firmus until backtracking is
no longer necessary. Gradus then uses the rules it
Bianchi, Numao, and Reischuk 2002), very little
collects when encountering new cantus firmi, ap- similar research has taken place in the field of mu-
plying its accumulated experiences to increase thesic. Gerhard Widmer's work (Widmer 1992; 1993)
chances that it will succeed. Ultimately, the pro- stands out among the few published examples of
gram learns to compose first-species counterpoint computational learning in music. In his 1992 arti-
quickly, accurately, and without any need for back-cle, Mr. Widmer argues the need for true learning
tracking. I have based the processes used in Gradus programs in music and that music requires domain
on those that I use when learning or re-learning specificity. The program he describes involves user
species counterpoint. interaction to achieve its results, which are im-
This article includes a brief discussion of musical pressive because the program then alters itself to
inference and a description of how the learning pro- reduce backtracking. William Schottstaedt's coun-
cesses described may be seen as computationallyterpoint program (1989) creates effective output in
inferring solutions to basic musical problems. The all five species but without any learning involved.
article then concludes with more elaborate exam- Cruz-Alcizar's and Vidal-Ruiz's work with gram-
matical inference (GI) algorithms (1997) holds po-
ples created by the program, including a fugue ex-
position and counterpoint in a more dissonant, tential but primarily applies to monophonic rather
non-triadic style. than polyphonic music.
David Evan Jones's CPA program (2000) provides
Background an effective contrapuntal toolbox for composers but
Webster's College Dictionary defines "learning" centers
as almost entirely on atonal music. H6rnel
and Menzel (1998) use feed-forward neural net-
the ability "to acquire knowledge of or skill in by
works in their work, with learning accomplished
through adjustment of nodal weights. However,
Computer Music Journal, 28:3, pp. 12-27, Fall 2004 learning with neural networks often requires exten-
C 2004 Massachusetts Institute of Technology. sive training and elaborate complementary algo-

12 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
rithmic programming (see Miranda 2001, pp. 99- point known as two-voice, one-against-one, first-
118). Other important work in the area of musical species counterpoint for the purposes of this
learning has been accomplished; however, the pau- demonstration. This is the type of counterpoint
city of publications remains clear. with which students usually begin and for which,
David Lewin's goal-oriented approach to species I feel, the rules are most programmable. I will de-
counterpoint (1983) clearly enhances one's ability scribe extensions of this software beyond its two-
to compose first-species counterpoint. However, voice, one-against-one limitations later in this
this approach provides shortcuts that attempt to article.
avoid the dead ends that rules cause rather than in- Gradus uses six goal categories. Although these
corporating true learning processes. There are many do not conform exactly to those of Fux and even
such shortcuts to creating counterpoint. For exam-omit certain details which many counterpoint in-
ple, in my book Experiments in Musical Intelli- structors find important (climax, mode adherence,
gence (Cope 1996, p. 213), I describe an approach cadence,
to and so on) or further limit Fux's con-
creating algorithmic fugues that involves "subtrac-straints (as in leaps of thirds only), most of Fux's
tive counterpoint," a technique that voids much of general rules appear here in one form or another:
the need to backtrack. Again, however, such short-
cuts do little to achieve learning, and hence I do 1. Simultaneously sounding notes must be
not discuss them here. consonant, forming intervals such as thirds,
fifths, sixths, octaves, and so on
The need exists therefore for music programs in-
volving machine learning to produce effective tools
2. Voice motion must be stepwise (i.e., no re-
for composers and to provide a better understand-
peated notes) with occasional leaps of thirds
always followed by stepwise contrary mo-
ing of the ways in which humans learn musically.
tion
The program described here is available from my
Web site at arts.ucsc.edu/faculty/cope and will run
3. No simultaneous leaps in both voices are
allowed
on any platform and requires only a version of the
4. Parallel fifths and octaves must be avoided
computer language Common Lisp.
5. Hidden fifths and octaves must be avoided
6. No more than two continuous same-
direction motions are allowed
The Goals
The more models used, the more accurately Gra-
Species counterpoint poses particular composing dus sets its goals. Therefore, I have chosen 50 two-
problems that have challenged students for centu- part, one-against-one completed counterpoints to
ries. A single fixed line (called the cantus firmus) serve as models of music for Gradus to analyze.
combines with a variable number of simulta- Each of these counterpoints incorporates the above
neously sounding new lines that must adhere togoals. a Figure 1 shows several of the 50 models from
strict set of musical goals. Often, new lines lead towhich the program-in its default state-sets its
dead ends for which no correct choice is possible.goals. In essence, Gradus assumes that all of the
Beginning students often restart only to find them- vertical intervals, parallel motions, skip numbers,
selves in the same or similar predicaments. Many and so on found in the models are allowable and
months of practice are typically required for even places the vertical intervals, parallel motions, skip
highly intelligent students to become facile at cre- numbers, and so on it does not find-presumed to
ating these new lines without backtracking. Al- be illegal-in appropriate variables to serve as pro-
though other kinds of music (such as canons, gram goals. If the number of models to be used for
fugues, serial constructions, and so on) can cause goal analysis changes between runs of Gradus, the
similar conflicts and thus serve as interesting prob-program can re-analyze the models, and users may
lems for computer programs to solve, I have chosen re-set the corresponding goal's variable for further
a rather straightforward type of species counter- composition.

Cope 13

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 1. Five of the 50 models upon
which the Gradus program bases its
analysis of goals for creating good
counterpoint.

(a) (d)

A~

(b) (e)

(c)

-4?-
. o9oo

.9-o o ~

As can be To make the best possiblethe


seen, seed-note choice,go
Gra-
tory rather dus saves than
its successful outputs with their generat-
exem
of what not to do rather than what to do-a more ing seed notes and uses the seed notes of these
standard approach to programming. Figure 2 pro- successful lines to create new accompanying lines.
vides musical examples for each of the six goals To provide as broad a match for the comparison
listed above as exemplified in the 50 models pro-process, Gradus also saves cantus firmus templates.
vided with the Gradus program. These goals helpTemplates (like rules discussed later) are measured
the two voices remain in consonant relationship in terms of diatonic steps rather than by exact in-
and to retain their relative independence, which aretervals; in other words, the upward interval of a
important features of both 16th- and 18th-century second equates to the number 1, the upward inter-
contrapuntal composition. val of a third to the number 2, and so on, with neg-
The Gradus program requires a seed note to be- ative numbers referring to downward motion. A
gin its composition of a new accompanying line template
to takes the form of the number of vertical
the cantus firmus. This seed note acts as an origin diatonic steps between the seed note and the begin-
ning pitch of the cantus firmus, followed by a re-
for selecting a first note. Because composing a first
note from this seed note follows the previously pre-duced, diatonic-step map of the cantus firmus, as in
sented goals, the seed note generates a number of the following:
possibilities (four to be exact, as we will shortly
(-4 (5 0))
see) from which the program chooses a logical ini-
tial pitch using stepwise motions and interval-of-a- The first number here (-4) represents the
third leaps only. Some seed notes will project of diatonic steps between the seed note (no
several likely correct candidates, whereas other first note of the successful accompanying
seed notes will project only one possible logical the first note of the cantus firmus. The lis
choice, a choice that occasionally may later prove lows this first number indicates respective
incapable of creating a completed counterpoint. number of diatonic steps between the note
Therefore, selecting a good seed note is important moved (high or low) and the beginning not
for the composing process. cantus firmus, and the number of diatonic

14 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 U76 12:34:56 UTC
All use subject to https://about.jstor.org/terms
Figure 2. The program goals in musi-
cal notation where (a)-(f) relate to
goals 1-6, respectively.

(a) (d)
not not or

(b) (e)
A not or not

(c) (f)
not not

Z) en0 A

tween the last note of the cantus firmus in and the 3. Gradus initially chooses one of these
Figure
first note of the cantus firmus. In the above
notes case,
randomly, which means that different results
the cantus firmus rises to a maximum five may diatonic
occur each time the program is run, depending
steps above the first note and ends with onthewhether
same the note chosen follows the program's
goals. Gradus also requires a scale for diatonic to-
note as it began. With several of these successful
cantus firmus templates saved in a globalnal pitch selection, the default of which is the
variable,
C-major scale, which allows the program to only
the Gradus program can select the most similar
map to the cantus firmus being used and select
then notes
pro-in the key of the provided cantus firmi
ject the appropriate seed note. This process helps
(also in C major). Gradus is not currently designed
to compose
the program avoid false starts. If there are two (-4 in other keys or use atonal scales and
(5 0)) templates stored but only one (-5 (5cantus
0)) tem-firmi. However, only a relatively few small
changes
plate stored, the program will select the (-4 in a number of variables would be required
(5 0))
template, because it has obviously proved morethis kind of variation possible.
to make
successful. The Gradus program thus usesThe previous
centerpiece of the Gradus program is its
experience to infer future choices. goal-testing cycle. This cycle contains the hoops
through which a successful choice must pass: verti-
cal consonance, avoidance of parallel fifths and oc-
The Process taves, leaps followed by contrary motion steps, no
simultaneous leaps in both octaves, avoidance of
Gradus uses one of the cantus firmi included with direct fifths and octaves, and three or fewer consec-
the program or one provided by the user. Cantus utive and legal parallel-direction motions. The pro-
firmi should follow the goals mentioned in the pre-gram looks ahead for its best choice by projecting
vious section. Failing to use a cantus firmus that forward one pitch from the currently chosen pitch.
follows these goals can make it impossible to com-Comparing the results of this projection with the
pose an appropriate accompanying line or prevent current rules (soon to be discussed) enables the pro-
the program from behaving as described. The de- gram to avoid choosing a pitch that will conflict
with the goals, which requires backtracking. Gra-
fault cantus firmus and all of the other cantus firmi
provided with Gradus follow the first-species goals dus then selects another pitch if the current choice
of the models provided with the program. creates a conflict. If no correct possibility among
As just mentioned, Gradus can move only step- those available exists, then the program creates and
wise or leap a third up or down. Consequently, saves a new rule and backtracks to find a different
only four notes can be projected from a seed note, solution. I will discuss this process in more detail
and each successive note in the new line as shown momentarily.

Cope 15

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 3. The four possible first-note
choices for the seed note A.

choices to avoid repeating the same mistake. If one


or more of the four possibilities does survive the
tests, then the program looks ahead with a kind of
approximation. This approximation takes into ac-
count the next cantus firmus note but with a wild-
Rules in the Gradus program consist of three or card matching anything, and it compares this
fewer motions and appear as follows: projection with the currently constituted rules. If a
rule prevents all of the possible four projected new-
(-2 (1 1) (-1 1))
line notes from occurring, then the program
A rule consists of three parts: (1) the number
chooses another ofpitch from those currently avail-
vertical diatonic steps between the first able.affected
The balance between inline tests and looking
note of the cantus firmus and the new ahead to see(2)
line; if athe
rule exists to block a future move
number of diatonic steps between theisaffected precarious, but it ensures that back-tracking will
notes of the cantus firmus itself; andonly (3) occur
the num-
at times requiring new-rules creation
ber of diatonic steps between the related notes
and that ofeffort will be kept to a minimum.
wasted
the new line. The vertical difference isFigure necessary
4 shows graphically how this process
because there may be diatonic step distances works. In this be-representation, the program has cor-
tween the associated first notes of the two lines rectly completed all of the whole notes in the bass
where the combination of voice motions will work clef up to and including the E, the third note from
correctly. For example, the counterpoint A-B-C/ the end. Because this E resulted from a leap down-
F-E-F separated by an octave resulting in a rule of ward, the program must-according to the goals-
(-2 (1 1)(-1 1)) is incorrect due to parallel fifths. move stepwise in the opposite direction. Doing so,
However, the counterpoint A-B-C/A-G-A in the however, creates a dissonant tritone relation with
same register-equivalent to the rule (-7 (1 1) the B, the second note from the end in the cantus
(-1 1))-is correct, but it would match the rule of firmus, causing an error (represented by the black
(-2 (1 1)(-1 1)) if the vertical separation were not triangle note). The program, therefore, creates a
present to differentiate the two patterns. Voice mo- rule to cover this situation, backs up one note, sub-
tions alone simply do not provide enough informa- tracts the E from the possibilities available for a
tion to be useful as rules. Using vertical distancesthird note from the end, and chooses a more suc-
and voice motions as rules also avoids the need to cessful A (shown as a black square note). The pro-
have rules that duplicate one another when diaton- gram then continues to negotiate the remainder of
ically transposed. For example, the pitch rules the counterpoint successfully. In future attempts to
C-D-E/A-G-A and E-F-G/C-B-C in the same register compose with this cantus firmus, the program will
are diatonically identical when transposed, butlook ahead and, upon encountering G as fourth
both would be necessary in a pitch-notated rulesnote from the end, will see that selecting E pro-
system, whereas the single diatonic-step rule of duces (-2 a problem with the necessary F and will thus
(1 1)(-1 1)) includes both of them as well as all choose A as third note from the end to avoid back-
other similar transpositions. tracking.
Composing in Gradus follows a straightforward The look-ahead process in the Gradus program
process. At every point in choosing a new note, involves
the creating a rule on the fly-without adding
program produces a set of four possible notes from it to the database-using an extension of the can-
which it can choose, seconds or thirds up or down tus firmus by one note beyond the current state of
from the current note. These four notes are tested the new line along with the proposed new note, as
using the previously described goals. If none of the well as a wildcard that will match anything found
four possibilities survives the tests, then the pro- in the rules. The temporary rule of (-9 (1 -1 -1)(-1
gram backs up one note and begins again, this time -2 nil)), which is equivalent to C-D-C-B/A-G-E-?
with the offending note-the last note of the new (fifth note from the end of Figure 4 and onward)
line composed thus far-removed from the possible where the last E represents the proposed new note

16 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 4. The Gradus backtracking Figure 5. Backtracking to create new
process. rules to avoid future backtracking.

(4)
C.F.

new choice and completion

failed note

note removed

(5) try 3 try 2 try 1


C.F.

and entirely.
the This new rule is kept in a separate vari-
"
of able-in fact a temporary variable, since with
such an an-
(-1 other cantus firmus this1))
-2 correct choice may in fact
lead to further correct choices. This process of cre-t
example
the ating rules for otherwise correct choices and stor-
progr
note. ing them in temporary
Beca locations is extremely
resentimportant to the Gradus program's de learning pro-
intervals substituted for the interval shown also cesses.

create problems), the match correctly causes the Figure 5 demonstrates how this pr
program to choose another note for the one causingEach of the rectangles here represen
the problem. Hence, the look-ahead process avoidscan be seen in this instance, the pr
dead ends before they can occur. rules up to the beginning of the com
When the look-ahead function finds a rule pro- the result that the note A will be avoided in all
hibiting the program from choosing a note, Gradussubsequent runs of the program with this cantus
makes another note choice from those that pass thefirmus. In detail here, try 1 is foiled because the
previously discussed tests. Often, however, there program has leapt to the last B in the lower voice,
are no more notes to choose from, and the program forcing a stepwise opposite direction C, which, if
must then backtrack. This may seem like wastedcreated, would produce parallel octaves. In try 2,
effort, as we have not reduced backtracking using the result of the program's looking ahead and dis-
this method. To solve this, the look-ahead function covering the problem with try 1, no other correct
creates a new rule that prohibits the up-to-this- possibilities exist for the new line except the B, and
point correct note that led to the incorrect choice. thus it too fails. Try 3 does not work because no
This ensures that when this situation is encoun- other choice exists here aside from the shown
tered again with this cantus firmus, the program fourth-note D.
will choose another note (if possible) to avoid the Figure 6 shows a typical set of Gradus program
collision ahead. This creation of rules prohibiting a without any backtracking. The program iden-
runs
correct choice may continue until it prohibits onetifies each attempt to extend the new line with the
of the possible correct notes projected from the output text "working.. ." followed on the next
seed note. This new rule, unlike normal rules be- line by the current state of the composition of the
cause it disallows a pattern that by itself is per- accompanying line in relation to the cantus firmus.
fectly correct, helps to eliminate backtracking Final output is presented in event-list format with

Cope 17

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 6. A typical set of runs with- Figure 7. The results of Figure 6 in Figure 8. Six outputs from the Gra-
out any backtracking. standard musical notation. dus program showing different sec-
ond lines to the same cantus firmus.

? (gradus) A
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2)) i n
working .....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2))
working..... Figure 7
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2))
working ....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2 c3))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2 c3 d3))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2 c3 d3 c3))
((0 69 1000 1 90)(0 57 1000 2 90)(1000 71 1000 1 90)(1000 55 1000 2 90)
(2000 72 1000 1 90) (2000 57 1000 2 90) (3000 76 1000 1 90)
(3000 55 1000 2 90) (4000 74 1000 1 90) (4000 59 1000 2 90)
(5000 72 1000 1 90) (5000 57 1000 2 90) (6000 74 1000 1 90)
(6000 59 1000 2 90) (7000 72 1000 1 90) (7000 60 1000 2 90)
(8000 71 1000 1 90) (8000 62 1000 2 90) (9000 69 1000 1 90)
(9000 60 1000 2 90))

Figure 6

(a) (d)

C.F." l00 C.F. ..L

(b) (e)

(c) ()

18 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 9. A typical set of runs with
backtracking.

? (gradus)
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 e2))
backtracking.....there are now
1
rules.

working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 f2))
backtracking.....there are now
2
rules.

working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 b2 c3))
working ....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 g2 a3 c3))
backtracking.....there are now
3
rules.
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 g2 a3 b3))
working.....
((a3 b3 c4 e4 d4 c4 d4 c4 b3 a3) (a2 g2 a2 g2 b2 a2 g2 a3 b3 d3))
((0 69 1000 1 90)(0 57 1000 2 90)(1000 71 1000 1 90)(1000 55 1000 2 90)
(2000 72 1000 1 90) (2000 57 1000 2 90) (3000 76 1000 1 90)
(3000 55 1000 2 90) (4000 74 1000 1 90) (4000 59 1000 2 90)
(5000 72 1000 1 90) (5000 57 1000 2 90) (6000 74 1000 1 90)
(6000 55 1000 2 90) (7000 72 1000 1 90) (7000 57 1000 2 90)
(8000 71 1000 1 90) (8000 59 1000 2 90) (9000 69 1000 1 90)
(9000 62 1000 2 90))

each element in each list referring to (1) runtime


more than onein correct possible new not
thousands of a second; (2) pitch (with
gram middle
can setC the same cantus firmus in
equaling 60, C-sharp above that beingways.61,Figure
etc.); (3)
8 shows six such settings t
duration in thousands of a second; (4) channel
firmus of (1 for 7. Although each of th
Figure
the cantus firmus and 2 for the newly created
follows the line);
program's goals slightly diff
and finally (5) loudness (0-127). Note that the
results up- similar, as will be the c
are quite
per voice appears in channel 1 and ever
the lower voice
the seed note remains constant for
in channel 2 and that the two voices cantus
are spliced
firmus.to- However, the slight mod
gether here-they alternate by event-in order
resulting fromto different note choices o
make performance easier. Figure 7 shows
furtherthechanges,
re- creating different vers
sults of Figure 6 in musical notation.companying lines.
As mentioned earlier, because there often
Figureexists
9 shows a typical set of program

Cope 19

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 10. The results of Figure 9 in Figure 11. (a) A dead-ended passageFigure 12. Rules are initially created
musical notation. requiring backtracking. The dead by backtracking, but once created,
end causes Gradus to produce (b) a they plateau in number with back-
new passage and (c) a new rule. tracking no longer necessary.

C.F.
c.I."o
WB mm- I
(a) (b)
Sdead end

cont.

Figure 10
(c)

(-4 (1) (-2))

Figure 11
using default cantus firmus of '(69 71 72 76 74 72 74 72 71 69)

(23444567777778888888888888888888888

888888888888888888888888888888888888

88888888888888888888888888888)

Figure 12

include backtracking. Here the text "backtracking called one hundred successive times without hand-
... there are now 3 rules" clearly delineates the resetting the rules variable; in other words, the
process for the user. Figure 10 shows the results of rules here accumulate rather than reinitiate with
Figure 9 in musical notation; Figure 11 then illus- each new function call.
trates how the dead ends appearing in Figure 9 Using two short, transposed-from-one-another
occur. Figure 1 la presents an example of a dead end cantus firmi in multiple runs demonstrates the ef-
requiring backtracking. Figures 1 lb-c show the fectiveness of rules in the learning process and of
new rule resulting from the backtracking in musi- using diatonic steps in rules rather than actual note
cal and numerical notations. In Figure 1 la (equiva- names. For example, running the program with the
lent to the dead end-creating rule 1 of Figure 9), the upwards-stepping A-B-C-D-E as cantus firmus with
music dead ends because each of the four possibili- middle C as seed note 50 times produces three
ties cause conflicts with one or more of the pro- backtracks and three rules. Running the program
gram's goals. Leaping upward to a D creates both a then with F-G-A-B-C as a cantus firmus, a simple
double leap and dissonance with the C in the can- transposition a third down, with A (an interval of a
tus firmus. Moving upward stepwise to a C creates third below middle C) as the seed note, produces
parallel octaves. Moving downward to an A does no new rules and no backtracking.
not resolve the downward leap in the new line by Figure 13 shows the contents of the rules vari-
stepwise opposite motion as required by the pro- able in both rule format and in musical notation af-
gram's goals. Leaping downward to G causes the ter the runs shown in Figure 12 were conducted. As
same conflict. Thus Gradus has no option but to can be seen, particularly in their musical versions,
backtrack and, in this case, because composition is each rule is context-specific but at the same time
so near the beginning, start again from a new pitch. not tied to a particular cantus firmus. Rules of
The results of the tests shown in Figure 12 show fewer than four elements (the norm for rules) result
how rules increase in number by backtracking. from their occurring at the beginning of a counter-
However, rule numbers quickly plateau with back- point. (For example, compare the upper lines of
tracking no longer necessary. Each of the entries in rules 3 and 7 to the upper-line cantus firmus open-
these lists represents the length of the rules vari- ing in Figure 9.) Note that each rule actually ends
able (*rules*) following one additional run of the with the error that caused the backtracking. Note
Gradus program. In this case, the program was also that Gradus does not reduce the diatonic step-

20 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 13. The contents of the
*rules* variable in both (a) rule
format and in (b) musical notation.

(a)

((-12 (1 -1 -1) (-1 2 -1)) (-11 (2 -1 -1) (-1 2 -2)) (-4 (1) (2)) (-9
(1 -1 -1) (-1 -2 1))
(-9 (-1 1 -1) (-1 -2 1)) (-9 (-1 -1 -1) (1 2 -1)) (-4 (1 1) (-2 -1))
(-7 (1 1 2) (-1 -2 1)))

(b)

1 2 3 4

5 6 7 8

6 n o o -e e o oo 0
l&, " "0

wiserequire more verti


or fewer new rules than shown here.
cause occa
In addition, choosing different seed notes-users
produce may override the program's choice-may result in c
posed different numbers of newby rules from those given
duce here. Sooner corre
or later, however, the program will
problems). find all the rules it requires to appropriately accom-
The tests of 50 calls each to the Gradus program pany almost any goal-correct cantus firmus to
shown in Figure 14 immediately followed the runs which the user wishes a second line.
shown in Figure 12, without clearing the rules vari-
able and therefore using the rules created by differ-
ent cantus firmi. As can be seen here, the first new User Interaction
cantus firmus requires only two more rules than
the eight already created by the runs in Figure 12. The most frequent user interaction with the Gra-
The second run in Figure 14 requires two more dus program involves changing the cantus firmus
new rules as well. The third new cantus firmus, by redefining the * cantus-firmus* variable. As
however, requires no new rules at all. In essence, mentioned earlier, one should not create cantus
the program has "learned" how to compose two- firmi that themselves stray from the goals, because
voice, one-against-one counterpoint-at least it has doing so can produce unsolvable problems to which
learned those rules required to create appropriate the program may find itself in an infinite loop. As
accompanying lines to the cantus firmus shown an example, the difference between the cantus
here.
firmus
I have chosen these particular cantus firmi be-
cause they resemble one another somewhat and (72 71 69 67 72 67 71 72 74 76)
therefore suggest that fewer new rules will be nec- and
essary to create new logical counterpoints. Running
the program with very different cantus firmi may (72 71 69 71 69 72 71 72)

Cope 21

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 14. Using rules created by the
cantus firmus of Figure 12 to help
produce a second line to new cantus
firmi, which then require less back-
tracking.

using '(69 71 69 72 71 74 72 71 69) added only 2 rules

(9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
scratch. A knowledge of Lisp will obviously pro-
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
vide users with many more ways to interact and to
10 10) follow Gradus. However, even with access to the
minimal number of variables given above, users
using '(69 71 72 76 74 72 71 72 74 72) added only 2 rules
(10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 can observe the "learning" processes the program
11 11 11 11 11
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12)
uses.

using '(69 71 72 71 72 74 72) added no rules at all


((12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
12 12 12 12 12
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12)
Inference

I describe several forms of musical inference in


is relatively small. However, because the first can-
my book The Algorithmic Composer (Cope 2000).
tus firmus contains more than two motions in the
Of interest here is my definition of inference as "an
same direction, double leaps, leaps not followed by
ability to extrapolate basic principles from exam-
contrary stepwise motion, and so on, it will cause
ples" (p. 67; see also McCorduck 1979; Anderson
excess backtracking. Usually, if the problems are
1964; Charniak and McDermott 1985). While cen-
few in number, the program will still successfully
tering on set theory as the primary basis for infer-
negotiate the learning process. If the differences are
ence in my book, I also discuss a form of tonal
great, however, Gradus may lapse into backtrack-
inference (see pp. 73-79) using voice leading as a
ing loops for which the only escape is to abort the
core. Although an extension of the program I de-
program. This is particularly truescribe
forhere cantus
could usefirmi
the same manner of inference
that contain repeated notes. To keep the code rela-
as the program I discuss in The Algorithmic Com-
tively small and readable, I have not accounted for
poser, Gradus is too small in its current incarna-
these anomalies. However, simply keeping the can-
tion to incorporate that program's inferential
tus firmus within the stated goals of the program
techniques.
nullifies any chance that such problems
Interestingly,will
however,occur.
Gradus uses rule-making
Gradus can create its own cantus firmus by sim-
and look-ahead processes that, by their very nature,
ply using one of its own counterpoint solutions
are inferential. For example, although rules 1, 2, 4,
transposed up one octave, thus eliminating
5, 6, 7, and 8 in Figurethe13 are context-specific, the
need for a user-supplied cantus firmus. However,
look-ahead process will consider them universal.
because a provided cantus firmus As is such,
typically
the programcon-will disallow any leap up a
sidered a part of the musical puzzle
thirdfor which
in a new a so-to a cantus firmus
line it composes
lution is desired, eliminating thisthat
user-supplied
simultaneously contains a downward scale of
element seems unnecessary. Ultimately,
notes beginningthe pro-above (as between
two octaves
gram functions only with a set of examples
notes 2 through 4 ofupon
Figure 13bl), because that
which to base its own creations, aclearly
situation
requires an not un-
incorrect diatonic stepwise
like that facing human composers. In fact,
downward motionas I
to follow it creating parallel
mentioned earlier, Gradus composes counterpoint
fifths. Contextually, when D is determined as a
in much the same way that I, as anew composer, com- line to the cantus fir-
note of an accompanying
pose counterpoint, particularly when attempting
mus as in Figure 13bl, an F toas a following note is
solve problems created by working within
eliminated duringexplicit
the look-ahead process. In es-
constraints. sence, the program infers that there are no correct
Rules are stored in the rules variable and may possibilities
be with the choice of F as a third note (in
accessed at any time when using the program. Set- this instance, as well as all other equivalent in-
ting the rules variable to nil (see the documenta-stances). Importantly, the program does not then
tion accompanying the code to Gradus for more disqualify the D as the second note of the counter-
information on this and other alterable variables)point, because that note could be correctly fol-
allows users to reset the program to begin from lowed by the note E.

22 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 15. A simple first-species
canon created by five lines of added
code.

C.F.

17

f2 f2 1 9 1 r I I "

Extensibility two-voice canon created by Gradus's create-canon


function. Note that the simple code for producing
this canon does not account for the seams between
As an example of extensions possib
dus program, I have repetitions of the theme. Here, these seams
included with are ac- t
a simple canon-maker function ceptable. However, using other cantus firmi mayalo
ple cantus firmus. produce repeated
Canons, notes or double leaps
at at the inter-
least
sections between the theme repetitions. This prob-
octave as is the case here, require
lem could easily be avoided with the addition of
additional ingredients beyond the b
further code that I omitted in an effort to make the
first-species counterpoint: invertab
transition from simple one-against-one counter-
repetition. Invertability can be achi
point to more formalistic canons as clear as possible.
the perfect fifth to the invalid vert
I should note here that this canon program in no
because perfect fifths invert to inva
way extends the learning capabilities of the Gradus
fourths during imitation at the oct
program. The program continues to create and use
sixths, and octaves-the only rema
only the rules that enable it to compose better first-
vals-invert to correct intervals when inverted at
species non-canon counterpoint. However, the
the octave and thus remain acceptable. Adding above-mentioned
the problems (encountering
perfect fifth to the invalid vertical interval list cre-
impossible-to-accompany cantus firmi and poor
ates an added constraint that then makes manyseams between theme entries) could themselves be-
cantus firmi impossible to accompany with a sec- come learning processes. For example, one could
ond line. Therefore, cantus firmi must be chosencode the seams of canons as part of an extended
carefully when creating canons so as not to forceone-against-one counterpoint-unlike the simplis-
dead ends that no amount of backtracking can tic manner in which I have strung them together
amend. here-with added rules accounting for the desired
Figure 15 presents an example of a first-species seamlessness.

Cope 23

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 16. The beginning of the first
of 48 fugues and the accompanying
48 preludes from The Well-
Programmed Clavier.

i9 R l F 7
ATM

The Gradus program is domain-specific and will basic imitative structure-repetition of the subject
currently function only within the boundaries I at the interval of a fifth, tonal versus real answers,
have defined. However, with minimal program- and so on-was not learned (it was built into the
ming, the program could be adapted to second-, code, as was the canon function just described),
third-, fourth-, and fifth-species counterpoint as most of the basic counterpoint resulted from ana-
well as to counterpoint in more than two voices. lyzed goals learned by self-created rules. As with
From the resulting four-voice, fifth-species counter-the version of Gradus described previously, the pro-
point code, little change would be required for the gram that created this fugue did not contain any
program to "learn" to compose Bach-like four-voicecode relating to consonance, dissonance, or voice
chorales. Creating more elaborate canons (at inter- leading, but rather it determined the detail of these
vals other than the octave for example) and fugue- goals from the models provided to the program.
like contrapuntal forms should also be possible by The three-voice texture and instrumental coun-
adapting the code. Because most composers use terpoint style presented in Figure 16 require altered
rules of some kind (set theory, serial constructions, versions of the goal types presented previously as
and so on) that at least occasionally collide to pro- well as new goal types added to cover the triadic
duce cul-de-sacs, the program would seem a naturalimplications of the thicker texture. In short, the
fit for a variety of machine-learning musical situa- program requires two extensions not discussed thus
tions. far: (1) the ability to detect goals in fifth-species
As an example, the entire four-voice fugue (of ("florid") counterpoint; and (2) the capability to
which only the opening three-voice texture appears compose two new voices in a three-voice texture.
in Figure 16) was created by a program different For the most part, these extensions involve expand-
from, but not dissimilar to, Gradus. Whereas the ing the numbers and types of goal variables so that

24 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 17. The cantus firmus used to
create the fugue shown in Figure 16.

k34-
oJI

the programfirst-speciescan collect a


appropriate lier. to expandedSuffice i
ularies. In a processes-go
few cases, the
required the throughaddition back of s
the formalisms takes inherent elimina
tending existinging-follow lines, repa
will be seen its
shortly. allusions
Figure 17 showsthe first
the of
sing 4
Gradus usedpreludes to create fro th
16. This 2002).
template contains
fugue theme To show
in the flexibility of Gradus and to demon-
different
expected in strate
a thatfugue
the program is not limited to traditional
(mm.
structions concepts of consonance and dissonance
require nor to his-
Gradus
counterpoint torical models
in of counterpoint
measurealone, I here include 4
end of the three models (see Figure 18) with fifths, seconds,
subject's first
also includes and sevenths
instructions
acting as consistent vertical intervals
counter-subject in
instead of fifths, thirds, and transp
sixths. As can be seen
the subject appears
in the output in Figure 19, the result of again
the pro-
different register.
gram's learning new goals, Gradus incorporates
Space the
detailed rules of the new models without the need
description in for revis-
th
between the ing existing
creation code. Although contemporary of compos- t
voice ers may not use rules so rigorously
composition here nor as simply as
an

Cope 25

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
Figure 18. Three models that feature Figure 19. Output from Gradus using
open fifths, seconds, and sevenths the three models of Figure 17.
acting as consistent vertical inter-
vals.

(a)
C.F.al

C.F.

(b)
Because my w
C.F. going research
gence, a projec
modeling of c
9 o o o
word about th
and its poten
(c)
tional composi
C.oF.
my book The
telligence as b
sociation, and
create its obje
911

towards those
point with sel
these, slowly decreas m
point tracking is in no
isms are conscious or not. I do not feel,
The Gradus program and ideas presented here, First al- of all, th
though simple, indicate a number of interesting importantif pre
not important conclusions. For example, the notion The Algorithm
that machine learning in music is not only possible ous shortcom
but attainable using fairly rudimentary techniques its own proble
can have significant consequences. Such an obser- tions of probl
vation may in itself not seem particularly impor- in Gradus, how
tant were it not for the fact that so little other work in this a
evidence exists in terms of the published literature. might better
Because a "learning" algorithm can be imple- learning, crea
mented with so few lines of code and with such ba- Whatever the
sic concepts, one can further imagine that Gradus progra
extending this code to include more sophisticated these kinds of
musical problems would require less than heroic the least, reve
efforts. Whether such extensions would be simple which humans
tools for composing, orchestration, and so on, or proaches to m
composing programs that create new works in means for imp
their entirety remains to be seen. However, the po- also believe th
tential clearly exists within Gradus for a diversity cepts presente
of applications. The Gradus program's current abil- for learning in
ity to learn and to generalize its discoveries in sical situation
ways that improve its ability to succeed in its in- I invite readers to download and use the Gradus
tended purpose, however limited, can lay the foun-program code and see and hear the ways in which
dation for more elegant applications to come. the program increases its skills in creating simple

26 Computer Music Journal

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms
counterpoints. The program is quite small, easy to Fux, J. J. 1725. Gradus ad Parnassum, trans. A. Mann
use, and includes a simple guide to aid even those (Steps to Parnassus, The Study of Counterpoint, New
with minimal computer skills in taking advantage York: Norton, 1943).
Hinton, G., and T. J. Sejnowski, eds. 1999. Unsupervised
of the processes it offers.
Learning: Foundations of Neural Computation. Cam-
bridge, Massachusetts: MIT Press.
Hcrnel, D., and W. Menzel. 1998. "Learning Musical
References
Structure and Style with Neural Networks." Com-
puter Music Journal 22(4):44-62.
Anderson, A. R., ed. 1964. Minds and Machines. Engle- Jones, D. E. 2000. "Composer's Assistant for Atonal
wood Cliffs, New Jersey: Prentice-Hall. Counterpoint." Computer Music Journal 24(4):33-43.
Baldi, P. 2001. Bioinformatics: The Machine Learning Lewin, D. 1983. "An Interesting Global Rule for Species
Approach. Cambridge, Massachusetts: MIT Press. Counterpoint," In Theory Only 6(6):19-44.
Cesa-Bianchi, N., M. Numao, and R. Reischuk, eds. Mackintosh, N. 1983. Conditioning and Associative
2002. Algorithmic Learning Theory: 13th Interna- Learning. New York: Oxford University Press.
tional Conference. New York: Springer Verlag. McCorduck, P. 1979. Machines Who Think. San Fran-
Charniak, E., and D. McDermott. 1985. Introduction to cisco: Morgan Kaufmann.
Artificial Intelligence. Reading, Massachusetts: Michalski, R. 1986. Machine Learning: An Artificial
Addison-Wesley. Intelligence Approach. San Francisco: Morgan Kauf-
Cherkassky, V. S. 1998. Learning from Data: Concepts, mann.

Theory, and Methods. New York: Wiley. Miranda, E. R. 2001. Composing Music
Cope, D. 1996. Experiments in Musical Intelligence. Boston, Massachusetts: Focal Press.
Madison, Wisconsin: A-R Editions. Mitchell, T. 1997. Machine Learning. N
Cope, D. 2000. The Algorithmic Composer. Madison, McGraw-Hill.
Wisconsin: A-R Editions. Schottstaedt, W. 1989. "Automatic Counterpoint." In
Cope, D. 2002. The Well-Programmed Clavier (after J. S.M. Mathews and J. Pierce, eds. Current Directions in
Bach). Paris: Spectrum Press. Computer Music Research. Cambridge, Massachusetts
Cope, D. 2003. "Computer Analysis of Musical Allu- MIT Press, pp. 199-214.
sions." Computer Music Journal 27(1):11-28. Widmer, G. 1992. "The Importance of Basic Musical
Costello, R. B., ed. 1991. Webster's College Dictionary.Knowledge for Effective Learning." In M. Balaban,
New York: Random House. K. Ebcioglu, and 0. Laske, eds. Understanding Music
Cruz-Alcazar, E., and E. Vidal-Ruiz. 1997. "A Study of with AI. Cambridge, Massachusetts: MIT Press,
Grammatical Inference Algorithms in Automatic Mu- pp. 490-507.
sic Composition and Music Style Recognition." Pro-Widmer, G. 1993. "Understanding and Learning Musical
ceedings of the 1997 Workshop on Automata Expression." Proceedings of the 1993 International
Induction, Grammatical Inference, and Language Ac-Computer Music Conference. San Francisco: Interna-
quisition (n. p., n.d.). tional Computer Music Association, pp. 268-275.

Cope 27

This content downloaded from


132.174.254.12 on Mon, 11 Apr 2022 16:33:09 UTC
All use subject to https://about.jstor.org/terms

You might also like