Measuring musical beauty through mathematical patterns

The notion of beauty has long captivated philosophers and artists alike. Webster’s New World Dictionary (1981) describes it as “the quality attributed to whatever pleases or satisfies the senses or mind, as by line, color, form, texture, proportion, rhythmic motion, tone, etc., or by behavior, attitude, etc.” For computers, which operate on quantitative representations, modeling something as subjective as beauty poses a real challenge. Personal taste — shaped by culture, education, and physiology — seems to make the problem even harder. Yet evidence suggests that aesthetically gratifying music may follow a consistent statistical fingerprint.

Where Zipf meets music

Musicologists broadly agree that music carries meaning. Some researchers try to understand this meaning by breaking it into separate, discrete sounds. Others look for meaning in how listeners group stimuli into patterns and study their hierarchical organization. Meyer (1956) argued that emotional states in music — sadness, anger, happiness — are defined by statistical parameters such as dynamic level, register, speed, and continuity. These parameters vary locally within a piece but stay relatively stable across the whole work.

In his landmark book, Zipf (1949) explored how language behaves in art and how meaning travels between creators and audiences. He showed that phenomena emerging from complex social or natural systems — including socially sanctioned art — tend to follow a predictable statistical structure. When you plot word frequencies in a book like Homer’s Iliad against their rank on a logarithmic scale, you get a straight line with a slope near –1.0. A handful of words (like “a” and “the”) appear very often, while most words appear rarely. Formally, the frequency of the nth-ranked word is 1/na, where a is close to 1.

Related laws surfaced independently in the work of Pareto, Lotka, and Benford. These principles later inspired Benoit Mandelbrot, who extended them to cover a wider range of natural phenomena. In this broader view, slopes can range from 0 (pure randomness) to negative infinity (total monotony). These distributions are also called power-law distributions.

Zipf distributions appear everywhere — in human languages, computer languages, operating system calls, colors in images, city sizes, incomes, music, earthquake magnitudes, sediment layers, species extinctions, traffic jams, and website visits.

Work in fractals and chaos theory suggests that both natural and artificial objects we find pleasing follow hidden rules that limit how their parts can be assembled. Voss and Clarke proposed that music, too, behaves like a complex system whose structure is partly subconscious to the composer — and that listeners may rely on similar subconscious rules when they respond aesthetically.

Zipf’s law in musical compositions

Zipf himself gave early examples of his distribution operating in music. Working by hand, before computers, he looked at the length of intervals between repeated notes and the count of melodic intervals. His examples included Mozart’s Bassoon Concerto in Bb, Chopin’s Etude in F minor (Op. 25, No. 2), Irving Berlin’s “Doing What Comes Naturally,” and Jerome Kern’s “Who.”

Later, Voss and Clarke ran a large-scale study on music from classical, jazz, blues, and rock radio stations recorded continuously over 24 hours. They measured several fluctuating physical variables, such as the output voltage of an audio amplifier, loudness fluctuations, and pitch fluctuations. They discovered that both pitch and loudness fluctuations follow Zipf’s distribution.

Voss and Clarke also wrote a computer program that generated music from a Zipf-distribution noise source (also called 1/f or pink noise). The results were striking. As they wrote:

The music obtained by this method was judged by most listeners to be much more pleasing than that obtained using either a white noise source (which produced music that was ‘too random’) or a 1/f² noise source (which produced music that was ‘too correlated’). Indeed the sophistication of this ‘1/f music’ (which was ‘just right’) extends far beyond what one might expect from such a simple algorithm, suggesting that a ‘1/f noise’ (perhaps that in nerve membranes?) may have an essential role in the creative process.

Zipf-based metrics for evolving music

We built a set of Zipf-based metrics designed to capture and describe balance along several musical dimensions. These dimensions include pitch, rests, duration, harmonic intervals, melodic intervals, chords, movements, volume, timbre, tempo, and dynamics. Some can stand alone (for example, pitch). Others work only in combination (for example, duration). Some attributes are easy to derive metrics from (melodic intervals), while others are trickier (timbre). We selected these attributes because they (a) have been used in earlier research, (b) have traditionally expressed musical expression and creativity, or (c) appear commonly in compositional analysis — and they are all standard topics in music theory and composition. This list is not exhaustive.

