Affinity Map

With the 13-note Blackwood etude, I wasn't confident that the way I was looking for a suitable
color/pitch mapping was guaranteed to find the best possible one. I was looking at the six possible
circle-of-_______s orderings, but the question nagged me: "What if the music isn't organized that
way? What if there's some other pattern of pitch usage involved?"

To explore this, I made a tool to answer the question: what pitches and combinations of pitches
are used most often?

The tool calculates amount of time notes of each pitch (class) are sounding, and for each pair of
pitches, how much time they're sounding simultaneously. The results are displayed in a circle,
with the prominence of each pitch and pairings of two pitches indicated by brightness. For lack
of a better term, I call this an affinity map.

Here's what that looks like for the 13-note etude, with the pitch classes arranged in numerical order:


As you can see, some pitch and combinations figure more prominently than others.

But is there a way to make more sense of this?

I noticed that pairs of pitches 3 steps apart were fairly common, so I tried ordering the pitches that way:


That segregated the pitches into two nice groups, {0,3,6,9,12} and {8,11,1,4}, but there were some
prominent affinities between the groups (e.g. 1:6, 1:9, 6:11), so I tried reordering them by hand to
bring those pairs closer. Here's the best I could do:


That seemed pretty good, but I wondered whether I was missing something. I thought about having the tool
rank all possible arrangements in terms of maximizing the affinity of neighboring pitches, but abandoned
that idea when I realized that there were about half a trillion combinations, and it would take several
days for my computer to evaluate them all.

So, instead, I made it try improving an arrangement by moving pitches around; it tries swapping a pair of
pitches, and if that improves the ranking, keep it, but otherwise undo the swap and try a different pair.
This quickly found arrangements that looked a little better than mine, but never any that were significantly
better, so I decided I was close enough to optimum to not worry about it further. Here's one of those:

Once I got to this point, I compared these arrangements to the best one I'd found that was based on a single
step size all around the circle: the 5-step one. Here's what that looks like:

That seemed reasonably well-organized (lots of prominent pairs adjacent), and I decided that having the
pitches arranged in a regular way was advantageous, and that an ad hoc, irregular affinity map, while
interesting, didn't necessarily the best ordering for other uses.


Having made the tool, though, I wondered what it would look like on conventional, 12-pitch, tonal music.
I tried it with a Rachmaninoff prelude. Here's what that looks like; on the left is the affinity map with the
pitches in order (chromatic scale), and on the right is what it looks like after my automated shuffle/test thingy
had done its work:

Pretty much what you'd expect: a nice tonal cluster centered around D (2), the key the piece is in.

As a reality check, I tried it on an atonal piece by Schoenberg.
As before, on the left is with the pitches in chromatic order, on the right is after my tool tried its best:

As expected: no significant tonal clustering, relatively equal use of all pitches and combinations.