示例#1
0
def FiniteRV(density, symbol=None):
    """
    Create a Finite Random Variable given a dict representing the density.

    Returns a RandomSymbol.

    >>> from sympy.stats import FiniteRV, P, E

    >>> density = {0: .1, 1: .2, 2: .3, 3: .4}
    >>> X = FiniteRV(density)

    >>> E(X)
    2.00000000000000
    >>> P(X>=2)
    0.700000000000000
    """
    return create_SingleFinitePSpace(density, symbol).value
示例#2
0
 def __new__(cls, sides=6, symbol=None):
     density = dict((i,Rational(1,sides)) for i in range(1,sides+1))
     return create_SingleFinitePSpace(density, symbol, cls)
示例#3
0
 def __new__(cls, p, a, b, symbol=None):
     a, b, p = map(sympify, (a, b, p))
     density = {a:p, b:(1-p)}
     return create_SingleFinitePSpace(density, symbol, cls)
示例#4
0
 def __new__(cls, items, symbol=None):
     density = dict((sympify(item), Rational(1, len(items)))
                    for item in items)
     return create_SingleFinitePSpace(density, symbol, cls)
示例#5
0
 def __new__(cls, N, m, n, symbol=None):
     N, m, n = map(sympify, (N, m, n))
     density = dict((k, binomial(m, k) * binomial(N-m, n-k) / binomial(N, n))
             for k in range(max(0, n+m-N), min(m, n) + 1))
     return create_SingleFinitePSpace(density, symbol, cls)
示例#6
0
 def __new__(cls, n, p, succ=1, fail=0, symbol=None):
     n, p, succ, fail = map(sympify, (n, p, succ, fail))
     density = dict((k*succ + (n-k)*fail,
             binomial(n, k) * p**k * (1-p)**(n-k)) for k in range(0, n+1))
     return create_SingleFinitePSpace(density, symbol, cls)
示例#7
0
 def __new__(cls, p, succ=1, fail=0, symbol=None):
     succ, fail, p = map(sympify, (succ, fail, p))
     density = {succ:p, fail:(1-p)}
     return create_SingleFinitePSpace(density, symbol, cls)