Fractal Music from Randomness
Well-chosen variables can make a randomized sequence of notes sound musical
Music as Data Series
"My life seemed to be a series of events and accidents. Yet when I look back, I see a pattern."
― Benoit B. Mandelbrot (1924–2010)
Motivation and Background
Music is a rich source of multi-dimensional data. This data can take the symbolic form of a score, usually represented by MIDI values, or the form of an audio signal.
For many years, I’ve used MIDI data to identify fractal structure in music. MIDI files are notorious for their inconsistent quality, stemming from both human and machine error. Datasets need to be screened for quality and cleaned to deal with missing, corrupt, or duplicate values, outliers, and sometimes global timing issues. The work draws heavily on the tools of exploratory data analysis, incorporating graphical inspection, statistical summaries, data smoothing, fitting, and critical analysis.
A question that naturally arose was whether I could, to some extent, reverse the process; that is, take a synthetic dataset of musical characteristics with a known distribution and algorithmically turn it into music, or rather, music that anyone might actually enjoy listening to.
Algorithmic music is a currently active field and the results can take many forms. While the boundaries between approaches can be blurry, popular methods for generation include aleatoric methods, evolutionary/genetic methods, Markov-based models, audio/MIDI mapping of non-musical media (e.g., images and text), and neural networks.
The idea of writing music in a manner that is, to some extent, independent of a human composer dates back to at least the time of Mozart. His Musikalisches Würfelspiel ("Musical Dice Game") is probably the best known example of applying a source of random input to the composition of music. The modern age of computer-generated and computer-assisted composition arrived in 1957 with Lejaren Hiller’s and Leonard Isaacson’s _Illiac Suite_ (see also Musica Informatica for more details). Of course, the leading edge of current efforts to algorithmically compose realistic music in a variety of styles centers on the sophistication and power of AI, as evidenced by OpenAI’s Jukebox.
Most of these existing methods attempt to either use, codify, or learn from existing musical structure. For me, the question was, how little could I do in producing musical-sounding music? Looking to nature seemed like a good place to start.
Power-laws
Here, we’ll introduce what appears to be a new approach to algorithmic composition that uses a fundamental property of fractal geometry called a power-law. Power-laws are found in an incredible array of phenomena in the natural and social sciences. Here are just a few examples:
- Biodiversity
- Circulatory systems in plants and animals
- Cotton prices
- Distribution of Galaxies
- Distribution of Wealth
- Earthquakes
- Hurricanes & floods
- Language word usage
- The measure of coastlines
- Tumor growth
- Urban systems
Power-laws can also arise in music with respect to many characteristics like pitch, interval, duration, rhythmic variation, and a form of fractal structure called motivic scaling. Motivic scaling __ made an appearance at least five centuries ago with the work of Franco-Flemish composer, Josquin des Prez.
Fractal Music
The term "fractal music" can mean different things to different people. For some, it simply means "music that came from a fractal image." However, mapping an image to musical sounds does not insure that those mapped sounds also possess fractal properties. This would be a bit like expecting a poem by Robert Frost to rhyme when translated into Cantonese.
Benoit Mandelbrot always had a strong intuition that music was measurably fractal. This is the sense in which we will use the term. Fractal geometry is, first and foremost, geometry, a subject whose name implies measurement. At minimum, music that is truly fractal must possess some measurable scaling property.
We will explore the broader subject of fractal music in future articles. Here, we will look at a property we call melodic interval scaling. It describes the distribution of the set of distances between the single notes of a melody. Melodic interval scaling can, for instance, be found in some of the compositions of Johann Sebastian Bach [1, 2, 3].
The Experiment
Here is an animation of a short composition with a solo that was generated using the algorithm described below:
<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FvewF_bVH-6w%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DvewF_bVH-6w&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FvewF_bVH-6w%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" title="Animation of the fractal composition "Brecker 8."" height="480" width="854">
You can get an intuitive sense of the interval scaling by looking at the distribution of the vertical spacings between solo notes. Overall, there are lots of small jumps and fewer medium-sized jumps. These are all punctuated by very few large jumps. This relationship between count and size can be accurately described by a power-law.
A Bit of the Math
Consider a heterogeneous series of melodic intervals of different sizes, {_s₁ **** , s₂ , s₃ , …}. We count the number of intervals of each size {_N₁ , _ N₂ ,_ N₃ , …}, where Nₖ corresponds to the number of intervals of size sₖ. The sequence possess melodic interval scaling if, when we graph a log-log plot of N against s, the points fall along a straight line. The slope of that line can be interpreted as the dimension d of the set of elements – in this case, intervals. This is because taking the log of a power-law relation transforms it into a linear equation:
If we let y=Log[N] and x=Log[1/s], then what we have is the equation of a line, y=mx+b, where d=m and b=0. For a rigorous description of this type of analysis and its application to the Bach Cellos Suites, see [1].
The Algorithm
What this all means is that we can:
- Choose a dimension and a range of interval sizes.
- Using the formula above, calculate how many of each size interval we need to fulfill the power law we defined with our choice of dimension.
- Create a distribution of intervals based on this calculation, wherein half of the intervals of each size are positive and the other half, negative.
- Randomly sort this distribution to insure heterogeneity.
- Accumulate the resulting sequence of intervals to produce our melody.
Here is pseudocode for steps 1 through 3:
// Assignments:
2^(-1/12) ← sizeRatio
dimension ← fractal dimension of set /* dimension > 0 */
scalingRange ← number of levels of scaling in set /* scalingRange ≥ 3 */
largeCount ← number of the largest elements in set
// Implementation:
countRatio := Exp[dimension*Log[1/sizeRatio]]
sizes := Table[1/ratio^k, (k, 1, scalingRange)]
counts :=
Table[largeCount*countRatio^(k-1), (k, scalingRange, 1, -1)] /* k counts down from scalingRange to 1 */
data := Log[Transpose[sizes, counts]]
Fit[data, (1, x), x] /* perform linear regression, if desired, to confirm dimension */
melodicIntervalSet := Join[data,-1*data]
We’ll assume that steps 4 and 5 are familiar operations in the language of your choice. When reducing the above algorithm to practice, it is also necessary to address boundary issues for cases when the accumulated sum of intervals exceeds the standard MIDI range (0 to 127).
Warning: the melodies generated from this process can get very weird. However, with appropriate parameters and the right context, the results can be surprisingly musical.
For the above composition, Brecker 8, here is the distribution of intervals where the size of each interval is equal to 2^(k/12) for an interval of k semitones:
The value 2^(k/12) comes from the physics of the equal temperament scale commonly used in Western music. Here are plots of the data:
While this example arose from focusing on the effects of varying the dimension of a set of melodic intervals, other power-laws (e.g., related to duration or dynamics) can also be algorithmically incorporated to give a more human feel (see [4] for an example).
What I find particularly compelling about this piece is the idea that a random process can create something that, nonetheless, "makes sense" as a result of the underlying distribution of elements it acts on and the context in which it appears. At least in music, randomness needn’t sound so random.
References
[1] Intervallic Scaling in the Bach Cello Suites [2] Fractal Geometry of Music [3] Mandel-Bach Journey: A Marriage of Musical and Visual Fractals [4] 100 Seconds of Pi
Thank you for reading! If you enjoyed this piece, please consider following me and hitting the "Applause" icon at the top as many times as you’d like. You can also subscribe to get my latest content straight to your inbox. I write weekly on fun topics in math, music, and science.
Related Articles
John Coltrane’s Giant Steps Solo: Fractal Geometry in Action
Share This Article
Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.
Write for TDS