We automated several of these metrics in Visual Basic and C++, which allowed us to test our hypothesis quickly on hundreds of MIDI‑encoded musical pieces. Here is a short description of the principal metrics:

  • Pitch: The relative balance of pitch of musical events in a piece (128 possible MIDI pitches).
  • Pitch mod 12: The relative balance of pitches across the 12‑note chromatic scale.
  • Duration: The relative balance of event durations independent of pitch.
  • Pitch & duration: The relative balance of combined pitch/duration events.
  • Melodic intervals: The balance of melodic intervals (originally investigated by Zipf).
  • Harmonic intervals: The balance of harmonic intervals (also investigated by Zipf).
  • Harmonic bigrams: The balance of specific pairs of harmonic intervals — capturing chord structures.
  • Melodic bigrams: The balance of specific pairs of melodic intervals — reflecting melodic structure and arpeggiated chords.
  • Melodic trigrams: The balance of specific triplets of melodic intervals — also capturing melodic structure.
  • Higher‑order melodic intervals: Because melodic intervals track pitch changes over time, we also examined changes of that change, and so on. This hierarchy behaves like mathematical derivatives. Even if listeners cannot consciously hear such high‑order changes, some subconscious processing may occur.

Putting the metrics to the test

To evaluate these Zipf metrics, we assembled a corpus of high‑quality MIDI renderings. For comparison we also included pieces generated from DNA sequences and random compositions (both white and pink noise). Most of the classical‑piece MIDI renderings came from the Classical Archives.

The final corpus contained 220 MIDI pieces. The works broken down by genre and composer included:

  • Baroque: Bach, Buxtehude, Corelli, Handel, Purcell, Telemann, Vivaldi — 38 pieces
  • Classical: Beethoven, Haydn, Mozart — 18 pieces
  • Early Romantic: Hummel, Rossini, Schubert — 14 pieces
  • Romantic: Chopin, Mendelssohn, Tarrega, Verdi, Wagner — 29 pieces
  • Late Romantic: Mussorgsky, Saint‑Saëns, Tchaikovsky — 13 pieces
  • Post Romantic: Dvořák, Rimsky‑Korsakov — 13 pieces
  • Modern Romantic: Rachmaninov — 2 pieces
  • Impressionist: Ravel — 1 piece
  • Twelve‑tone: Berg, Schönberg, Webern — 15 pieces
  • Jazz: Parker, Corea, Porter, Gillespie, Reinhardt, Ellington, Coltrane, Davis, Rollins, Monk — 33 pieces
  • Rock: Black Sabbath, Led Zeppelin, Nirvana — 12 pieces
  • Pop: The Beatles, Bee Gees, Madonna, The Mamas & the Papas, Jackson, Spice Girls — 18 pieces
  • Punk: The Ramones — 3 pieces
  • DNA music: Actual and simulated DNA sequences encoded into MIDI — 12 pieces
  • Random (white noise): Composed by a uniform random‑number generator for pitches, start times, durations — 6 pieces
  • Random (pink noise): Composed by a random‑number generator that produced a Zipf distribution for pitches, start times, durations — 6 pieces

A surprise from our study: once a piece showed a Zipfian distribution for a low‑order metric, higher‑order metrics also tended to exhibit those same distributions. However, the higher‑order slopes drifted toward zero (high entropy, or purely random). This suggests that the balance introduced at a certain level of assembly may affect perceived structure at many remove levels — a finding that, if generalizable, carries significant philosophical weight.

What the data reveal

Each metric yields two numbers per piece: Slope, the trendline slope of the data (ranging from 0, meaning high entropy, to –∞, meaning monotone; slopes near –1.0 signifying a proper Zipf distribution), and R, measuring how tightly the trendline fits the data (0.0 = extremely poor fit, 1.0 = perfect fit; we considered R > 0.7 as a good fit).

