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'"[depthsequence](loop [accum