A Musical Learning Algorithm
A Musical Learning Algorithm
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
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-
Cope 13
(a) (d)
A~
(b) (e)
(c)
-4?-
. o9oo
.9-o o ~
(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
(4)
C.F.
failed note
note removed
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
? (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)
(b) (e)
(c) ()
? (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))
Cope 19
C.F.
c.I."o
WB mm- I
(a) (b)
Sdead end
cont.
Figure 10
(c)
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-
(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
Cope 21
(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.
C.F.
17
f2 f2 1 9 1 r I I "
Cope 23
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
k34-
oJI
Cope 25
(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
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