19.1 Random variables and probability spaces

Module: sage.probability.random_variable

Random variables and probability spaces

This introduces a class of random variables, with the focus on discrete random variables (i.e. on a discrete probability space). This avoids the problem of defining a measure space and measurable functions.

Module-level Functions

is_DiscreteProbabilitySpace( S)

is_DiscreteRandomVariable( X)

is_ProbabilitySpace( S)

is_RandomVariable( X)

Class: DiscreteProbabilitySpace

class DiscreteProbabilitySpace
The discrete probability space
DiscreteProbabilitySpace( self, X, P, [codomain=None], [check=False])

Create the discrete probability space with probabilities on the space X given by the dictionary P with values in the field real_field.

sage: S = [ i for i in range(16) ] 
sage: P = {}
       sage: for i in range(15): P[i] = 2^(-i-1)
sage: P[15] = 2^-16 
sage: X = DiscreteProbabilitySpace(S,P)
sage: X.domain()
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
sage: X.set()
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
sage: X.entropy()
       1.9997253418

A probability space can be defined on any list of elements.

sage: AZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
sage: S = [ AZ[i] for i in range(26) ]
sage: P = { 'A':1/2, 'B':1/4, 'C':1/4 }
sage: X = DiscreteProbabilitySpace(S,P)
sage: X
Discrete probability space defined by {'A': 1/2, 'C': 1/4, 'B': 1/4}
sage: X.entropy()
       1.5

Functions: entropy,$ \,$ set

entropy( self)

The entropy of the probability space.

set( self)

The set of values of the probability space taking possibly nonzero probability (a subset of the domain).

Special Functions: __init__,$ \,$ __repr__

Class: DiscreteRandomVariable

class DiscreteRandomVariable
A random variable on a discrete probability space.
DiscreteRandomVariable( self, X, f, [codomain=None], [check=False])

Create free binary string monoid on $ n$ generators.

Input: x: A probability space f: A dictionary such that X[x] = value for x in X is the discrete function on X

Functions: correlation,$ \,$ covariance,$ \,$ expectation,$ \,$ function,$ \,$ standard_deviation,$ \,$ translation_correlation,$ \,$ translation_covariance,$ \,$ translation_expectation,$ \,$ translation_standard_deviation,$ \,$ translation_variance,$ \,$ variance

correlation( self, other)

The correlation of the probability space X = self with Y = other.

covariance( self, other)

The covariance of the discrete random variable X = self with Y = other.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the variance of $ X$ is:

   cov$\displaystyle (X,Y) = E((X-E(X)*(Y-E(Y)) = \sum_{x \in S} p(x) (X(x) - E(X))(Y(x) - E(Y))
$

expectation( self)

The expectation of the discrete random variable, namely $ \sum_{x \in S} p(x) X[x]$ , where $ X$ = self and $ S$ is the probability space of $ X$ .

function( self)

The function defining the random variable.

standard_deviation( self)

The standard deviation of the discrete random variable.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the standard deviation of $ X$ is defined to be

$\displaystyle \sigma(X) = \sqrt{ \sum_{x \in S} p(x) (X(x) - E(x))**2}
$

translation_correlation( self, other, map)

The correlation of the probability space X = self with image of Y = other under map.

translation_covariance( self, other, map)

The covariance of the probability space X = self with image of Y = other under the given map of the probability space.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the variance of $ X$ is:

   cov$\displaystyle (X,Y) = E((X-E(X)*(Y-E(Y)) = \sum_{x \in S} p(x) (X(x) - E(X))(Y(x) - E(Y))
$

translation_expectation( self, map)

The expectation of the discrete random variable, namely $ \sum_{x \in S} p(x) X[e(x)]$ , where $ X$ = self, $ S$ is the probability space of $ X$ , and $ e$ = map.

translation_standard_deviation( self, map)

The standard deviation of the translated discrete random variable $ X \circ e$ , where $ X$ = self and $ e$ = map.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the standard deviation of $ X$ is defined to be

$\displaystyle \sigma(X) = \sqrt{ \sum_{x \in S} p(x) (X(x) - E(x))**2}
$

translation_variance( self, map)

The variance of the discrete random variable $ X \circ e$ , where $ X$ = self, and $ e$ = map.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the variance of $ X$ is:

$\displaystyle \var(X) = E((X-E(x))^2) = \sum_{x \in S} p(x) (X(x) - E(x))^2
$

variance( self)

The variance of the discrete random variable.

Let $ S$ be the probability space of $ X$ = self, with probability function $ p$ , and $ E(X)$ be the expectation of $ X$ . Then the variance of $ X$ is:

$\displaystyle \var(X) = E((X-E(x))^2) = \sum_{x \in S} p(x) (X(x) - E(x))^2
$

Special Functions: __call__,$ \,$ __init__,$ \,$ __repr__

__call__( self, x)

Return the value of the random variable at x.

Class: ProbabilitySpace_generic

class ProbabilitySpace_generic
A probability space.
ProbabilitySpace_generic( self, domain, RR)

A generic probability space on given domain space and codomain ring.

Functions: domain

Special Functions: __init__

Class: RandomVariable_generic

class RandomVariable_generic
A random variable.
RandomVariable_generic( self, X, RR)

Functions: codomain,$ \,$ domain,$ \,$ field,$ \,$ probability_space

Special Functions: __init__

See About this document... for information on suggesting changes.