B
    [                 @   s   d dl mZmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZ ddddd	d
ddddddddddddddddgZd&ddZd'ddZd(ddZeZd)d dZd*d!dZd+d"dZd,d#d$Zd-d%dZeZeZ dS ).    )print_functiondivision   )probabilityexpectationdensitywheregivenpspacecdfcharacteristic_functionsamplesample_iterrandom_symbolsindependent	dependentsampling_densitymoment_generating_function)sqrtPEr   r   r	   r   r   r   r
   r   variancestdskewness
covariancer   r   r   correlationmomentcmomentr   r   Nc             K   s   t | | | |f|S )a4  
    Return the nth moment of a random expression about c i.e. E((X-c)**n)
    Default value of c is 0.

    Examples
    ========

    >>> from sympy.stats import Die, moment, E
    >>> X = Die('X', 6)
    >>> moment(X, 1, 6)
    -5/2
    >>> moment(X, 2)
    91/6
    >>> moment(X, 1) == E(X)
    True
    )r   )Xnc	conditionkwargs r#   7lib/python3.7/site-packages/sympy/stats/rv_interface.pyr      s    c             K   s   t | d|f|S )ao  
    Variance of a random expression

    Expectation of (X-E(X))**2

    Examples
    ========

    >>> from sympy.stats import Die, E, Bernoulli, variance
    >>> from sympy import simplify, Symbol

    >>> X = Die('X', 6)
    >>> p = Symbol('p')
    >>> B = Bernoulli('B', p, 1, 0)

    >>> variance(2*X)
    35/3

    >>> simplify(variance(B))
    p*(-p + 1)
       )r   )r   r!   r"   r#   r#   r$   r   #   s    c             K   s   t t| |f|S )aH  
    Standard Deviation of a random expression

    Square root of the Expectation of (X-E(X))**2

    Examples
    ========

    >>> from sympy.stats import Bernoulli, std
    >>> from sympy import Symbol, simplify

    >>> p = Symbol('p')
    >>> B = Bernoulli('B', p, 1, 0)

    >>> simplify(std(B))
    sqrt(p*(-p + 1))
    )r   r   )r   r!   r"   r#   r#   r$   standard_deviation<   s    r&   c             K   s.   t | t | |f| |t ||f|  |f|S )a"  
    Covariance of two random expressions

    The expectation that the two variables will rise and fall together

    Covariance(X,Y) = E( (X-E(X)) * (Y-E(Y)) )

    Examples
    ========

    >>> from sympy.stats import Exponential, covariance
    >>> from sympy import Symbol

    >>> rate = Symbol('lambda', positive=True, real=True, finite=True)
    >>> X = Exponential('X', rate)
    >>> Y = Exponential('Y', rate)

    >>> covariance(X, X)
    lambda**(-2)
    >>> covariance(X, Y)
    0
    >>> covariance(X, Y + rate*X)
    1/lambda
    )r   )r   Yr!   r"   r#   r#   r$   r   R   s    c             K   s,   t | ||f|t| |f|t||f|  S )a  
    Correlation of two random expressions, also known as correlation
    coefficient or Pearson's correlation

    The normalized expectation that the two variables will rise
    and fall together

    Correlation(X,Y) = E( (X-E(X)) * (Y-E(Y)) / (sigma(X) * sigma(Y)) )

    Examples
    ========

    >>> from sympy.stats import Exponential, correlation
    >>> from sympy import Symbol

    >>> rate = Symbol('lambda', positive=True, real=True, finite=True)
    >>> X = Exponential('X', rate)
    >>> Y = Exponential('Y', rate)

    >>> correlation(X, X)
    1
    >>> correlation(X, Y)
    0
    >>> correlation(X, Y + rate*X)
    1/sqrt(1 + lambda**(-2))
    )r   r   )r   r'   r!   r"   r#   r#   r$   r   q   s    c             K   s    t | |f|}t| |||f|S )a<  
    Return the nth central moment of a random expression about its mean
    i.e. E((X - E(X))**n)

    Examples
    ========

    >>> from sympy.stats import Die, cmoment, variance
    >>> X = Die('X', 6)
    >>> cmoment(X, 3)
    0
    >>> cmoment(X, 2)
    35/12
    >>> cmoment(X, 2) == variance(X)
    True
    )r   r   )r   r   r!   r"   Zmur#   r#   r$   r      s    c             K   s*   t | |f|}d| | t| ||f| S )a  
    Return the nth Standardized moment of a random expression i.e.
    E( ((X - mu)/sigma(X))**n )

    Examples
    ========

    >>> from sympy.stats import skewness, Exponential, smoment
    >>> from sympy import Symbol
    >>> rate = Symbol('lambda', positive=True, real=True, finite=True)
    >>> Y = Exponential('Y', rate)
    >>> smoment(Y, 4)
    9
    >>> smoment(Y, 4) == smoment(3*Y, 4)
    True
    >>> smoment(Y, 3) == skewness(Y)
    True
    r   )r   r   )r   r   r!   r"   Zsigmar#   r#   r$   smoment   s    r(   c             K   s   t | d|f|S )a  
    Measure of the asymmetry of the probability distribution

    Positive skew indicates that most of the values lie to the right of
    the mean

    skewness(X) = E( ((X - E(X))/sigma)**3 )

    Examples
    ========

    >>> from sympy.stats import skewness, Exponential, Normal
    >>> from sympy import Symbol
    >>> X = Normal('X', 0, 1)
    >>> skewness(X)
    0
    >>> rate = Symbol('lambda', positive=True, real=True, finite=True)
    >>> Y = Exponential('Y', rate)
    >>> skewness(Y)
    2
       )r(   )r   r!   r"   r#   r#   r$   r      s    )r   N)N)N)N)N)N)N)N)!Z
__future__r   r   rvr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Zsympyr   __all__r   r   r&   r   r   r   r   r(   r   r   r   r#   r#   r#   r$   <module>   s"   D








