idsel {{id | (id+)} stream}+ [Macro]

Creates an id selection table for implementing higher order Markov processes using the graph pattern. In higher order Markov, the probability of the next choice is based on the current node and zero or more previous choices, represented as zero or more previous node ids. The transition table is specified as a sequence of id stream pairs. id can be a single identifier or a list of previous identifiers. Stream is the probability item stream to use if that id matches the actual previous ids that were chosen. For example, the declaration of a node for some item B in a 2nd order Markov graph might look like:

(B to (idsel a (items a b c in random)
             b (items (a weight 4) b in random)>
             c a)))
which corresponds to the transition table:
Previous       A    B    C
Current        B    B    B
Next
          A  .333  .80  1.0
          B  .333  .20  0.0
          C  .333  .00  0.0
idsel uses pattern matching to find previous ids in the selection table. Previous ids are matched with each candidate id entry in the table according two rules: (1) matching occurs for the length of id, which may be less than the previous number of choices. If every candidate id matches its corresponding id in the previous choices, then that probability stream is selected. This allows multiple entries in a table to be collapsed to a single selection. (2) A * at any position in id matches the corresponding previous choice, no matter what it was. For example, the following two selection tables are equivalent:

(idsel a (items a b c d in random)
       b (items (a weight 4) c d in random)
       c (items a b c d in random)
       d (items a b c d in random))

(idsel b (items (a weight 4) c d in random)
       * (items a b c d in random))

Example:

;; this second order markov graph generates random 
;; rhythms that maintain a quarter note pulse (tobias kunze)

(rhythms (h   to (items e e. q q. q.. h in random))
         (q.. to s)
         (q.  to (items e s in random))
         (q   to (items e e. q q. q.. h in random))
         (e.  to s)
         (e   to (idsel e (items s e e. q q. q.. h in random)
                        * e))
         (s   to (idsel e s q. s q e. h e.
                        * (items e e. q q. q.. h in random)))
         in graph for 20 previous (q)))

See Also:

graph, markov.cm


Last Modified: 5-Mar-1998