Minimal Fitness Functions in Genetic Algorithms for the Composition of Piano Music
Total Page:16
File Type:pdf, Size:1020Kb
ICMC 2015 – Sept. 25 - Oct. 1, 2015 – CEMI, University of North Texas Minimal Fitness Functions in Genetic Algorithms for the Composition of Piano Music Rodney Waschka II North Carolina State University [email protected] ABSTRACT Perhaps the most significant problem facing anyone em- A general strategy for creating extremely simple but effec- ploying genetic algorithms for music is the determination tive fitness functions in genetic algorithms is described. of an appropriate fitness function. Two major factors cause Called “minimal fitness functions”, these fitness functions the fitness function to become a point of high tension in the are designed to 1) consist of the smallest amount of infor- creation of a genetic algorithm for music composition. mation or restrictions possible, 2) avoid the “fitness bot- First, it is usually the case that the fitness function serves tleneck” problem, 3) be “aesthetically neutral”, and 4) be as the main method for determination of the musical con- musically useful. A summary of the general background in tent of a piece made with genetic algorithms. Second, even music for this work on fitness functions is provided, the when composing intuitively -- in the “old-fashioned way” - rationale and strategy of minimal fitness functions are set - it is often incredibly difficult for a composer to determine forth, and then specific examples of this type of fitness what constitutes a good reason to incorporate or omit some function are presented. Finally, examples of the musical note, phrase, sound, or group of sounds into or from a results generated by these minimal functions to help com- composition. Explaining the reasons for such inclusions or pose piano music are provided. While the examples show omissions is not necessarily easier after the piece has been the results in the composition of piano music, this work completed. In other words, the composer faces the problem indicates that the use of minimal fitness functions is not of developing an appropriate fitness function when she or limited to the writing of piano music and other kinds of he may not be able to imagine or sometimes even recog- pieces made using these minimal techniques are cited. nize an appropriate solution. Consequently, it can be extremely time consuming and 1. INTRODUCTION problematic to try to develop a set of rules encoded in a fitness function for the composition of a new work. This Genetic algorithms are used in attempts to solve a variety most troublesome aspect of composing with genetic algo- of problems across a range of disciplines. Implementations rithms -- creating an efficient and effective fitness function of these algorithms in music have been cited in Biles [1], -- has been described by Biles [1] as the “fitness bottle- Miranda and Biles [2], Waschka [3], Klügel et al [4], and neck.” It has been discussed by Waschka [3], Klügel et al Ando [5]. These algorithms model some of the basic as- [4], and Cho [6]. pects of natural selection. Genetic algorithms employ an initial (digitally represented) population of “individuals” -- 2. BACKGROUND AND PROBLEM potential (insufficient) solutions -- a fitness function, and a set of “breeding” rules including crossover and mutation. The author has utilized genetic algorithms to help compose The process brings together pairs or groups of parents to music in the past. For this study, most of the attributes of “breed” resulting in a new generation. That new generation previously used genetic algorithms remained in place. A is subjected to the same process, as are the succeeding single measure of music constitutes an individual, usually generations. Typically, given an appropriate initial popula- there is only one “breakpoint” or point of crossover, and tion and fitness function, a solution or group of solutions mutations vary from a single set mutation used in every will emerge after much iteration. case to mutations chosen intuitively by the composer on a case-by-case basis. In addition, rather than iterating nu- merous times in order to determine a single measure, each Copyright © 2015 Rodney Waschka II. This is an open-access article generation created is included in the piece and heard. distributed under the terms of the Creative Commons Attribution License This exploration attempted to determine if it is possible 3.0 Unported, which permits unrestricted use, distribution, and to use extremely simple fitness functions that specify the reproduction in any medium, provided the original author and source are minimal amount of restriction to create compelling con- credited. temporary art music. The goal was to develop fitness func- – 408 – ICMC 2015 – Sept. 25 - Oct. 1, 2015 – CEMI, University of North Texas tions that 1) could be stated in one sentence and imple- ing two constraints. The other five clearly make use of a mented with few lines of code, 2) were aesthetically neu- single constraint. Two of the seven minimal fitness func- tral, 3) were musically useful, and 4) developed results that tions (for pieces 2 and 5) relate specifically to piano play- were computationally efficient and did not require either ing. re-workings of the function or other types of intervention. These minimal fitness functions do not push the pieces in any particular aesthetic direction. Only two of the func- 3. FITNESS FUNCTION DEVELOPMENT tions implicate pitch choice in any way (the fitness func- tions for pieces 3 and 7). Of much greater impact in terms The fitness functions described here were used in the crea- of the musical aesthetics of the pieces are other factors. tion of a set of seven piano pieces, the Enigmatic Sonatas These include: [7]. Each piece is separately named. The resulting set of 1) the decision to use genetic algorithms in the first pieces is, in some ways, similar to the sonatas of Domenico place, Scarlatti, [8] which served as one of the inspirations for 2) the decision to implement the algorithm in such a these works. The pieces may be played singly, in groups of way that each generation is part of the piece and is heard, less than seven in any order, or, all seven may be played in 3) the decision to make the initial population not only a a different order, or all seven may be played in the order bank of individuals from which the breeding parents of the given. Each piece has the same form – initial population, a next generation would be drawn, but to also have that ini- set number of generations created by the algorithm, and tial population played as the beginning of the piece, and then a repeat of the initial population. Each of the pieces 4) the actual composition or choice of the initial popu- contains the same number of measures. The fitness func- lation, which, as previously mentioned, in this case often tions developed were, in some cases, general, and could featured tonal centers of some kind. easily be applied to the composition of other types of Most of the individual/measures within an initial popula- pieces. Others were quite specific to the piano and not nec- tion would fulfill the fitness function. essarily applicable to other instruments or ensembles. Various functions were tried. Only those that worked and 4. OTHER ASPECTS OF THE GENETIC succeeded in producing pieces of some interest are de- scribed here. ALGORITHM It should be noted that the initial populations for these Some of the other aspects of these genetic algorithms are pieces often contained, or were based on, tonal material usual, such as the use of a two-parent model, while other including folk songs. Using this kind of material has the aspects are potentially less typical. advantage, in many instances, of making it easier to follow the alteration of the material brought on by the genetic al- 4.1 Breeding gorithm. The algorithms used in these pieces featured a two-parent model and a single crossover point randomly determined. 3.1 The Seven Fitness Functions The individuals in the initial population were not differen- The fitness functions for each of the pieces consisted of tiated in any way or split into groups. Any individ- a constraint that could be stated in one sentence. The fit- ual/measure from the initial population or succeeding gen- ness functions for each piece is given below: erations could serve as parent one or parent two and could Piece 1: The individual must contain a rest or a tuplet. function as parent one in one instance and parent two in Piece 2: The individual must have notes played by the another. An individual could also breed with itself, which left hand of the pianist. would, of course, result in an exact replication. Piece 3: The individual must contain an accidental. As implied by the statement above, some individuals Piece 4: The individual must not contain any half notes. would breed more than once while other individuals in the Piece 5: The individual must have notes played by the initial and subsequent populations who met the fitness right hand of the pianist. function requirements would not breed. A random selec- Piece 6: The individual must contain at least one six- tion from those individuals that met the fitness function teenth note. requirements was made. Consequently, as in life, some Piece 7: The individual must not contain any A-flats or genetic material was stripped away by the fitness function, G-flats in the melody. while other material was lost or emphasized due to chance. 4.2 Mutation 3.2 Notes on the Functions In the genetic algorithm for each of the seven pieces there Of the seven different fitness functions, only two contained existed the possibility of mutation. There were multiple the word “or” and could, therefore, be considered as hav- ways this could happen.