Every well-known piece in our corpus showed multiple Zipf distributions. Random pieces (white noise) and DNA pieces exhibited few or none. Table 1 summarizes average results by genre for slope, R, and their standard deviations.

Across all musical pieces (excluding DNA, pink, and white noise), the average slope registered –1.2004 with an average R of 0.8213 — a very near‑Zipf profile. Further statistical exploration of these numbers revealed patterns across genres. Initially we produced side‑by‑side boxplots of each metric organized by genre, with number codes: 1 = Baroque, 2 = Classical, 3 = Early Romantic, 4 = Romantic, 5 = Late Romantic, 6 = Post Romantic, 7 = Modern Romantic, 9 = Twelve‑tone, 10 = Jazz, 11 = Hard rock, 12 = Pop, 13 = Punk, 14 = DNA, 15 = Pink noise, 16 = White noise. While boxplots are not formal inference tools, they reveal clear visual differences among genres. Genres 14 (DNA) and 16 (random music with uniformly distributed pitch) stood apart noticeably in the pitch metric. The first seven genres (Baroque through the romantic offshoots) overlapped substantially across all metrics — not surprising, given they are often lumped together as “classical music.” Closer inspection suggested it might still be possible to pinpoint distinct styles and individual composers by combining several metrics.

We then performed ANOVAs to test whether the various metrics gave significantly different averages across genres. All p‑values were significant, indicating genuine differences between genres in our corpus. Confidence interval graphs — shown for the harmonic interval metric in Figure 1 — more clearly distinguish genres. When intervals overlap, the corresponding genres’ means may not be statistically different; when they do not overlap, a statistically significant difference appears.

From this analysis, twelve‑tone and DNA both differ significantly from other genres. In pitch, Late Romantic differs noticeably from Hard Rock and Pop. In the pitch‑mod‑12 metric, several genres differ significantly from Jazz. On duration, Jazz and Baroque diverge. Jazz also stands apart from most other genres in pitch & duration.

More intriguing patterns emerged. Twelve‑tone music, for example, produced slopes close to uniform distribution on the pitch‑mod‑12 metric — an average slope of –0.3168 (SD 0.1801). Schönberg’s pieces alone averaged –0.2801, comparable to random (white‑noise) pieces (–0.1535). This metric reliably identifies twelve‑tone music. For comparison, the next closest average slope among musical genres was Jazz (–0.8770), followed by Late Romantic (–1.0741).

Table 1. Average results across metrics for each genre

Genre — Slope — R — Slope Std — R Std

Baroque — –1.1784 — 0.8114 — 0.2688 — 0.0679 Classical — –1.2639 — 0.8357 — 0.1915 — 0.0526 Early Romantic — –1.3299 — 0.8215 — 0.2006 — 0.0551 Romantic — –1.2107 — 0.8168 — 0.2951 — 0.0609 Late Romantic — –1.1892 — 0.8443 — 0.2613 — 0.0667 Post Romantic — –1.2387 — 0.8295 — 0.1577 — 0.0550 Modern Romantic — –1.3528 — 0.8594 — 0.0818 — 0.0294 Impressionist — –0.9186 — 0.8372 — N/A — N/A Twelve‑Tone — –0.8193 — 0.7887 — 0.2461 — 0.0964 Jazz — –1.0510 — 0.7864 — 0.2119 — 0.0796 Rock — –1.2780 — 0.8168 — 0.2967 — 0.0844 Pop — –1.2689 — 0.8194 — 0.2441 — 0.0645 Punk Rock — –1.5288 — 0.8356 — 0.5719 — 0.0954 DNA — –0.7126 — 0.7158 — 0.2657 — 0.1617 Random (Pink) — –0.8714 — 0.8264 — 0.3077 — 0.0852 Random (White) — –0.4430 — 0.6297 — 0.2036 — 0.1184

All together, these findings indicate that Zipf‑style distributions form what might be necessary but not sufficient conditions for aesthetically satisfying music. This project was sparked by how the Zipf‑Mandelbrot law identifies “naturally occurring” phenomena in diverse domains — phenomena with a natural feel. Unsurprisingly, then, we keep running into this correlation between pleasant music and Zipf distributions.

