Chapter 10. Meeting 10, Approaches: Probability and Markov Chains 10.1. Announcements • Musical Design Report 2 due this Thursday, 11 March • Thursday we will work in PD and Csound • Quiz next Tuesday 10.2. Half-Period Oscillators as ParameterObjects • Continuously varying the seconds per cycle (frequency) of an oscillator results in complex periodicities; random or discrete frequency variation results in complexity :: tpmap 100 ws,e,(ls,e,50,10,30),0,0,10 waveSine, event, (lineSegment, (constant, 50), (constant, 10), (constant, 30)), 0, (constant, 0), (constant, 10) TPmap display complete. :: tpmap 100 ws,e,(ru,19,21),0,0,10 waveSine, event, (randomUniform, (constant, 19), (constant, 21)), 0, (constant, 0), (constant, 10) TPmap display complete. • An alternative is an oscillator that only updates seconds per half cycle (half frequency) once per half-period 96
23
Embed
Session #10, Approaches: Probability and Markov chains · Chapter 10. Meeting 10, Approaches: Probability and Markov Chains 10.1. Announcements • Musical Design Report 2 due this
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Chapter 10. Meeting 10, Approaches: Probability and Markov Chains
10.1. Announcements
• Musical Design Report 2 due this Thursday, 11 March
• Thursday we will work in PD and Csound
• Quiz next Tuesday
10.2. Half-Period Oscillators as ParameterObjects
• Continuously varying the seconds per cycle (frequency) of an oscillator results in complex periodicities; random or discrete frequency variation results in complexity
• 1961: Harry Olson and Herbert Belar build a sophisticated electronic machine that produced and synthesized melodices based on Markovian pitch and rhythm analysis of eleven Stephen Collins Foster songs (1961)
To be, or not to be- that is the question: Whether ’tis nobler in the mind to suffer The slings and arrows of outrageous fortuneOr to take arms against a sea of troubles,And by opposing end them. To die- to sleep- No more; and by a sleep to say we endThe heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be wish’d. To die- to sleep. To sleep- perchance to dream: ay, there’s the rub! For in that sleep of death what dreams may comeWhen we have shuffled off this mortal coil, Must give us pause. There’s the respectThat makes calamity of so long life.For who would bear the whips and scorns of time,Th’ oppressor’s wrong, the proud man’s contumely, The pangs of despis’d love, the law’s delay,The insolence of office, and the spurnsThat patient merit of th’ unworthy takes,When he himself might his quietus makeWith a bare bodkin? Who would these fardels bear, To grunt and sweat under a weary life,But that the dread of something after death- The undiscover’d country, from whose bournNo traveller returns- puzzles the will, And makes us rather bear those ills we have Than fly to others that we know not of?Thus conscience does make cowards of us all,And thus the native hue of resolution Is sicklied o'er with the pale cast of thought,And enterprises of great pith and momentWith this regard their currents turn awryAnd lose the name of action.- Soft you now! The fair Ophelia!- Nymph, in thy orisons Be all my sins rememb'red.
• 0-order Markov re-generation
wish’d. contumely, Be contumely, the Devoutly thus pangs by thy of fardels makes name consummation pale Who we to respect coil, the to be and To Nymph, Th’ That No ’Tis There’s And the cowards of that When the weary or To a against wrong, And name With th’ we thought, the sins That To my wrong, off perchance those Be scorns To his a that With others The quietus currents fly wrong, weary that To traveller time, When have scorns wrong, pale traveller against of make scorns quietus of delay, sleep. awry With to currents in and With cast coil, But have may arms Th’ take arrows and The those their to regard the end we coil, fortune take
die to others that is the name of so long life. For in the will, And enterprises of great pith and scorns of thought, And enterprises of thought, And lose the proud man’s contumely, The undiscover’d country, from whose bourn No more; and the whips and moment With this regard their currents turn awry And lose the proud man’s contumely, The slings and sweat under a sleep perchance to dream: ay, there’s the whips and scorns of office, and arrows of great pith and scorns of something after death what dreams may come When he himself might his quietus make With this regard their currents turn awry And makes us pause. There’s the law’s delay, The heartache, and arrows of
• 2-order Markov re-generation
To be, or not to be wish’d. To die to sleep No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be wish’d. To die to sleep No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be wish’d. To die to sleep No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be that is the question: Whether ’tis nobler in the mind to suffer The slings and
• 3-order Markov re-generation
the name of action. Soft you now! The fair Ophelia! Nymph, in thy orisons Be all my sins rememb'red. To be, or not to be wish’d. To die to sleep No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be that is the question: Whether ’tis nobler in the mind to suffer The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die to sleep No more; and by a sleep to say we end The heartache, and the spurns That patient merit of th’ unworthy takes, When he himself
• 4-order Markov re-generation
those ills we have Than fly to others that we know not of? Thus conscience does make cowards of us all, And thus the native hue of resolution Is sicklied o'er with the pale cast of thought, And enterprises of great pith and moment With this regard their currents turn awry And lose the name of action. Soft you now! The fair Ophelia! Nymph, in thy orisons Be all my sins rememb'red. To be, or not to be wish’d. To die to sleep No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. ’Tis a consummation Devoutly to be that is the question: Whether ’tis nobler in the
• 5-order Markov re-generation
we have shuffled off this mortal coil, Must give us pause. There’s the respect That makes calamity of so long life. For who would bear the whips and scorns of time, Th’ oppressor’s wrong, the proud man’s contumely, The pangs of despis’d love, the law’s delay, The insolence of office, and the spurns That patient merit of th’ unworthy takes, When he himself might his quietus make With a bare bodkin? Who would these fardels bear, To grunt and sweat under a weary life, But that the dread of something after death The undiscover’d country, from whose bourn No
109
traveller returns puzzles the will, And makes us rather bear those ills we have Than fly to others that we know
10.9. Markov Chains: Example: Mozart Symphony 40
• Audio: Mozart: Symphony 40
• Pitch and rhythm based Markov regeneration at various orders
• Markov-generated examples [markovMozart.py]
10.10. Markov Analysis and Generation with athenaCL Python Libraries: Text
• Use the athenaCL Markov module
• Create a markov.Transition instances to do analysis
• Example: string data [markovShakespear.py]
import randomfrom athenaCL.libATH import markov
src = """To be, or not to be- that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortuneOr to take arms against a sea of troubles,And by opposing end them. To die- to sleep- No more; and by a sleep to say we endThe heartache, and the thousand natural shocksThat flesh is heir to. 'Tis a consummation Devoutly to be wish'd. To die- to sleep.To sleep- perchance to dream: ay, there’s the rub!For in that sleep of death what dreams may comeWhen we have shuffled off this mortal coil,Must give us pause. There’s the respectThat makes calamity of so long life.For who would bear the whips and scorns of time,Th' oppressor’s wrong, the proud man’s contumely,The pangs of despis'd love, the law’s delay,The insolence of office, and the spurnsThat patient merit of th' unworthy takes,When he himself might his quietus makeWith a bare bodkin? Who would these fardels bear,To grunt and sweat under a weary life,But that the dread of something after death- The undiscover'd country, from whose bournNo traveller returns- puzzles the will,And makes us rather bear those ills we haveThan fly to others that we know not of?
110
Thus conscience does make cowards of us all, And thus the native hue of resolutionIs sicklied o'er with the pale cast of thought,And enterprises of great pith and momentWith this regard their currents turn awryAnd lose the name of action.- Soft you now!The fair Ophelia!- Nymph, in thy orisons Be all my sins rememb'red."""
orderMax = 2 # large numbers here will take time!mkObj = markov.Transition()mkObj.loadString(src, orderMax) # source and max order1
for order in range(0, orderMax+1):print('requested order: ' + order)msg = []for x in range(120):
val = random.random()msg.append(mkObj.next(val, msg, order))
print(' '.join(msg) + '\n')
10.11. Markov Analysis and Generation with athenaCL Python Libraries: MIDI
• Example: pitch and rhythm data [markovMozart.py]
ampGen = parameter.factory(['ws','e',4,0,100,120]) # sine osc b/n 90 and 120 f = random.choice(range(50,70))phase = random.random()panGen = parameter.factory(['ws','e',f,phase,20,107])score = []tStart = 0.0
for i in range(events):pitch = mkPitch.next(random.random(), pitchHistory, order)pitchHistory.append(pitch)rhythm = mkRhythm.next(random.random(), rhythmHistory, order)rhythmHistory.append(rhythm)
Description: Produces Pulse sequences by means of a Markov transition string specification and a dynamic transition
order generator. The Markov transition string must definesymbols that specify valid Pulses. Markov transition orderis specified by a ParameterObject that produces valuesbetween 0 and the maximum order available in the Markov
transition string. If generated-orders are greater thanthose available, the largest available transition order will
be used. Floating-point order values are treated asprobabilistic weightings: for example, a transition of 1.5
Description: Produces values by means of a Markov transitionstring specification and a dynamic transition ordergenerator. Markov transition order is specified by a
ParameterObject that produces values between 0 and themaximum order available in the Markov transition string. If
generated-orders are greater than those available, the largest available transition order will be used. Floating-
point order values are treated as probabilistic weightings:for example, a transition of 1.5 offers equal probability of
first or second order selection. Arguments: (1) name, (2) transitionString, (3) parameterObject {order value}
maxAnalysisOrder, parameterObjectDescription: Produces values by means of a Markov
analysis of values provided by a source Generator ParameterObject; the analysis of these values is usedwith a dynamic transition order Generator to produce newvalues. The number of values drawn from the source Generator is specified with the valueCount argument. Themaximum order of analysis is specified with themaxAnalysisOrder argument. Markov transition order isspecified by a ParameterObject that produces valuesbetween 0 and the maximum order available in the Markov
transition string. If generated-orders are greater thanthose available, the largest available transition order
will be used. Floating-point order values are treated asprobabilistic weightings: for example, a transition of1.5 offers equal probability of first or second orderselection. Arguments: (1) name, (2) parameterObject{source Generator}, (3) valueCount, (4)
maxAnalysisOrder, (5) parameterObject {output order value}
• First order analysis and regeneration of a sine oscillation