Module dist
[frames] | no frames]

Module dist

Discrete probability distributions

Classes
  DDist
Discrete distribution represented as a dictionary.
  MixtureDist
A mixture of two probabability distributions, d1 and d2, with mixture parameter p.
Functions
 
JDist(PA, PBgA)
Create a joint distribution on P(A, B) (in that order), represented as a DDist
 
bayesEvidence(PA, PBgA, b)
Returns: P(A | b)
 
totalProbability(PA, PBgA)
Returns: P(B) using the law of total probability.
 
DeltaDist(v)
Distribution with all of its probability mass on value v
 
UniformDist(elts)
Uniform distribution over a given finite set of elts
 
triangleDist(peak, halfWidth, lo=None, hi=None)
Construct and return a DDist over integers.
 
squareDist(lo, hi, loLimit=None, hiLimit=None)
Construct and return a DDist over integers.
 
removeElt(items, i)
non-destructively remove the element at index i from a list; returns a copy; if the result is a list of length 1, just return the element
 
incrDictEntry(d, k, v)
If dictionary d has key k, then increment d[k] by v.
Variables
  __package__ = None
Function Details

JDist(PA, PBgA)

 

Create a joint distribution on P(A, B) (in that order), represented as a DDist

Parameters:
  • PA - a DDist on some random var A
  • PBgA - a conditional probability distribution specifying P(B | A) (that is, a function from elements of A to DDist on B)

bayesEvidence(PA, PBgA, b)

 
Parameters:
  • PBgA - conditional distribution over B given A (function from values of a to DDist over B)
  • PA - prior on A
  • b - evidence value for B = b
Returns:
P(A | b)

totalProbability(PA, PBgA)

 
Parameters:
  • PBgA - conditional distribution over B given A (function from values of a to DDist over B)
  • PA - distribution over A (object of type DiscreteDist)
Returns:
P(B) using the law of total probability. self represents P(B | A); P(A) is the argument to the method; we compute and return P(B) as sum_a P(B | a) P(a)

UniformDist(elts)

 

Uniform distribution over a given finite set of elts

Parameters:
  • elts - list of any kind of item

triangleDist(peak, halfWidth, lo=None, hi=None)

 

Construct and return a DDist over integers. The distribution will have its peak at index peak and fall off linearly from there, reaching 0 at an index halfWidth on either side of peak. Any probability mass that would be below lo or above hi is assigned to lo or hi

squareDist(lo, hi, loLimit=None, hiLimit=None)

 

Construct and return a DDist over integers. The distribution will have a uniform distribution on integers from lo to hi-1 (inclusive). Any probability mass that would be below lo or above hi is assigned to lo or hi.

incrDictEntry(d, k, v)

 

If dictionary d has key k, then increment d[k] by v. Else set d[k] = v.

Parameters:
  • d - dictionary
  • k - legal dictionary key (doesn't have to be in d)
  • v - numeric value