CCRMA

Random Processes


Probability distributions

Probability is the likehood of occurrence of a given event, ratio of number of occurrences of that event to the total number of results of the random process. A probability distribution is a table that shows the likehood of occurrence of one of more events, where the probability of occurrence of a given event is expressed as a value between 0 and 1.

[continuous vs discrete distributions]

Random numbers... as normally generated in a computer are not really really random. They are the result of executing an algorithm, the output values can be considered statistically random if the algorithm is good enough. Normally the random number generator is seeded by a number, after that the numbers generated are predictable (each time we seed the generator with the same number it produces the same sequence of "random" numbers).

In common lisp we can generate random floating point values using the (random xxx) function, where xxx is a floating point number. If we need integers (for example to generate midi note numbers) then the argument to random should be an integer.

[Distributions: uniform, linear, triangular, exponential...]

The example file probability.lisp has some examples of probability distributions, but see below for the more complete Common Music "ran" function (Note: for probability.lisp you'll have to first compile and load plot.lisp to be able to plot the distributions, but this has not been ported yet to cmucl)

See some useful functions in Common Music: drunk, between,

State Machines

[a definition]

A state machine remembers a "state" (a memory of where it is in its internal process) and depending on whar state it is in, it calculates outputs that are determined by the current inputs and then transitions to a different (or the same) state. We could specify a state machine by a connected graph. States are represented by circles. Directed arrows specify the transitions between states. Each transition is determined by the "current state" (that is, the circle it originates in) and by the input conditions. As a side effect of the state transition the state machine defines new output values.

[Mealy: transition -> output; Moore: state -> output]

A very simple state machine could be defined by the following lisp code:

(defparameter h-state t)

(defun harmonize (input)
  (if h-state
      ;; up by a fifth
      (progn
	(setf h-state nil)
	(+ input 7))
    ;; up by a fourth
    (progn
      (setf h-state t)
      (+ input 5))))

h-state is a global variable that remembers the current state of the state machine. It can have two values, t or nil (ie: this state machine has only two states). The function definition is simple, depending on h-state is executes two branches of code, each one calculates and returns an output value based on the input to the state machine and the current state. It then transitions to the other state.

(with-sound()
  (loop
    repeat 10
    for time from 0 by 0.2
    for note = 60 then (harmonize note)
    do
    (fm-violin time 0.16 (hertz (if (> note 128) 128 note)) 0.1)))

See statemachine.lisp for ready to run examples...

Each state within the state machine has to define what to do with the outputs and how to transition to the next state. So far we have only seen a completely deterministic behavior in our state machine.

What if some of the decisions were taken by stochastic (random) processes? The output of our state machine is no longer completely predictable. Those stochastic decisions could influence the transition between states of the generation of outputs from the current inputs to the state machine.

  • State Machines
    • Deterministic
    • Stochastic

[Markov chains: probability for transitions between states]

see the class lisp transcript for examples on how to define and use markov chains in our Lisp environment

Relevant entries in the Common Music Dictionary


©1998, 2001-2005 Fernando Lopez-Lezcano. All Rights Reserved.
nando@ccrma.stanford.edu