Blending metrics into composite scores

These results suggest that aesthetically pleasing features in music can be algorithmically identified — and classified. By combining individual metrics into a weighted composite (incorporating measures across the full measurable aesthetic space), classification tasks become possible. We have experimented with composites that use (a) various weights on the individual metrics and (b) conditional combinations of component metrics.

We are testing several neural‑network configurations for different classification jobs. In one experiment, a multilayer perceptron (built using the Stuttgart Neural Network Simulator) tried to see if Zipf metrics stored enough information for authorship attribution. Our data covered two sets: Bach pieces BWV500 through BWV599 and Beethoven sonatas 1 through 32. When shown a piece it had never seen before, the trained network identified the correct composer with 95% accuracy. We think this rate could rise even higher with a more refined training set — or by folding in the fractal metrics discussed below.

Composite metrics, implemented through neural network classifiers, could be employed to identify pieces that share similar aesthetic characteristics with a given composition. These composite measures may also help generate a statistical signature (identifier) for a musical work. Such an identifier could prove particularly valuable in data retrieval applications, where one searches for different performances of a specific piece across large volumes of music. During an earlier study [8], for instance, a mislabeled MIDI file was discovered because it had identical Pitch-mod-12 slope and R² values with another MIDI file. The two files contained different performances of Bach’s Toccata and Fugue in D minor.

Fractal Metrics

The Zipf metrics described so far show considerable promise. However, they suffer from a notable weakness: they only measure the global balance of a piece. Consider the sample in figure 2.a, whose pitch metric is perfectly Zipfian (slope = –1.0, R² = 1.0). Yet locally, this sample is extremely monotonous. This problem can be straightforwardly addressed using a fractal method of measurement. The metric is applied recursively at different levels of resolution: we measure the entire sample, split it into two equal phrases and measure each of those, then split the sample into four equal phrases, and continue this process. For example, at resolution 2 (the sample in figure 2.b), the slope of the left side is negative infinity (monotone), while the right side has a slope of –0.585. Dividing the sample into two parts quickly exposed this lack of local balance.

Preliminary tests with music corpora suggest that aesthetically pleasing music exhibits Zipf distributions at multiple levels of resolution. Depending on the piece, this characteristic persists until the resolution reaches a small number of measures. In Bach’s Two-Part Invention No. 13 in A minor (BWV.784), for instance, this balance holds until a resolution of three measures per subdivision.

Preliminary results indicate that, similar to simple Zipf metrics, aesthetically pleasing music displays several fractal dimensions near 1, in contrast to aesthetically displeasing music or non-music. For example, the pitch fractal dimension for Bach’s Two-Part Invention in A minor is 0.9678. These results are preliminary, but we believe these fractal metrics will prove considerably more powerful than simple metrics for ANN-based classification purposes.

Evolutionary Music Framework

We have demonstrated that Zipf-based metrics can capture aspects of the economy present in socially sanctioned music. This ability should prove highly useful in computer-assisted composition systems. Such systems are built using various AI frameworks, including formal grammars, probabilistic automata, chaos and fractals, neural networks, and genetic algorithms [2], [3], [14].

We are currently evaluating the potential of Zipf-based metrics for guiding evolutionary experiments. Based on results so far, we believe that fitness functions built on Zipf metrics should generate musical samples resembling socially sanctioned (aesthetically pleasing) music. Since Zipf distributions appear to be a necessary but not sufficient condition for aesthetically pleasing music, such fitness functions could at least serve as an automatic filtering mechanism to eliminate unpromising musical samples.

Genotype Operations

Our system is loosely based on Machado’s NEvAr system [7], a powerful framework for evolutionary visual art composition. In our adaptation, a phenotype is a music score, and a genotype is represented as a tree. Leaf nodes are musical phrases, while non-leaf nodes are operators that, when interpreted, generate a phenotype (see figure 3). Genotype operators such as +, –, and * are related to, but not entirely analogous with, their mathematical definitions. The following overview describes low-level genotype operators; we use “element” to refer to an arbitrary genotype sub-tree.

