150 likes | 291 Views
Andrei Andreyevich Markov 1856 - 1922. Markov Chains. Probability. Typically measured between 0.0 and 1.0 For events following another event must total 1.0 Important in statistics
E N D
Probability • Typically measured between 0.0 and 1.0 • For events following another event must total 1.0 • Important in statistics • Be careful in establishing (e.g., the probability of heads up on a tossed coin is forever 0.5 no matter how many times the coin is tossed). • Americans have 2.5 children
First order Markov Chainindicates that the current event will effect the choice of the following event.
Second order Markov chainTwo successive events will influence the next event
Markov Chains • Are a type of grammar (syntax) • Many types of grammars (e.g., finite state, recursive, augmented transition, etc.) • These are typically linear • Robust grammars require hierarchy • Hierarchy is non-linear
Markov Analysis • Select data • Extract pitches • Place pitches in STM • Create code for doing above
Details • Some cope-events: ’((0 60 1000 1 127) (1000 60 1000 1 127)(2000 62 1000 1 127) (3000 61 1000 1 127)(4000 60 1000 1 127)(5000 60 1000 1 127)) • Get the pitches: (mapcar #’second . . . .) = (60 60 62 61 60 60) • Place in an stm (defvar *stm* ()) • Data can look like this ((60 (60 61 60)) (62 (61)) (61 (60))) which equates to:
Code details • Create a blank *stm* • Create a function that adds stuff to *stm* • Create two sub functions 1) that adds a new entry if none exists 2) adds a new following pitch to an existing entry if one does exist
Needs • “assoc” is a good function for testing whether or not an entry is present in a composite list as in • (assoc 2 '((1 (2 2))(2 (3 3))) :test #'equal) which returns (2 (3 3))
Also • (substitute ‘(2 (3 3 3)) '(2 (3 3)) '((1 (2 2))(2 (3 3))) :test #'equal) returns ((1 (2 2)) (2 (3 3 3))) But “substitute” is not destructive. That is, “substitute” does not actually alter a global variable, you’ll have to reset the variable yourself. In other words, if: (defvar *stm* ‘((2 (3 3))(4 (5 5)))) and you do (substitute ‘(4 (5 5 6)) ‘(4 (5 5)) *stm* :test #’equal) *stm* will remain the same you’ll have to (setf *stm* (substitute ‘(4 (5 5 6) ‘(4 (5 5)) *stm* :test #’equal))
Markov Composition • Use an STM • Select first pitch randomly (careful) • Continue until unable to proceed