Andrei Andreyevich Markov 1856 - 1922. Markov Chains.

Post on 18-Dec-2015

217 views 0 download

Transcript of Andrei Andreyevich Markov 1856 - 1922. Markov Chains.

Andrei Andreyevich Markov 1856 - 1922Andrei Andreyevich Markov 1856 - 1922

QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.

Markov ChainsMarkov Chains

ProbabilityProbability

• 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

Zero order Markov Chain

Pseudo-random choices.

Zero order Markov Chain

Pseudo-random choices.

First order Markov Chain

indicates that the current event will effect the choice

of the following event.

First order Markov Chain

indicates that the current event will effect the choice

of the following event.

First order state transition matrix First order state transition matrix (stm)(stm)

A

B

C

A B C

.5 .5 0

.5 0 .5

0 .5 .5

Second order Markov chain

Two successive events will influence the next event

Second order Markov chain

Two successive events will influence the next event

A B C

AA

AB

AC

BA

BB

BC

CA

CB

CC

0 1.0 0

.3 .3 .4

0 .2 .8

0 .6 .4

.2 .5 .3

0 1.0 0

.7 .2 .1

.1 .4 .5

.2 .8 0

Markov ChainsMarkov 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 AnalysisMarkov Analysis

• Select data

• Extract pitches

• Place pitches in STM

• Create code for doing above

Details 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: QuickTime™ and a

TIFF (Uncompressed) decompressorare needed to see this picture.

Code detailsCode 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

NeedsNeeds

• “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 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 CompositionMarkov Composition

• Use an STM

• Select first pitch randomly (careful)

• Continue until unable to proceed