- + (addition) takes two elements, A and B, and returns the union of both, preserving their respective start times, end times, and pitches. - (subtraction) takes two elements, A and B, and returns the set of notes in B that are NOT enveloped by A. - & (concatenation) takes two elements, A and B, and appends B to the end of A. - \* (multiplication) takes two elements, A and B, and replaces each occurrence of B with a complete repetition of A, transposed from A’s starting note to B. Each repetition is appended to the last.

These low-level operations are used to evolve themes. Once a theme has been evolved, higher-level operations are applied to develop other aspects of the notes, phrases, and the piece as a whole. These operations include standard compositional devices such as retrograde, diminution, augmentation, inversion, imitation, harmonization, temporal quantization, harmonic quantization, and transposition.

We also include genetic operators for evolving sub-trees, specifically mutate (sub-tree mutation) and fit (sub-tree evaluation). These allow for introducing improvised phrases within larger compositions. We maintain control over the probabilities and complexity restrictions for when these operations occur. If an operation is more common in the first few tree levels than the last few within a given genre, this fact can be used to weight the corresponding operation’s probabilities across the various generation levels.

In the NEvAr system, elements consist of collections of pixels forming a two-dimensional image. Expressions are evaluated pixel by pixel, and results serve as arguments for the next operation in the expression tree. Any sub-tree can be mutated in one of five ways: (1) swapping arbitrary sub-trees; (2) replacing arbitrary sub-trees with randomly created ones; (3) inserting a randomly created node at a random insertion point; (4) deleting a randomly selected node; and (5) randomly selecting and changing an operator [7]. These sub-tree mutations could be valuable in music, since, unlike most visual art, music is defined almost entirely by abstract layers built upon each other: notes to phrases, phrases to melody, melody to sections, and sections to piece. Because this approach mirrors the actual composition process, these operations should at least produce something resembling a standard musical piece in structure.

The critical question remains: “To what degree should certain operations occur, and where?” If the answer is “anywhere, anytime,” far more non-standard compositions will be created than if the answer is based on music theory or probability (depending on the genre being emulated). Though a fitness test (a human evaluator in NEvAr’s case) typically decides which generations survive, a valid fitness test for musical beauty is nearly impossible to formulate, as the goal is fundamentally hard to articulate. A better solution lies somewhere between these extremes, applying weightings and restrictions to the generation process (for both elemental and sub-tree operations) and a fitness test that at least

discards generations that are not minimally “musical.” Generations produced would more likely be of a structured type, yet less structured generations could still pass the fitness test. Among possible fitness measures, combined Zipf metrics are strong candidates, since they depend not on musical tastes or theory rules but on the abstract notion that balance begets beauty.

Conclusion

We have demonstrated the potential of using the Zipf-Mandelbrot law to measure balance, and to some degree pleasantness, in musical pieces by applying it to various musical attributes including pitch, duration, and note distances. Results from ANN experiments indicate that a neural network can distinguish pieces based on their Zipf metrics, and therefore can serve, in whole or in part, as a fitness test for each generation. Using a neural network for this test could also constrain the generation process to produce specific types of music—such as Classical, Jazz, etc.—or pieces similar to particular composers.

We also discussed creating musical pieces through an evolutionary framework using genetic operations similar to those in the NEvAr system. This approach enables structured music generation with or without human interaction. Though this system might produce music statistically similar to socially sanctioned music, it remains unclear whether the result will be truly aesthetically pleasing. Therefore, this tool could minimally assist a human composer by enforcing minimal conditions for aesthetically pleasing music, thereby producing rough musical sketches for inspiration and further refinement.

Acknowledgements

The authors acknowledge Penousal Machado for suggesting the combination of Zipf metrics with an ANN for authorship attribution. They also thank José Santiago, Cernadas Vilas, Mónica Miguélez Rico, and Miguel Penin Álvarez for conducting the ANN experiment. Tarsem Purewal, Charles McCormick, Valerie Sessions, and James Wilkinson helped derive Zipf metrics and MIDI corpora. This work was supported in part by the College of Charleston through an internal R&D grant.