Markov Creativity

The above is an aleatoric composition in the style of J.S. Bach, produced automatically by my laptop in ~60 milliseconds. (You can hear a rendering here). The code to implement the algorithm comes to around 17 lines of Clojure:

(defn model-from-sequence
  "Returns a transition matrix of 'depth' from 'sequence'"
  [depth sequence]
  (loop [accum {}
         chunks (partition (inc depth) 1 (seq sequence))]
    (if (seq? chunks)
      (let [chunk  (first chunks)
            prefix (drop-last chunk)
            suffix (last chunk)]
        (recur (assoc accum prefix (conj (get accum prefix []) suffix)) (next chunks)))
      accum)))

(defn chain
  "Returns a lazy Markov chain starting with 'current' using matrix 'trans'"
  [current trans]
  (if-let [transitions (trans current)]
    (cons (first current)
          (lazy-seq (chain (concat (rest current) [(rand-nth transitions)]) trans)))
    current))

It can be a bit spooky at first to think of a computer composing plausible Bach after listening to the six pieces of Bach’s 1st Cello Suite once, especially when a music student would require quite a bit more time to gain the same skill.

“How can a machine be creative?”, one is oft asked. The answer, which typically only increases the interlocutor’s unease, is that it does it the same way we do: by observing patterns and gradually creating an internal model from which to steer serendipity.

That we are rule inferencing and pattern driven is clear in the cultural artifacts we produce. Beethoven cannot have composed jazz or rock or Carnatic music because his pattern recognition facilities received only the music of his own time and place. This is also why Brahms’s First Symphony is sometimes referred to as “Beethoven’s Tenth.”

It isn’t just music, either. These sorts of probability chaining algorithms work over many domains. They’re used by physicists, biologists, hedge fund quants, and so on, yielding useful results in all cases. For example, if I feed the same code a diet of Cavafy’s poetry, it yields a synthetic poet whom I shall call Markovafy:

His mouth, his flesh
all of it suffers unremittingly from desire,
from the feel of that other
Delectable intelligence of their well-delineated, close-knit flesh:
they do not tread the ground,
but only run the waters

His body is honor,
and here is the statue at which I now gaze in ecstasy

Choking, almost silenced by desire,
answers came back the same way from
the distracted voice

Here in the water with his beauty,
his delicate beauty.

My computer now seems to long for a steamy Greek bathhouse. But, of course, it has no desires at all.

Most of us harbor a lingering intuition that that which makes us feel must have come as a flash of communication from another soul, but once there is no soul, no special ghost driving the body, what’s left is a biochemical process, a mass of neuroanatomy that learns from what it experiences and remixes what it has learnt.

In addition to the obvious lessons one can draw from this regarding copyright, the concept of “artistic theft” and the vilification of remix culture, a careful reader will also see an echo of Aristotle: we are what we do repeatedly.

If you want a particular future for yourself, you must live that future’s past today. Or as, while musing over whether the best trained athlete would win the Olympiad, Markovafy once put it:

When the month has passed away,
the things now coming can be told
before they are known.

§

This entry is part of Jack Rusher’s archive, originally published December 22nd, 2012, in New York.