
&]\c           @` s   d  d l  m Z m Z m Z d  d l m Z m Z m Z d  d l m	 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d d l m Z m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z m Z m Z m Z m Z d  d l m  Z  d  d l m! Z! d  d l 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/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 d  d l# Z8 d d l9 m: Z: e rd   Z; n	 e j< Z; i d d 6d d 6d d 6Z= d Z> d Z? d Z@ d ZA d ZB d ZC d ZD d ZE d ZF d  ZG d! ZH d" ZI d# ZJ d$ ZK d% ZL d& ZM d' ZN d( ZO d) ZP d* ZQ d+ ZR d, ZS d- jT e= d e> e? e@ eC eD eE eF eG eH eI eJ eK eL eM eO eP eQ eR eS g  ZU d. ZV d/ ZW d0 ZX d1 ZY d- jT eV eU d2 eX g  ZZ d- jT eV eU g  Z[ i e> d3 6e? d4 6e@ d5 6eC d6 6eD d7 6eE d8 6eF d9 6eG d: 6eH d; 6eJ d< 6eK d= 6eL d> 6eI d? 6eM d@ 6eS dA 6eP dB 6eR dC 6eQ dD 6eO dE 6eU dF 6eV dG 6eW dH 6eX dI 6eZ dJ 6e[ dK 6eY dL 6Z\ e\ j]   Z^ eA e^ dM <eB e^ dN <eN e^ d@ <d3 dM dN d6 d7 d8 d9 d: d; d< d= d@ dE dB dD dC dA g Z_ x( e_ D]  Z` e^ e` ja dO d-  e^ e` <q=Wd6 d7 d8 d9 g Zb x( eb D]  Z` e^ e` ja dP dQ  e^ e` <qzWe^ jc d4  e^ jc d5  d- jT g  e_ D] Z` e^ e` ^ q ZU e= d eU e^ dF <eV ja dR dS  e^ dG <dT ZW eW e^ dH <dU Zd dV Ze ed e^ dI <ee e^ dL <d- jT e^ dG e^ dF g  Z[ e[ e^ dK <d- jT e^ dG e^ dF e^ dH e^ dI g  Zf ef e^ dJ <x? g  eg   D] Zh eh ji dW  reh ^ qD] Z` dX e` d UqW[` y [h Wn ej k
 rn Xek dY  Zl dZ   Zm d[   Zn d\   Zo d] ep f d^     YZq d_   Zr d` Zs da   Zt db   Zu dc   Zv dd ep f de     YZw dR ew f df     YZx dg   Zy dh   Zz ek ek di  Z{ dS ew f dj     YZ| dk dl dm dn  Z} do d dp  Z~ dq e| f dr     YZ ds   Z d S(t   i    (   t   divisiont   print_functiont   absolute_import(   t   string_typest   exec_t   PY3(   t   getargspec_no_selfN(   t   docceri   (   t   distcontt   distdiscrete(   t   check_random_state(   t	   _valarray(   t   combt   chndtrt   entrt   rel_entrt   xlogyt   ive(   t   optimize(   t	   integrate(   t
   derivative(   t   aranget   putmaskt   ravelt   onest   shapet   ndarrayt   zerost   floort   logical_andt   logt   sqrtt   placet   argmaxt	   vectorizet   asarrayt   nant   inft   isinft   NINFt   empty(   t   _XMAXc         C` s   t  j |  |  S(   N(   t   typest
   MethodType(   t   funct   objt   cls(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   instancemethod)   s    s   
Methods
-------
t   methodss   
Notes
-----
t   notess   
Examples
--------
t   examplessP   rvs(%(shapes)s, loc=0, scale=1, size=1, random_state=None)
    Random variates.
sE   pdf(x, %(shapes)s, loc=0, scale=1)
    Probability density function.
sS   logpdf(x, %(shapes)s, loc=0, scale=1)
    Log of the probability density function.
sB   pmf(k, %(shapes)s, loc=0, scale=1)
    Probability mass function.
sP   logpmf(k, %(shapes)s, loc=0, scale=1)
    Log of the probability mass function.
sI   cdf(x, %(shapes)s, loc=0, scale=1)
    Cumulative distribution function.
sW   logcdf(x, %(shapes)s, loc=0, scale=1)
    Log of the cumulative distribution function.
s}   sf(x, %(shapes)s, loc=0, scale=1)
    Survival function  (also defined as ``1 - cdf``, but `sf` is sometimes more accurate).
sG   logsf(x, %(shapes)s, loc=0, scale=1)
    Log of the survival function.
sd   ppf(q, %(shapes)s, loc=0, scale=1)
    Percent point function (inverse of ``cdf`` --- percentiles).
sV   isf(q, %(shapes)s, loc=0, scale=1)
    Inverse survival function (inverse of ``sf``).
sH   moment(n, %(shapes)s, loc=0, scale=1)
    Non-central moment of order n
so   stats(%(shapes)s, loc=0, scale=1, moments='mv')
    Mean('m'), variance('v'), skew('s'), and/or kurtosis('k').
sJ   entropy(%(shapes)s, loc=0, scale=1)
    (Differential) entropy of the RV.
sP   fit(data, %(shapes)s, loc=0, scale=1)
    Parameter estimates for generic data.
s   expect(func, args=(%(shapes_)s), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)
    Expected value of a function (of one argument) with respect to the distribution.
s   expect(func, args=(%(shapes_)s), loc=0, lb=None, ub=None, conditional=False)
    Expected value of a function (of one argument) with respect to the distribution.
sC   median(%(shapes)s, loc=0, scale=1)
    Median of the distribution.
s?   mean(%(shapes)s, loc=0, scale=1)
    Mean of the distribution.
sB   var(%(shapes)s, loc=0, scale=1)
    Variance of the distribution.
sL   std(%(shapes)s, loc=0, scale=1)
    Standard deviation of the distribution.
sw   interval(alpha, %(shapes)s, loc=0, scale=1)
    Endpoints of the range that contains alpha percent of the distribution
t    s   As an instance of the `rv_continuous` class, `%(name)s` object inherits from it
a collection of generic methods (see below for the full list),
and completes them with details specific for this particular distribution.
s+  
Alternatively, the object may be called (as a function) to fix the shape,
location, and scale parameters returning a "frozen" continuous RV object:

rv = %(name)s(%(shapes)s, loc=0, scale=1)
    - Frozen RV object with the same methods but holding the given shape,
      location, and scale fixed.
s  Examples
--------
>>> from scipy.stats import %(name)s
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

Calculate a few first moments:

%(set_vals_stmt)s
>>> mean, var, skew, kurt = %(name)s.stats(%(shapes)s, moments='mvsk')

Display the probability density function (``pdf``):

>>> x = np.linspace(%(name)s.ppf(0.01, %(shapes)s),
...                 %(name)s.ppf(0.99, %(shapes)s), 100)
>>> ax.plot(x, %(name)s.pdf(x, %(shapes)s),
...        'r-', lw=5, alpha=0.6, label='%(name)s pdf')

Alternatively, the distribution object can be called (as a function)
to fix the shape, location and scale parameters. This returns a "frozen"
RV object holding the given parameters fixed.

Freeze the distribution and display the frozen ``pdf``:

>>> rv = %(name)s(%(shapes)s)
>>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

Check accuracy of ``cdf`` and ``ppf``:

>>> vals = %(name)s.ppf([0.001, 0.5, 0.999], %(shapes)s)
>>> np.allclose([0.001, 0.5, 0.999], %(name)s.cdf(vals, %(shapes)s))
True

Generate random numbers:

>>> r = %(name)s.rvs(%(shapes)s, size=1000)

And compare the histogram:

>>> ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()

s5  The probability density above is defined in the "standardized" form. To shift
and/or scale the distribution use the ``loc`` and ``scale`` parameters.
Specifically, ``%(name)s.pdf(x, %(shapes)s, loc, scale)`` is identically
equivalent to ``%(name)s.pdf(y, %(shapes)s) / scale`` with
``y = (x - loc) / scale``.
s   
t   rvst   pdft   logpdft   cdft   logcdft   sft   logsft   ppft   isft   statst   entropyt   fitt   momentt   expectt   intervalt   meant   stdt   vart   mediant
   allmethodst   longsummaryt
   frozennotet   examplet   defaultt   before_notest   after_notest   pmft   logpmfs	   , scale=1s   (x, s   (k, t   rv_continuoust   rv_discretes  
Alternatively, the object may be called (as a function) to fix the shape and
location parameters returning a "frozen" discrete RV object:

rv = %(name)s(%(shapes)s, loc=0)
    - Frozen RV object with the same methods but holding the given shape and
      location fixed.
s  Examples
--------
>>> from scipy.stats import %(name)s
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

Calculate a few first moments:

%(set_vals_stmt)s
>>> mean, var, skew, kurt = %(name)s.stats(%(shapes)s, moments='mvsk')

Display the probability mass function (``pmf``):

>>> x = np.arange(%(name)s.ppf(0.01, %(shapes)s),
...               %(name)s.ppf(0.99, %(shapes)s))
>>> ax.plot(x, %(name)s.pmf(x, %(shapes)s), 'bo', ms=8, label='%(name)s pmf')
>>> ax.vlines(x, 0, %(name)s.pmf(x, %(shapes)s), colors='b', lw=5, alpha=0.5)

Alternatively, the distribution object can be called (as a function)
to fix the shape and location. This returns a "frozen" RV object holding
the given parameters fixed.

Freeze the distribution and display the frozen ``pmf``:

>>> rv = %(name)s(%(shapes)s)
>>> ax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-', lw=1,
...         label='frozen pmf')
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()

Check accuracy of ``cdf`` and ``ppf``:

>>> prob = %(name)s.cdf(x, %(shapes)s)
>>> np.allclose(x, %(name)s.ppf(prob, %(shapes)s))
True

Generate random numbers:

>>> r = %(name)s.rvs(%(shapes)s, size=1000)
s   The probability mass function above is defined in the "standardized" form.
To shift distribution use the ``loc`` parameter.
Specifically, ``%(name)s.pmf(k, %(shapes)s, loc)`` is identically
equivalent to ``%(name)s.pmf(k - loc, %(shapes)s)``.
t   _doc_s   del c         C` s-   | d  k r |  j   } n  |  | | j   S(   N(   t   NoneRC   (   t   datat   nt   mu(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _momentl  s    c   
      C` s  |  d k r d S|  d k rC | d  k r: | d |  } q| } nz|  d k r | d  k sg | d  k ry | d |  } q| | | } n3|  d k r| d  k s | d  k s | d  k r | d |  } q| t j | d  } | d | | | | | } n |  d k r| d  k s?| d  k s?| d  k s?| d  k rQ| d |  } q| d | d	 }	 | t j | d  } |	 d | | d
 | | | | | | | } n | |  |  } | S(   Ni    g      ?i   i   i   g      ?i   g      @g       @i   (   RS   t   npt   power(
   RU   RV   t   mu2t   g1t   g2t   moment_funct   argst   valt   mu3t   mu4(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _moment_from_statsr  s.    	$!05c         C` sW   t  j |   }  |  j   } |  | d j   } |  | d j   } | t  j | d  S(   s8   
    skew is third central moment / variance**(1.5)
    i   i   g      ?(   RX   R   RC   RY   (   RT   RV   t   m2t   m3(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _skew  s
    c         C` sS   t  j |   }  |  j   } |  | d j   } |  | d j   } | | d d S(   s=   
    kurtosis is fourth central moment / variance**2 - 3
    i   i   i   (   RX   R   RC   (   RT   RV   Rc   t   m4(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt	   _kurtosis  s
    t	   rv_frozenc           B` s   e  Z d    Z e d    Z e j d    Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d d d	  Z d
   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d e d  Z RS(   c         O` s{   | |  _  | |  _ | j | j     |  _ |  j j | |   \ } } } |  j j |   |  j j |  j j |  _ |  _ d  S(   N(	   R^   t   kwdst	   __class__t   _updated_ctor_paramt   distt   _parse_argst	   _argcheckt   at   b(   t   selfRl   R^   Ri   t   shapest   _(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   __init__  s    		c         C` s
   |  j  j S(   N(   Rl   t   _random_state(   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   random_state  s    c         C` s   t  |  |  j _ d  S(   N(   R
   Rl   Ru   (   Rq   t   seed(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRv     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R5   R^   Ri   (   Rq   t   x(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR5     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R6   R^   Ri   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR6     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R7   R^   Ri   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR7     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R8   R^   Ri   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR8     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R;   R^   Ri   (   Rq   t   q(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR;     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R<   R^   Ri   (   Rq   Ry   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<     s    c         C` s@   |  j  j   } | j i | d 6| d 6 |  j j |  j |   S(   Nt   sizeRv   (   Ri   t   copyt   updateRl   R4   R^   (   Rq   Rz   Rv   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR4     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R9   R^   Ri   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR9     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R:   R^   Ri   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR:     s    t   mvc         C` s9   |  j  j   } | j i | d 6 |  j j |  j |   S(   Nt   moments(   Ri   R{   R|   Rl   R=   R^   (   Rq   R~   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR=     s    c         C` s   |  j  j |  j |  j   S(   N(   Rl   RF   R^   Ri   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRF     s    c         C` s   |  j  j |  j |  j   S(   N(   Rl   RC   R^   Ri   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRC     s    c         C` s   |  j  j |  j |  j   S(   N(   Rl   RE   R^   Ri   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRE     s    c         C` s   |  j  j |  j |  j   S(   N(   Rl   RD   R^   Ri   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRD     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   R@   R^   Ri   (   Rq   RU   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR@     s    c         C` s   |  j  j |  j |  j   S(   N(   Rl   R>   R^   Ri   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR>     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   RN   R^   Ri   (   Rq   t   k(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRN     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   RO   R^   Ri   (   Rq   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRO     s    c         C` s   |  j  j | |  j |  j  S(   N(   Rl   RB   R^   Ri   (   Rq   t   alpha(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRB     s    c   	   	   K` s   |  j  j |  j |  j   \ } } } t |  j  t  rX |  j  j | | | | | | |  S|  j  j | | | | | | | |  Sd  S(   N(   Rl   Rm   R^   Ri   t
   isinstanceRQ   RA   (	   Rq   R,   t   lbt   ubt   conditionalRi   Ro   t   loct   scale(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRA     s
    $"N(   t   __name__t
   __module__Rt   t   propertyRv   t   setterR5   R6   R7   R8   R;   R<   RS   R4   R9   R:   R=   RF   RC   RE   RD   R@   R>   RN   RO   RB   t   FalseRA   (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRh     s.   																		c         G` s]   t  j |   } t | t  s* | g } n  |  |  k } g  | D] } t  j |  | |  ^ q= S(   s  Return the sequence of ravel(args[i]) where ravel(condition) is
    True in 1D.

    Examples
    --------
    >>> import numpy as np
    >>> rand = np.random.random_sample
    >>> A = rand((4, 5))
    >>> B = 2
    >>> C = rand((1, 5))
    >>> cond = np.ones(A.shape)
    >>> [A1, B1, C1] = argsreduce(cond, A, B, C)
    >>> B1.shape
    (20,)
    >>> cond[2,:] = 0
    >>> [A2, B2, C2] = argsreduce(cond, A, B, C)
    >>> B2.shape
    (15,)

    (   RX   t
   atleast_1dR   t   listt   extract(   t   condR^   t   newargst
   expand_arrt   arr1(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt
   argsreduce
  s
    s  
def _parse_args(self, %(shape_arg_str)s %(locscale_in)s):
    return (%(shape_arg_str)s), %(locscale_out)s

def _parse_args_rvs(self, %(shape_arg_str)s %(locscale_in)s, size=None):
    return self._argcheck_rvs(%(shape_arg_str)s %(locscale_out)s, size=size)

def _parse_args_stats(self, %(shape_arg_str)s %(locscale_in)s, moments='mv'):
    return (%(shape_arg_str)s), %(locscale_out)s, moments
c         C` s|   | d d } t  j |   t  j |  } } t | d |  |  d | | d } | t  j t | | |  d  7} | S(   Ng       @g      ?g      ?i   (   RX   R   R   R   R   (   Rx   t   dft   nct   df2t   xst   nst   res(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _ncx2_log_pdf5  s
    '$c         C` s   t  j t |  | |   S(   N(   RX   t   expR   (   Rx   R   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt	   _ncx2_pdf@  s    c         C` s   t  |  | |  S(   N(   R   (   Rx   R   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt	   _ncx2_cdfD  s    t
   rv_genericc           B` sR  e  Z d  Z d! d  Z e d    Z e j d    Z d   Z d   Z	 d   Z
 d! d  Z d! d! d! d d	  Z d
   Z d   Z e j e _ d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d    Z# RS("   s^   Class which encapsulates common functionality between rv_discrete
    and rv_continuous.

    c         C` sX   t  t |   j   t |  j  } | d d  k	 p? d | d k |  _ t |  |  _ d  S(   Ni   R~   i    (	   t   superR   Rt   t   _getargspect   _statsRS   t   _stats_has_momentsR
   Ru   (   Rq   Rw   t   sign(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRt   M  s
    c         C` s   |  j  S(   sY   Get or set the RandomState object for generating random variates.

        This can be either None or an existing RandomState object.

        If None (or np.random), use the RandomState singleton used by np.random.
        If already a RandomState instance, use it.
        If an int, use a new RandomState instance seeded with seed.

        (   Ru   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRv   V  s    c         C` s   t  |  |  _ d  S(   N(   R
   Ru   (   Rq   Rw   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRv   c  s    c         C` s   |  j    |  j f S(   N(   Rk   Ru   (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   __getstate__g  s    c         C` s&   | \ } } |  j  |   | |  _ |  S(   N(   Rt   Ru   (   Rq   t   statet
   ctor_paramt   r(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   __setstate__j  s    	c         C` sN  |  j  r t |  j  t  s* t d   n  |  j  j d d  j   } x5| D]E } t j |  rp t d   n  t	 j
 d |  sL t d   qL qL Wn g  } x | D] } t |  } | j d }	 |	 r | j |	  | j d k	 r t d   n  | j d k	 rt d	   n  | j d k	 r4t d
   q4q q W| rw| d } x2 | D]! }
 |
 | k rOt d   qOqOWn g  } | rd j |  d n d } t d | d | d |  } i  } t t | |  x: d d d g D]) } t |  | t | | |  |  j   qW| r d j |  n d |  _  t |  d  sJt |  |  _ n  d S(   s!  Construct the parser for the shape arguments.

        Generates the argument-parsing functions dynamically and attaches
        them to the instance.
        Is supposed to be called in __init__ of a class for each distribution.

        If self.shapes is a non-empty string, interprets it as a
        comma-separated list of shape parameters.

        Otherwise inspects the call signatures of `meths_to_inspect`
        and constructs the argument-parsing functions from these.
        In this case also sets `shapes` and `numargs`.
        s   shapes must be a string.t   ,t    s"   keywords cannot be used as shapes.s   ^[_a-zA-Z][_a-zA-Z0-9]*$s'   shapes must be valid python identifiersi   s+   *args are not allowed w/out explicit shapess,   **kwds are not allowed w/out explicit shapess#   defaults are not allowed for shapesi    s!   Shape arguments are inconsistent.s   , R3   t   shape_arg_strt   locscale_int   locscale_outRm   t   _parse_args_statst   _parse_args_rvst   numargsN(   Rr   R   R   t	   TypeErrort   replacet   splitt   keywordt	   iskeywordt   SyntaxErrort   ret   matchR   R^   t   appendt   varargsRS   t   keywordst   defaultst   joint   dictR   t   parse_arg_templatet   setattrR/   Rj   t   hasattrt   lenR   (   Rq   t   meths_to_inspectR   R   Rr   t   fieldt   shapes_listt   metht   shapes_argsR^   t   itemt
   shapes_strt   dctR   t   name(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _construct_argparserp  sT    	
		c         C` s  | j    } |  j p d | d <|  j p+ d | d <| d k rG d } n  d j d   | D  } | | d <|  j pv d | d <|  j r |  j d	 k r | d c d
 7<n  |  j r d |  j | f | d <n
 d | d <|  j d k rx1 d d g D]  } | | j d d  | | <q Wn  xV t d  D]H } |  j d k rU|  j j d d  |  _ n  t	 j
 |  j |  |  _ q%W|  j j d d  j d d  |  _ d S(   s;   Construct the instance docstring with string substitutions.t   distnameR   R3   Rr   s   , c         s` s   |  ] } d  | Vq d S(   s   %.3gN(    (   t   .0R_   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pys	   <genexpr>  s    t   valst   shapes_i   R   s   >>> %s = %st   set_vals_stmtRK   RL   s-   
%(shapes)s : array_like
    shape parametersi   s   %(shapes)s, s   (, t   (s   , )t   )N(    (   R{   R   Rr   RS   R   R   R   t   ranget   __doc__R   t	   docformat(   Rq   t   docdictt   shapes_valst   tempdictR   R   t   i(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _construct_doc  s,    	
	

t
   continuousc         C` s   | d	 k r d } n  | d	 k r* d } n  | j d  rF | d } n  d j d | | f d t d | d g  |  _ |  j |  d	 S(
   s7   Construct instance docstring from the default template.t   AR3   s   

i   s   %s %s random variable.s   

%(before_notes)s
R1   s   
%(example)sN(   RS   t
   startswithR   t
   docheadersR   R   (   Rq   t   longnamet   extradocR   t   discrete(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _construct_default_doc  s    		
c         O` s   t  |  | |  S(   s  Freeze the distribution for the given arguments.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution.  Should include all
            the non-optional arguments, may include ``loc`` and ``scale``.

        Returns
        -------
        rv_frozen : rv_frozen instance
            The frozen distribution.

        (   Rh   (   Rq   R^   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   freeze  s    c         O` s   |  j  | |   S(   N(   R   (   Rq   R^   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   __call__  s    c         O` s   d S(   N(   NNNN(   RS   (   Rq   R^   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR     s    c         G` s5   t  j d d  } |  j | |  } t  j |   | S(   Nt   allt   ignore(   RX   t   seterrt   generic_moment(   Rq   RU   R^   t   olderrR   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _munp  s    c         O` s[  | j  d d   } t j |   } d   } g  | D] } | |  ^ q1 } | d j } | d j } | d  k rx | }	 n t t j |   }	 | t |	  }
 |
 d k  r d |
 | } n |
 d k r d	 |
 |	 }	 n  t	 g  t
 | |	  D]$ \ } } | d k p| | k ^ q  } | s-t d   n  | d  } | d } | d } | | | |	 f S(
   NRz   c         S` s7   x0 |  j  d k r2 |  j d d k r2 |  d }  q W|  S(   Ni    i   (   t   ndimR   (   Ro   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   squeeze_left!  s    %i    i   s:   size does not match the broadcast shape of the parameters.ii(   i   (   i   (   t   getRS   RX   t   broadcast_arraysR   R   t   tupleR   R   R   t   zipt
   ValueError(   Rq   R^   t   kwargsRz   t	   all_bcastR   Ro   t   bcast_shapet
   bcast_ndimt   size_t   ndifft   bcdimt   szdimt   okt   param_bcastt	   loc_bcastt   scale_bcast(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _argcheck_rvs  s,    		:


c         G` s6   d } x) | D]! } t  | t |  d k  } q W| S(   s   Default check for correct values on args and keywords.

        Returns condition array of 1's where arguments are correct and
         0's where they are not.

        i   i    (   R   R#   (   Rq   R^   R   t   arg(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRn   ]  s    c         C` s   |  j  | k | |  j k @S(   N(   Ro   Rp   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _support_maski  s    c         C` s   |  j  | k  | |  j k  @S(   N(   Ro   Rp   (   Rq   Rx   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _open_support_maskl  s    c         G` s+   |  j  j |  j  } |  j | |  } | S(   N(   Ru   t   random_samplet   _sizet   _ppf(   Rq   R^   t   Ut   Y(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _rvso  s    c         G` s   t  |  j | |   S(   N(   R   t   _cdf(   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _logcdfz  s    c         G` s   d |  j  | |  S(   Ng      ?(   R	  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _sf}  s    c         G` s   t  |  j | |   S(   N(   R   R  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _logsf  s    c         G` s   |  j  | |  S(   N(   t   _ppfvec(   Rq   Ry   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s    c         G` s   |  j  d | |  S(   Ng      ?(   R  (   Rq   Ry   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _isf  s    c         O` s@  | j  d d  } | j  d d  } |  j | |   \ } } } } t |  j |   | d k  } t j |  s~ t d   n  t j | d k  r | t | d  S| d k	 r |  j	 }	 t
 |  |  _	 n  | |  _ |  j |   }
 |
 | | }
 | d k	 r	|	 |  _	 n  | r<| d k r*t |
  }
 q<|
 j t  }
 n  |
 S(   sj  
        Random variates of given type.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).
        scale : array_like, optional
            Scale parameter (default=1).
        size : int or tuple of ints, optional
            Defining number of random variates (default is 1).
        random_state : None or int or ``np.random.RandomState`` instance, optional
            If int or RandomState, use it for drawing the random variates.
            If None, rely on ``self.random_state``.
            Default is None.

        Returns
        -------
        rvs : ndarray or scalar
            Random variates of given `size`.

        R   Rv   i    s   Domain error in arguments.t   dN(    (   t   popRS   R   R   Rn   RX   R   R   R   Ru   R
   R  R  t   intt   astype(   Rq   R^   Ri   R   t   rndmR   R   Rz   R   t   random_state_savedR   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR4     s*    		c      	   O` s)  |  j  | |   \ } } } } t t | | f  \ } } t t t |   } |  j |   | d k @| | k @} g  } t t |  |  j  } t j	 |  rt
 | | | | f  }	 |	 d |	 d |	 d  } } }	 |  j r|  j |	 i | d 6  \ }
 } } } n |  j |	   \ }
 } } } | d k r8d } nF | d k rY|  j d |	  } n  | d k r~| t j | d  } n  d | k r|
 d k r|  j d |	  }
 n  | j   } t | | |
 | |  | j |  n  d	 | k r| d k rV|  j d |	  } |
 d k r*|  j d |	  }
 n  | |
 |
 } t j |
  rVt j } qVn  | j   } t | | | | |  | j |  n  d
 | k r|| d k rP|  j d |	  } |
 d k r|  j d |	  }
 n  | d k r|  j d |	  } | |
 |
 } n  t j d d  5 | d |
 | |
 d } | t j | d  } Wd QXn  | j   } t | | |  | j |  n  d | k r| d k r|  j d |	  } |
 d k r|  j d |	  }
 n  | d k r|  j d |	  } | |
 |
 } n  | d k rJ|  j d |	  } t j d d   | d |
 | |
 d } Wd QXn  t j d d  A | d |
 | d |
 |
 | |
 d } | | d d } Wd QXn  | j   } t | | |  | j |  qn0 g  } x' | D] } | j   } | j |  qWt |  d k r| d St |  Sd S(   s  
        Some statistics of the given RV.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional (continuous RVs only)
            scale parameter (default=1)
        moments : str, optional
            composed of letters ['mvsk'] defining which moments to compute:
            'm' = mean,
            'v' = variance,
            's' = (Fisher's) skew,
            'k' = (Fisher's) kurtosis.
            (default is 'mv')

        Returns
        -------
        stats : sequence
            of requested moments.

        i    iiR~   i   g      ?t   mi   t   vt   si   t   invalidR   NR   i   i   g       @g      @(   R   t   mapR#   R   Rn   t   valarrayR   t   badvalueRX   t   anyR   R   R   RS   R   RY   R{   R    R   R&   R%   t   errstateR   (   Rq   R^   Ri   R   R   R~   R   t   outputRK   t   goodargsRV   RZ   R[   R\   R`   t   out0t   mu2pt   mu3pt   mu4pRa   Rs   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR=     s    # 			#*c   	      O` s   |  j  | |   \ } } } t t | | f  \ } } t t t |   } |  j |   | d k @| | k @} t t |  d  } t | d | |  j  t	 | | |  } | d } | d } t | | |  j
 |   t |   | S(   s  
        Differential entropy of the RV.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).
        scale : array_like, optional  (continuous distributions only).
            Scale parameter (default=1).

        Notes
        -----
        Entropy is defined base `e`:

        >>> drv = rv_discrete(values=((0, 1), (0.5, 0.5)))
        >>> np.allclose(drv.entropy(), np.log(2.0))
        True

        i    R  i   (   Rm   R  R#   R   Rn   R   R   R    R  R   t
   vecentropyR   (	   Rq   R^   Ri   R   R   t   cond0R  R  t	   goodscale(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR>   ?  s    #

#c      	   O` s  |  j  | |   \ } } } |  j |   o3 | d k s: t St |  | k r[ t d   n  | d k  rv t d   n  d \ } } } }	 | d k r | d k  r |  j r i i d d 6d d 6d	 d
 6d d 6| d 6}
 n i  }
 |  j | |
   \ } } } }	 n  t | | | | |	 |  j	 |  } | d k r9| | | Sd } t
 |  t
 |  } xZ t |  D]L } t | | | | |	 |  j	 |  } | t | | d t | | | 7} qbW| | | | 7} | | | Sd S(   s  
        n-th order non-central moment of distribution.

        Parameters
        ----------
        n : int, n >= 1
            Order of moment.
        arg1, arg2, arg3,... : float
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        i    s   Moment must be an integer.s   Moment must be positive.i   R  i   R  i   t   vsi   t   vki   R~   t   exactN(   NNNN(   Rm   Rn   R$   R   R   RS   R   R   Rb   R   t   floatR   R   t   True(   Rq   RU   R^   Ri   R   R   RV   RZ   R[   R\   t   mdictR_   t   resultt   facR   t   valk(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR@   c  s.    	0!!!)c         O` s   |  j  d | |  S(   sr  
        Median of the distribution.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            Location parameter, Default is 0.
        scale : array_like, optional
            Scale parameter, Default is 1.

        Returns
        -------
        median : float
            The median of the distribution.

        See Also
        --------
        stats.distributions.rv_discrete.ppf
            Inverse of the CDF

        g      ?(   R;   (   Rq   R^   Ri   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRF     s    c         O` sF   d | d <|  j  | |   } t | t  rB | j d k rB | d S| S(   s  
        Mean of the distribution.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        mean : float
            the mean of the distribution

        R  R~   i    (    (   R=   R   R   R   (   Rq   R^   Ri   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRC     s
    
c         O` sF   d | d <|  j  | |   } t | t  rB | j d k rB | d S| S(   s  
        Variance of the distribution.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        var : float
            the variance of the distribution

        R  R~   i    (    (   R=   R   R   R   (   Rq   R^   Ri   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRE     s
    
c         O` s&   d | d <t  |  j | |    } | S(   s  
        Standard deviation of the distribution.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        std : float
            standard deviation of the distribution

        R  R~   (   R   R=   (   Rq   R^   Ri   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRD     s    
c         O` s   t  |  } t j | d k | d k  B r: t d   n  d | d } d | d } |  j | | |  } |  j | | |  } | | f S(   s  
        Confidence interval with equal areas around the median.

        Parameters
        ----------
        alpha : array_like of float
            Probability that an rv will be drawn from the returned range.
            Each value should be in the range [0, 1].
        arg1, arg2, ... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            location parameter, Default is 0.
        scale : array_like, optional
            scale parameter, Default is 1.

        Returns
        -------
        a, b : ndarray of float
            end-points of range that contain ``100 * alpha %`` of the rv's
            possible values.

        i   i    s'   alpha must be between 0 and 1 inclusiveg      ?i   (   R#   RX   R  R   R;   (   Rq   R   R^   Ri   t   q1t   q2Ro   Rp   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRB     s    N($   R   R   R   RS   Rt   R   Rv   R   R   R   R   R   R   R   R   R   R   R   Rn   R  R  R  R
  R  R  R  R  R4   R=   R>   R@   RF   RC   RE   RD   RB   (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR   H  sD   				P"					J										>	v	$	.				c           B` sd  e  Z d  Z d d$ d$ d d$ d$ d$ d$ d$ d$ d 
 Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d$ d  Z d   Z d   Z d   Z  d    Z! d!   Z" d$ d% d" d d$ d$ e# d#  Z$ RS(&   sQ  
    A generic continuous random variable class meant for subclassing.

    `rv_continuous` is a base class to construct specific distribution classes
    and instances for continuous random variables. It cannot be used
    directly as a distribution.

    Parameters
    ----------
    momtype : int, optional
        The type of generic moment calculation to use: 0 for pdf, 1 (default)
        for ppf.
    a : float, optional
        Lower bound of the support of the distribution, default is minus
        infinity.
    b : float, optional
        Upper bound of the support of the distribution, default is plus
        infinity.
    xtol : float, optional
        The tolerance for fixed point calculation for generic ppf.
    badvalue : float, optional
        The value in a result arrays that indicates a value that for which
        some argument restriction is violated, default is np.nan.
    name : str, optional
        The name of the instance. This string is used to construct the default
        example for distributions.
    longname : str, optional
        This string is used as part of the first line of the docstring returned
        when a subclass has no docstring of its own. Note: `longname` exists
        for backwards compatibility, do not use for new subclasses.
    shapes : str, optional
        The shape of the distribution. For example ``"m, n"`` for a
        distribution that takes two integers as the two shape arguments for all
        its methods. If not provided, shape parameters will be inferred from
        the signature of the private methods, ``_pdf`` and ``_cdf`` of the
        instance.
    extradoc :  str, optional, deprecated
        This string is used as the last part of the docstring returned when a
        subclass has no docstring of its own. Note: `extradoc` exists for
        backwards compatibility, do not use for new subclasses.
    seed : None or int or ``numpy.random.RandomState`` instance, optional
        This parameter defines the RandomState object to use for drawing
        random variates.
        If None (or np.random), the global np.random state is used.
        If integer, it is used to seed the local RandomState instance.
        Default is None.

    Methods
    -------
    rvs
    pdf
    logpdf
    cdf
    logcdf
    sf
    logsf
    ppf
    isf
    moment
    stats
    entropy
    expect
    median
    mean
    std
    var
    interval
    __call__
    fit
    fit_loc_scale
    nnlf

    Notes
    -----
    Public methods of an instance of a distribution class (e.g., ``pdf``,
    ``cdf``) check their arguments and pass valid arguments to private,
    computational methods (``_pdf``, ``_cdf``). For ``pdf(x)``, ``x`` is valid
    if it is within the support of a distribution, ``self.a <= x <= self.b``.
    Whether a shape parameter is valid is decided by an ``_argcheck`` method
    (which defaults to checking that its arguments are strictly positive.)

    **Subclassing**

    New random variables can be defined by subclassing the `rv_continuous` class
    and re-defining at least the ``_pdf`` or the ``_cdf`` method (normalized
    to location 0 and scale 1).

    If positive argument checking is not correct for your RV
    then you will also need to re-define the ``_argcheck`` method.

    Correct, but potentially slow defaults exist for the remaining
    methods but for speed and/or accuracy you can over-ride::

      _logpdf, _cdf, _logcdf, _ppf, _rvs, _isf, _sf, _logsf

    The default method ``_rvs`` relies on the inverse of the cdf, ``_ppf``,
    applied to a uniform random variate. In order to generate random variates
    efficiently, either the default ``_ppf`` needs to be overwritten (e.g.
    if the inverse cdf can expressed in an explicit form) or a sampling
    method needs to be implemented in a custom ``_rvs`` method.

    If possible, you should override ``_isf``, ``_sf`` or ``_logsf``.
    The main reason would be to improve numerical accuracy: for example,
    the survival function ``_sf`` is computed as ``1 - _cdf`` which can
    result in loss of precision if ``_cdf(x)`` is close to one.

    **Methods that can be overwritten by subclasses**
    ::

      _rvs
      _pdf
      _cdf
      _sf
      _ppf
      _isf
      _stats
      _munp
      _entropy
      _argcheck

    There are additional (internal and private) generic methods that can
    be useful for cross-checking and for debugging, but might work in all
    cases when directly called.

    A note on ``shapes``: subclasses need not specify them explicitly. In this
    case, `shapes` will be automatically deduced from the signatures of the
    overridden methods (`pdf`, `cdf` etc).
    If, for some reason, you prefer to avoid relying on introspection, you can
    specify ``shapes`` explicitly as an argument to the instance constructor.


    **Frozen Distributions**

    Normally, you must provide shape parameters (and, optionally, location and
    scale parameters to each call of a method of a distribution.

    Alternatively, the object may be called (as a function) to fix the shape,
    location, and scale parameters returning a "frozen" continuous RV object:

    rv = generic(<shape(s)>, loc=0, scale=1)
        `rv_frozen` object with the same methods but holding the given shape,
        location, and scale fixed

    **Statistics**

    Statistics are computed using numerical integration by default.
    For speed you can redefine this using ``_stats``:

     - take shape parameters and return mu, mu2, g1, g2
     - If you can't compute one of these, return it as None
     - Can also be defined with a keyword argument ``moments``, which is a
       string composed of "m", "v", "s", and/or "k".
       Only the components appearing in string should be computed and
       returned in the order "m", "v", "s", or "k"  with missing values
       returned as None.

    Alternatively, you can override ``_munp``, which takes ``n`` and shape
    parameters and returns the n-th non-central moment of the distribution.

    Examples
    --------
    To create a new Gaussian distribution, we would do the following:

    >>> from scipy.stats import rv_continuous
    >>> class gaussian_gen(rv_continuous):
    ...     "Gaussian distribution"
    ...     def _pdf(self, x):
    ...         return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
    >>> gaussian = gaussian_gen(name='gaussian')

    ``scipy.stats`` distributions are *instances*, so here we subclass
    `rv_continuous` and create an instance. With this, we now have
    a fully functional distribution with all relevant methods automagically
    generated by the framework.

    Note that above we defined a standard normal distribution, with zero mean
    and unit variance. Shifting and scaling of the distribution can be done
    by using ``loc`` and ``scale`` parameters: ``gaussian.pdf(x, loc, scale)``
    essentially computes ``y = (x - loc) / scale`` and
    ``gaussian._pdf(y) / scale``.

    i   g+=c         C` s  t  t |   j |
  t d | d | d | d | d | d | d | d | d	 |	 d
 |
  
|  _ | d  k rs t } n  | d  k r d } n  | |  _ | |  _ | |  _	 | |  _
 | d  k r t |  _	 n  | d  k r t |  _
 n  | |  _ | |  _ | |  _ |  j d |  j |  j g d d d d  t |  j d d |  _ |  j d |  j _ t |  j d d |  _ t |  j d d |  _ |  j d |  j _ |	 |  _ | d k rt |  j d d |  _ n t |  j d d |  _ |  j d |  j _ | d  k r!| d d k rd } n d } | | } n  t j  j! d k  r|  j" d  k rg|  j# d | d	 |	 d t$ d d  qt t%  } |  j& t$ | j' |  j   n  d  S(   Nt   momtypeRo   Rp   t   xtolR  R   R   Rr   R   Rw   t   DistributionR   R   s   loc=0, scale=1R   s
   loc, scalet   otypesR  i   i    t
   aeiouAEIOUs   An s   A i   R   R   R   (   R6  ((   R   RP   Rt   R   t   _ctor_paramRS   R$   R  R   Ro   Rp   R%   R3  t   moment_typeRr   R   t   _pdfR	  R"   t   _ppf_singleR  R   t   nint   _entropyR$  t   _cdf_singlet   _cdfvecR   t   _mom0_scR   t   _mom1_sct   syst   flagsR   R   R   R   R   R   R   (   Rq   R2  Ro   Rp   R3  R  R   R   Rr   R   Rw   t   hstrR   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRt     s\    											
c         C` sn   |  j  j   } |  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <| S(   s    Return the current version of _ctor_param, possibly updated by user.

            Used by freezing and pickling.
            Keep this in sync with the signature of __init__.
        Ro   Rp   R3  R  R   Rr   R   (	   R7  R{   Ro   Rp   R3  R  R   Rr   R   (   Rq   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRk     s    c         G` s   |  j  | f |   | S(   N(   R7   (   Rq   Rx   Ry   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _ppf_to_solve*  s    c         G` s   d  } } |  j t j k r) |  j } n  |  j t j k  rG |  j } n  d } | s d | } x2 |  j | | |  d k r | } | | 9} q` Wn  | s | } x2 |  j | | |  d k  r | } | | 9} q Wn  t j |  j | | d | f | d |  j S(   Ng      $@g      g        R^   R3  (	   RS   Ro   RX   R%   Rp   RD  R   t   brentqR3  (   Rq   Ry   R^   t   leftt   rightt   factor(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR:  -  s$    

c         G` s   | | |  j  | |  S(   N(   R5   (   Rq   Rx   R  R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _mom_integ0F  s    c         G` s-   t  j |  j |  j |  j d | f | d S(   NR^   i    (   R   t   quadRI  Ro   Rp   (   Rq   R  R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR?  I  s    c         G` s   |  j  | |  | S(   N(   R;   (   Rq   Ry   R  R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _mom_integ1N  s    c         G` s'   t  j |  j d d d | f | d S(   Ni    i   R^   (   R   RJ  RK  (   Rq   R  R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR@  Q  s    c      	   G` s"   t  |  j | d d d | d d S(   Nt   dxgh㈵>R^   t   orderi   (   R   R	  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR9  T  s    c         G` s   t  |  j | |   S(   N(   R   R9  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _logpdfX  s    c         G` s#   t  j |  j |  j | d | d S(   NR^   i    (   R   RJ  R9  Ro   (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR=  [  s    c         G` s   |  j  | |  S(   N(   R>  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR	  ^  s    c         O` s}  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | | @}	 t
 t |	  |  }
 t |
 d | t j |  |  j  t j |	  rbt |	 | f | | f  } | d | d  } } t |
 |	 |  j |   |  n  |
 j d k ry|
 d S|
 S(   sM  
        Probability density function at x of the given RV.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        pdf : ndarray
            Probability density function evaluated at x

        t   dtypei    i   i(    (   Rm   R  R#   R   RX   t   find_common_typeRO  t   float64Rn   R  R   R   R   t   isnanR  R  R   R    R9  R   (   Rq   Rx   R^   Ri   R   R   t   dtypR%  t   cond1R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR5   d  s"    !
$ c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | | @}	 t
 t |	  |  }
 |
 j t  t |
 d | t j |  |  j  t j |	  rut |	 | f | | f  } | d | d  } } t |
 |	 |  j |   t |   n  |
 j d k r|
 d S|
 S(   s  
        Log of the probability density function at x of the given RV.

        This uses a more numerically accurate calculation if available.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        logpdf : array_like
            Log of the probability density function evaluated at x

        RO  i    i   i(    (   Rm   R  R#   R   RX   RP  RO  RQ  Rn   R  R(   R   t   fillR'   R   RR  R  R  R   R    RN  R   R   (   Rq   Rx   R^   Ri   R   R   RS  R%  RT  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR6     s$    !
$&c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | |  j
 k | @}	 | | @}
 t t |
  |  } t | d | t j |  |  j  t | |	 d  t j |
  ret |
 | f |  } t | |
 |  j |    n  | j d k r|| d S| S(   sR  
        Cumulative distribution function of the given RV.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        cdf : ndarray
            Cumulative distribution function evaluated at `x`

        RO  i    i   g      ?(    (   Rm   R  R#   R   RX   RP  RO  RQ  Rn   R  Rp   R   R   R    RR  R  R  R   R	  R   (   Rq   Rx   R^   Ri   R   R   RS  R%  RT  t   cond2R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR7     s$    !
$c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | |  j
 k | @}	 | | @}
 t t |
  |  } | j t  t | d | | | k t j |  |  j  t | |	 d  t j |
  r|t |
 | f |  } t | |
 |  j |    n  | j d k r| d S| S(   sq  
        Log of the cumulative distribution function at x of the given RV.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        logcdf : array_like
            Log of the cumulative distribution function evaluated at x

        RO  i    i   g        (    (   Rm   R  R#   R   RX   RP  RO  RQ  Rn   R  Rp   R(   R   RU  R'   R    RR  R  R  R   R
  R   (   Rq   Rx   R^   Ri   R   R   RS  R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR8     s&    !
.c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | | |  j
 k @}	 | | @}
 t t |
  |  } t | d | t j |  |  j  t | |	 d  t j |
  ret |
 | f |  } t | |
 |  j |    n  | j d k r|| d S| S(   sE  
        Survival function (1 - `cdf`) at x of the given RV.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        sf : array_like
            Survival function evaluated at x

        RO  i    i   g      ?(    (   Rm   R  R#   R   RX   RP  RO  RQ  Rn   R  Ro   R   R   R    RR  R  R  R   R  R   (   Rq   Rx   R^   Ri   R   R   RS  R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR9   
  s$    !
$c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } t j | j t j g g   } t j | | | d | } |  j |   | d k @} |  j	 |  | d k @} | | |  j
 k @}	 | | @}
 t t |
  |  } | j t  t | d | t j |  |  j  t | |	 d  t j |
  rrt |
 | f |  } t | |
 |  j |    n  | j d k r| d S| S(   s  
        Log of the survival function of the given RV.

        Returns the log of the "survival function," defined as (1 - `cdf`),
        evaluated at `x`.

        Parameters
        ----------
        x : array_like
            quantiles
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        logsf : ndarray
            Log of the survival function evaluated at `x`.

        RO  i    i   g        (    (   Rm   R  R#   R   RX   RP  RO  RQ  Rn   R  Ro   R(   R   RU  R'   R    RR  R  R  R   R  R   (   Rq   Rx   R^   Ri   R   R   RS  R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR:   3  s&    !
$c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } |  j |   | d k @| | k @} d | k  | d k  @} | | d k @} | | d k @}	 | | @}
 t t |
  d |  j } |  j | | } |  j	 | | } t
 | | t | |  d  t
 | |	 t |	 |  d  t j |
  rt |
 | f | | | f  } | d | d | d  } } } t
 | |
 |  j |   | |  n  | j d k r| d S| S(   st  
        Percent point function (inverse of `cdf`) at q of the given RV.

        Parameters
        ----------
        q : array_like
            lower tail probability
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        x : array_like
            quantile corresponding to the lower tail probability q.

        i    i   t   valueii(    (   Rm   R  R#   R   Rn   R  R   R  Ro   Rp   R    R   RX   R  R  R   (   Rq   Ry   R^   Ri   R   R   R%  RT  RV  t   cond3R   R  t   lower_boundt   upper_boundR  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR;   `  s(    !#
  $c         O` s  |  j  | |   \ } } } t t | | | f  \ } } } t t t |   } |  j |   | d k @| | k @} d | k  | d k  @} | | d k @} | | d k @}	 | | @}
 t t |
  d |  j } |  j | | } |  j	 | | } t
 | | t | |  d  t
 | |	 t |	 |  d  t j |
  rt |
 | f | | | f  } | d | d | d  } } } t
 | |
 |  j |   | |  n  | j d k r| d S| S(   s}  
        Inverse survival function (inverse of `sf`) at q of the given RV.

        Parameters
        ----------
        q : array_like
            upper tail probability
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            location parameter (default=0)
        scale : array_like, optional
            scale parameter (default=1)

        Returns
        -------
        x : ndarray or scalar
            Quantile corresponding to the upper tail probability q.

        i    i   RW  ii(    (   Rm   R  R#   R   Rn   R  R   R  Ro   Rp   R    R   RX   R  R  R   (   Rq   Ry   R^   Ri   R   R   R%  RT  RV  RX  R   R  RY  RZ  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<     s(    !#
  $c         G` s    t  j |  j | |  d d S(   Nt   axisi    (   RX   t   sumRN  (   Rq   Rx   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _nnlf  s    c         C` sU   y( | d } | d } t  | d   } Wn t k
 rG t d   n X| | | f S(   Niis   Not enough input arguments.(   R   t
   IndexErrorR   (   Rq   t   thetaR   R   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _unpack_loc_scale  s    

c         C` s   |  j  |  \ } } } |  j |   s4 | d k r8 t St | | |  } t |  t |  } t j |  j |   r t S|  j	 | |  | S(   s   Return negative loglikelihood function.

        Notes
        -----
        This is ``-sum(log pdf(x, theta), axis=0)`` where `theta` are the
        parameters (including loc and scale).
        i    (
   R`  Rn   R%   R#   R   R   RX   R  R  R]  (   Rq   R_  Rx   R   R   R^   t   n_log_scale(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   nnlf  s    c         C` s   |  j  |  } t j | d d } | d k rH t | |  d } n  |  j | |  } t j |  } | t j | d d 7} | d k r | t t  d } t j | | d d | St j | d d S(   NR[  i    id   (	   R  RX   t   count_nonzeroR   RN  t   isfiniteR\  R   R)   (   Rq   Rx   R^   R%  t   n_badR6   t   finite_logpdft   penalty(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _nnlf_and_penalty  s    c         C` sv   |  j  |  \ } } } |  j |   s4 | d k r8 t St | | |  } t |  t |  } |  j | |  | S(   s    Return penalized negative loglikelihood function,
        i.e., - sum (log pdf(x, theta), axis=0) + penalty
           where theta are the parameters (including loc and scale)
        i    (   R`  Rn   R%   R#   R   R   Rh  (   Rq   R_  Rx   R   R   R^   Ra  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _penalized_nnlf  s    c         C` sB   | d  k r d |  j } n  |  j | |  \ } } | | | f S(   Ng      ?(   g      ?(   RS   R   t   _fit_loc_scale_support(   Rq   RT   R^   R   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt	   _fitstart  s    c         ` s   j  r  j  j d d  j   } x t |  D]z \ } } | j d | d   pf | j d | d   } | d  k	 r1 d | } | | k r t d |   q | | | <q1 q1 Wn  t    t     g   g  t	   d  D] } d | ^ q d d	 g }	 g  }
 xZ t |	  D]L \ } } | | k rO j
 |  | j |   | <q|
 j
  |  qWt   d
 k r j } d   nH t     k rt d   n     f d       f d   } |
 |   f S(   NR   R   t   ft   fix_s   f%ds   Duplicate entry for %s.i   t   floct   fscalei    s3   All parameters fixed. There is nothing to optimize.c         ` sH   d } x; t     D]- } |  k r | | |  | <| d 7} q q W|  S(   Ni    i   (   R   (   R^   R_  R   RU   (   t   Nargst   fixedn(    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   restore  s    c         ` s       |   }  j  | |  S(   N(   Ri  (   R_  Rx   t   newtheta(   R^   Rr  Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR,   '  s    (   Rr   R   R   t	   enumerateR  RS   R   R   R   R   R   Ri  (   Rq   R^   Ri   Rr   t   jR  R_   t   keyRU   t   namest   x0R,   (    (   Rp  R^   Rq  Rr  Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _reduce_func  s8    	,
1		c         O` s  t  |  } | |  j k r* t d   n  d g d } | |  j k  s_ d | k o[ d | k r |  j |  } | | | d !7} n  | j d | d  } | j d | d  } | | | f 7} |  j | |  \ } }	 }
 } | j d t j  } t	 |  rxt
 | t  rx| j d  s)d | } n  | d k r>d	 } n  y t t |  } Wqxt k
 rtt d
 |   qxXn  | rt d |   n  | |	 | d t |  f d d } |
 d k	 r|
 | |  } n  t |  } | S(   s  
        Return MLEs for shape (if applicable), location, and scale
        parameters from data.

        MLE stands for Maximum Likelihood Estimate.  Starting estimates for
        the fit are given by input arguments; for any arguments not provided
        with starting estimates, ``self._fitstart(data)`` is called to generate
        such.

        One can hold some parameters fixed to specific values by passing in
        keyword arguments ``f0``, ``f1``, ..., ``fn`` (for shape parameters)
        and ``floc`` and ``fscale`` (for location and scale parameters,
        respectively).

        Parameters
        ----------
        data : array_like
            Data to use in calculating the MLEs.
        args : floats, optional
            Starting value(s) for any shape-characterizing arguments (those not
            provided will be determined by a call to ``_fitstart(data)``).
            No default value.
        kwds : floats, optional
            Starting values for the location and scale parameters; no default.
            Special keyword arguments are recognized as holding certain
            parameters fixed:

            - f0...fn : hold respective shape parameters fixed.
              Alternatively, shape parameters to fix can be specified by name.
              For example, if ``self.shapes == "a, b"``, ``fa``and ``fix_a``
              are equivalent to ``f0``, and ``fb`` and ``fix_b`` are
              equivalent to ``f1``.

            - floc : hold location parameter fixed to specified value.

            - fscale : hold scale parameter fixed to specified value.

            - optimizer : The optimizer to use.  The optimizer must take ``func``,
              and starting position as the first two arguments,
              plus ``args`` (for extra arguments to pass to the
              function to be optimized) and ``disp=0`` to suppress
              output as keyword arguments.

        Returns
        -------
        mle_tuple : tuple of floats
            MLEs for any shape parameters (if applicable), followed by those
            for location and scale. For most random variables, shape statistics
            will be returned, but there are exceptions (e.g. ``norm``).

        Notes
        -----
        This fit is computed by maximizing a log-likelihood function, with
        penalty applied for samples outside of range of the distribution. The
        returned answer is not guaranteed to be the globally optimal MLE, it
        may only be locally optimal, or the optimization may fail altogether.

        Examples
        --------

        Generate some data to fit: draw random variates from the `beta`
        distribution

        >>> from scipy.stats import beta
        >>> a, b = 1., 2.
        >>> x = beta.rvs(a, b, size=1000)

        Now we can fit all four parameters (``a``, ``b``, ``loc`` and ``scale``):

        >>> a1, b1, loc1, scale1 = beta.fit(x)

        We can also use some prior knowledge about the dataset: let's keep
        ``loc`` and ``scale`` fixed:

        >>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
        >>> loc1, scale1
        (0, 1)

        We can also keep shape parameters fixed by using ``f``-keywords. To
        keep the zero-th shape parameter ``a`` equal 1, use ``f0=1`` or,
        equivalently, ``fa=1``:

        >>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
        >>> a1
        1

        Not all distributions return estimates for the shape parameters.
        ``norm`` for example just returns estimates for location and scale:

        >>> from scipy.stats import norm
        >>> x = norm.rvs(a, b, size=1000, random_state=123)
        >>> loc1, scale1 = norm.fit(x)
        >>> loc1, scale1
        (0.92087172783841631, 2.0015750750324668)
        s   Too many input arguments.i   R   R   iit	   optimizert   fmin_t   fmins   %s is not a valid optimizers   Unknown arguments: %s.R^   t   dispi    N(   R   R   R   RS   Rk  R  Ry  R   R|  t   callableR   R   R   t   getattrt   AttributeErrorR   R   R   (   Rq   RT   R^   Ri   t   Nargt   startR   R   Rx  R,   Rr  Rz  R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR?   -  s:    `	$c         G` sc  t  j |  } |  j | |  \ } } |  j |   |  j |  j } } | | } | d k rg | | f S| | | } | | | }	 t  j |  }
 t  j |  } | |
 k  r | |	 k  r | | f S| |
 } d } | | } | t  j k  r|
 | | } | d | | } | | f S| t  j k r8|
 | | d f S| t  j k  rY| | | d f St	  d S(   s  
        Estimate loc and scale parameters from data accounting for support.

        Parameters
        ----------
        data : array_like
            Data to fit.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).

        Returns
        -------
        Lhat : float
            Estimated location parameter for the data.
        Shat : float
            Estimated scale parameter for the data.

        i    g?i   i   N(
   RX   R#   t   fit_loc_scaleRn   Ro   Rp   t   mint   maxR%   t   RuntimeError(   Rq   RT   R^   t   loc_hatt	   scale_hatRo   Rp   t   support_widtht   a_hatt   b_hatt   data_at   data_bt
   data_widtht
   rel_margint   margin(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRj    s2    





c   
      G` s   |  j  | i d d 6  \ } } t |  } | j   } | j   } t | |  } | | | }	 t j |	  sy d }	 n  t j |  o d | k  s d } n  |	 | f S(   s  
        Estimate loc and scale parameters from data using 1st and 2nd moments.

        Parameters
        ----------
        data : array_like
            Data to fit.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).

        Returns
        -------
        Lhat : float
            Estimated location parameter for the data.
        Shat : float
            Estimated scale parameter for the data.

        R}   R~   i    i   (   R=   R#   RC   RE   R   RX   Rd  (
   Rq   RT   R^   RV   RZ   t   tmpt   muhatt   mu2hatt   Shatt   Lhat(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s    		c   	      ` s      f d   } t  j d d  } t j |  j  j  d } t  j |   t  j |  sc | S j d d g    \ } } t  j  j  r | } n	  j } t  j  j  r | } n	  j } t j | | |  d Sd  S(   Nc         ` s    j  |     } t |  S(   N(   R9  R   (   Rx   R_   (   R^   Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   integ	  s    t   overR   i    g|=g      ?gA?(	   RX   R   R   RJ  Ro   Rp   RR  R;   R&   (	   Rq   R^   R  R   t   ht   lowt   uppt   uppert   lower(    (   R^   Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<  	  s    				i    c         ` s  i | d 6| d 6  j  |     d
 k rB   f d   }	 n     f d   }	 | d
 k rw |  j | } n  | d
 k r |  j | } n  | r  j | |    j | |   }
 n d }
 | | d <t j d d  } t j |	 | | |  d	 |
 } t j |   | S(   s
  Calculate expected value of a function with respect to the
        distribution by numerical integration.

        The expected value of a function ``f(x)`` with respect to a
        distribution ``dist`` is defined as::

                    ub
            E[f(x)] = Integral(f(x) * dist.pdf(x)),
                    lb

        where ``ub`` and ``lb`` are arguments and ``x`` has the ``dist.pdf(x)`` 
        distribution. If the bounds ``lb`` and ``ub`` correspond to the 
        support of the distribution, e.g. ``[-inf, inf]`` in the default 
        case, then the integral is the unrestricted expectation of ``f(x)``. 
        Also, the function ``f(x)`` may be defined such that ``f(x)`` is ``0`` 
        outside a finite interval in which case the expectation is 
        calculated within the finite range ``[lb, ub]``. 

        Parameters
        ----------
        func : callable, optional
            Function for which integral is calculated. Takes only one argument.
            The default is the identity mapping f(x) = x.
        args : tuple, optional
            Shape parameters of the distribution.
        loc : float, optional
            Location parameter (default=0).
        scale : float, optional
            Scale parameter (default=1).
        lb, ub : scalar, optional
            Lower and upper bound for integration. Default is set to the
            support of the distribution.
        conditional : bool, optional
            If True, the integral is corrected by the conditional probability
            of the integration interval.  The return value is the expectation
            of the function, conditional on being in the given interval.
            Default is False.

        Additional keyword arguments are passed to the integration routine.

        Returns
        -------
        expect : float
            The calculated expected value.

        Notes
        -----
        The integration behavior of this function is inherited from
        `scipy.integrate.quad`. Neither this function nor
        `scipy.integrate.quad` can verify whether the integral exists or is
        finite. For example ``cauchy(0).mean()`` returns ``np.nan`` and
        ``cauchy(0).expect()`` returns ``0.0``.

        Examples
        --------

        To understand the effect of the bounds of integration consider 
        >>> from scipy.stats import expon
        >>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
        0.6321205588285578

        This is close to 

        >>> expon(1).cdf(2.0) - expon(1).cdf(0.0)
        0.6321205588285577

        If ``conditional=True``

        >>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
        1.0000000000000002

        The slight deviation from 1 is due to numerical integration.
        R   R   c         ` s   |   j  |  |    S(   N(   R5   (   Rx   R^   (   t   lockwdsRq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   fun{	  s    c         ` s     |    j  |  |   S(   N(   R5   (   Rx   R^   (   R,   R  Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  ~	  s    g      ?R^   R   R   i    N(	   Rn   RS   Ro   Rp   R9   RX   R   R   RJ  (   Rq   R,   R^   R   R   R   R   R   Ri   R  t   invfacR   R   (    (   R,   R  Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRA   ,	  s&    K


 N(    (%   R   R   R   RS   Rt   Rk   RD  R:  RI  R?  RK  R@  R9  RN  R=  R	  R5   R6   R7   R8   R9   R:   R;   R<   R]  R`  Rb  Rh  Ri  Rk  Ry  R?   Rj  R  R<  R   RA   (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRP   "  sH   	?												(	+	)	*	)	-	-	-							4		A	 	c         ` s@       f d   } t  |  j  j  j d     j  S(   s,   Non-central moment of discrete distribution.c         ` s    t  j |     j |     S(   N(   RX   RY   t   _pmf(   Rx   (   R^   RU   Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  	  s    g      ?(   t   _expectRo   Rp   R;   t   inc(   Rq   RU   R^   R  (    (   R^   RU   Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _drv2_moment	  s    c   	      G` s  |  j  } |  j } t |  r t t d | d   } xR | |  j  k rS d } Pn  |  j | |  } | | k  r~ | d 7} q: Pq: Wn d } t |  r t t d | d   } x^ | |  j k r d } Pn  |  j | |  } | | k r | d 8} q Pq Wn |  j | |  } x | | k r%| S| | k r5| S| | d k r\| | k rU| S| Sn  t | | d  } |  j | |  } | | k  r| | k r| } n t d	   | } q| | k r| | k r| } n t d	   | } q| SqWd  S(
   Nid   i
   g      ?iig        i   g       @s   updating stopped, endless loop(   Rp   Ro   R&   R  R  R	  R  R  (	   Rq   Ry   R^   Rp   Ro   t   qbt   qat   ct   qc(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _drv2_ppfsingle	  s\    						c         C` s   t  |   }  d |  t j |  d d }  | d k rD t |   } n_ t  |  } t |  t |   k rw t d   n  d | t j | d d } t |  |  } t j | d d } | d k	 r | t |  } n  | S(   sY  Calculate the entropy of a distribution for given probability values.

    If only probabilities `pk` are given, the entropy is calculated as
    ``S = -sum(pk * log(pk), axis=0)``.

    If `qk` is not None, then compute the Kullback-Leibler divergence
    ``S = sum(pk * log(pk / qk), axis=0)``.

    This routine will normalize `pk` and `qk` if they don't sum to 1.

    Parameters
    ----------
    pk : sequence
        Defines the (discrete) distribution. ``pk[i]`` is the (possibly
        unnormalized) probability of event ``i``.
    qk : sequence, optional
        Sequence against which the relative entropy is computed. Should be in
        the same format as `pk`.
    base : float, optional
        The logarithmic base to use, defaults to ``e`` (natural logarithm).

    Returns
    -------
    S : float
        The calculated entropy.

    g      ?R[  i    s    qk and pk must have same length.N(	   R#   RX   R\  RS   R   R   R   R   R   (   t   pkt   qkt   baset   vect   S(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR>   	  s    c           B` s  e  Z d  Z d e d d d d d d d d d d  Z d e d d d d d d d d d d  Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d d d e d d d d 	 Z RS(   s+  
    A generic discrete random variable class meant for subclassing.

    `rv_discrete` is a base class to construct specific distribution classes
    and instances for discrete random variables. It can also be used
    to construct an arbitrary distribution defined by a list of support
    points and corresponding probabilities.

    Parameters
    ----------
    a : float, optional
        Lower bound of the support of the distribution, default: 0
    b : float, optional
        Upper bound of the support of the distribution, default: plus infinity
    moment_tol : float, optional
        The tolerance for the generic calculation of moments.
    values : tuple of two array_like, optional
        ``(xk, pk)`` where ``xk`` are integers with non-zero
        probabilities ``pk``  with ``sum(pk) = 1``.
    inc : integer, optional
        Increment for the support of the distribution.
        Default is 1. (other values have not been tested)
    badvalue : float, optional
        The value in a result arrays that indicates a value that for which
        some argument restriction is violated, default is np.nan.
    name : str, optional
        The name of the instance. This string is used to construct the default
        example for distributions.
    longname : str, optional
        This string is used as part of the first line of the docstring returned
        when a subclass has no docstring of its own. Note: `longname` exists
        for backwards compatibility, do not use for new subclasses.
    shapes : str, optional
        The shape of the distribution. For example "m, n" for a distribution
        that takes two integers as the two shape arguments for all its methods
        If not provided, shape parameters will be inferred from
        the signatures of the private methods, ``_pmf`` and ``_cdf`` of
        the instance.
    extradoc :  str, optional
        This string is used as the last part of the docstring returned when a
        subclass has no docstring of its own. Note: `extradoc` exists for
        backwards compatibility, do not use for new subclasses.
    seed : None or int or ``numpy.random.RandomState`` instance, optional
        This parameter defines the RandomState object to use for drawing
        random variates.
        If None, the global np.random state is used.
        If integer, it is used to seed the local RandomState instance.
        Default is None.

    Methods
    -------
    rvs
    pmf
    logpmf
    cdf
    logcdf
    sf
    logsf
    ppf
    isf
    moment
    stats
    entropy
    expect
    median
    mean
    std
    var
    interval
    __call__


    Notes
    -----

    This class is similar to `rv_continuous`. Whether a shape parameter is
    valid is decided by an ``_argcheck`` method (which defaults to checking
    that its arguments are strictly positive.)
    The main differences are:

    - the support of the distribution is a set of integers
    - instead of the probability density function, ``pdf`` (and the
      corresponding private ``_pdf``), this class defines the
      *probability mass function*, `pmf` (and the corresponding
      private ``_pmf``.)
    - scale parameter is not defined.

    To create a new discrete distribution, we would do the following:

    >>> from scipy.stats import rv_discrete
    >>> class poisson_gen(rv_discrete):
    ...     "Poisson distribution"
    ...     def _pmf(self, k, mu):
    ...         return exp(-mu) * mu**k / factorial(k)

    and create an instance::

    >>> poisson = poisson_gen(name="poisson")

    Note that above we defined the Poisson distribution in the standard form.
    Shifting the distribution can be done by providing the ``loc`` parameter
    to the methods of the instance. For example, ``poisson.pmf(x, mu, loc)``
    delegates the work to ``poisson._pmf(x-loc, mu)``.

    **Discrete distributions from a list of probabilities**

    Alternatively, you can construct an arbitrary discrete rv defined
    on a finite set of values ``xk`` with ``Prob{X=xk} = pk`` by using the
    ``values`` keyword argument to the `rv_discrete` constructor.

    Examples
    --------

    Custom made discrete distribution:

    >>> from scipy import stats
    >>> xk = np.arange(7)
    >>> pk = (0.1, 0.2, 0.3, 0.1, 0.1, 0.0, 0.2)
    >>> custm = stats.rv_discrete(name='custm', values=(xk, pk))
    >>>
    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.plot(xk, custm.pmf(xk), 'ro', ms=12, mec='r')
    >>> ax.vlines(xk, 0, custm.pmf(xk), colors='r', lw=4)
    >>> plt.show()

    Random number generation:

    >>> R = custm.rvs(size=100)

    i    g:0yE>i   c         C` s<   | d  k	 r" t t |   j t  St t |   j |   Sd  S(   N(   RS   R   RQ   t   __new__t	   rv_sample(   R.   Ro   Rp   R   R  t
   moment_tolt   valuesR  R   Rr   R   Rw   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  
  s    c         C` s  t  t |   j |  t d | d | d | d | d | d | d | d | d	 |	 d
 |
 d |  |  _ | d  k ry t } n  | |  _ | |  _ | |  _	 | |  _
 | |  _ t |  j d d |  _ t |  j  |  _ |	 |  _ | d  k	 r t d   n  |  j d |  j |  j g d d d d  t t d d } |  j d | _ t | |  t  |  _ t t d d } |  j d | _ t | |  t  |  _ |  j d |  j _ |  j | | |
  d  S(   NRo   Rp   R   R  R  R  R  R   Rr   R   Rw   R5  R  s.   rv_discrete.__init__(..., values != None, ...)R   R   s   loc=0R   s   loc, 1i   i   (   R   RQ   Rt   R   R7  RS   R$   R  Ro   Rp   R  R  R"   R=  R>  R<  R$  Rr   R   R   R  R	  R  R   R;  R/   R   R  R  t   _construct_docstrings(   Rq   Ro   Rp   R   R  R  R  R  R   Rr   R   Rw   t   _vec_generic_momentt   _vppf(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRt   
  s<    							c      	   C` s   | d  k r d } n  | |  _ | |  _ | d  k r_ | d d k rL d } n d } | | } n  t j j d k  r |  j d  k r |  j d | d | d	 t d
 d
  n( t	 t
  } |  j t | j |  j   |  j j d d  |  _ n  d  S(   NR4  i    R6  s   An s   A i   R   R   R   R   sE   
    scale : array_like, optional
        scale parameter (default=1)R3   (   R6  (   RS   R   R   RA  RB  R   R   R   t   docdict_discreteR   R	   R   R   R   (   Rq   R   R   R   RC  R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  
  s(    				
	c         C` s{   |  j  j   } |  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j	 | d <| S(	   s    Return the current version of _ctor_param, possibly updated by user.

            Used by freezing and pickling.
            Keep this in sync with the signature of __init__.
        Ro   Rp   R  R  R  R   Rr   R   (
   R7  R{   Ro   Rp   R  R  R  R   Rr   R   (   Rq   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRk   
  s    c         G` s   t  |  | k S(   N(   R   (   Rq   R   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _nonzero
  s    c         G` s$   |  j  | |  |  j  | d |  S(   Ni   (   R	  (   Rq   R   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  
  s    c         G` s   t  |  j | |   S(   N(   R   R  (   Rq   R   R^   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   _logpmf
  s    c         G` s;   t  t |  j  | d  } t j |  j | |  d d S(   Ni   R[  i    (   R   R  Ro   RX   R\  R  (   Rq   R   R^   R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR=  
  s    c         G` s   t  |  } |  j | |  S(   N(   R   R>  (   Rq   Rx   R^   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR	  
  s    c         O` s#   t  | d <t t |   j | |   S(   sr  
        Random variates of given type.

        Parameters
        ----------
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).
        size : int or tuple of ints, optional
            Defining number of random variates (Default is 1).  Note that `size`
            has to be given as keyword, not as positional argument.
        random_state : None or int or ``np.random.RandomState`` instance, optional
            If int or RandomState, use it for drawing the random variates.
            If None, rely on ``self.random_state``.
            Default is None.

        Returns
        -------
        rvs : ndarray or scalar
            Random variates of given `size`.

        R   (   R+  R   RQ   R4   (   Rq   R^   R   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR4     s    
c         O` sD  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k @|  j | |  @} | | @} t t	 |  d  }	 t
 |	 d | t j |  |  j  t j |  r)t | | f |  }
 t
 |	 | t j |  j |
   d d   n  |	 j d k r@|	 d S|	 S(   s  
        Probability mass function at k of the given RV.

        Parameters
        ----------
        k : array_like
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information)
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        pmf : array_like
            Probability mass function evaluated at k

        R  i   i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R  R   R   R    RX   RR  R  R  R   t   clipR  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRN      s    ,
$+c         O` sB  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k @|  j | |  @} | | @} t t	 |  d  }	 |	 j
 t  t |	 d | t j |  |  j  t j |  r't | | f |  }
 t |	 | |  j |
    n  |	 j d k r>|	 d S|	 S(   s  
        Log of the probability mass function at k of the given RV.

        Parameters
        ----------
        k : array_like
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter. Default is 0.

        Returns
        -------
        logpmf : array_like
            Log of the probability mass function evaluated at k.

        R  i   i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R  R(   R   RU  R'   R    RX   RR  R  R  R   R  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRO   D  s     ,
$c         O` s]  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k  @} | |  j k } | | @}	 t t |	  d  }
 t	 |
 d | t
 j |  |  j  t	 |
 | | | k d  t
 j |	  rBt |	 | f |  } t	 |
 |	 t
 j |  j |   d d   n  |
 j d k rY|
 d S|
 S(   s  
        Cumulative distribution function of the given RV.

        Parameters
        ----------
        k : array_like, int
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        cdf : ndarray
            Cumulative distribution function evaluated at `k`.

        R  i   g      ?i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R   R   R    RX   RR  R  R  R   R  R	  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR7   i  s"    
$+c         O` s[  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k  @} | |  j k } | | @}	 t t |	  d  }
 |
 j	 t
  t |
 d | t j |  |  j  t |
 | | | k d  t j |	  r@t |	 | f |  } t |
 |	 |  j |    n  |
 j d k rW|
 d S|
 S(   s-  
        Log of the cumulative distribution function at k of the given RV.

        Parameters
        ----------
        k : array_like, int
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        logcdf : array_like
            Log of the cumulative distribution function evaluated at k.

        R  i   g        i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R(   R   RU  R'   R    RX   RR  R  R  R   R
  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR8     s$    
$c         O` sW  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k  @} | |  j k  | @} | | @}	 t t |	  d  }
 t	 |
 d | t
 j |  |  j  t	 |
 | d  t
 j |	  r<t |	 | f |  } t	 |
 |	 t
 j |  j |   d d   n  |
 j d k rS|
 d S|
 S(   s  
        Survival function (1 - `cdf`) at k of the given RV.

        Parameters
        ----------
        k : array_like
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        sf : array_like
            Survival function evaluated at k.

        R  i   g      ?i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R   R   R    RX   RR  R  R  R   R  R  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR9     s"    
$+c         O` sU  |  j  | |   \ } } } t t | | f  \ } } t t t |   } t | |  } |  j |   } | |  j k | |  j k  @} | |  j k  | @} | | @}	 t t |	  d  }
 |
 j	 t
  t |
 d | t j |  |  j  t |
 | d  t j |	  r:t |	 | f |  } t |
 |	 |  j |    n  |
 j d k rQ|
 d S|
 S(   sh  
        Log of the survival function of the given RV.

        Returns the log of the "survival function," defined as 1 - `cdf`,
        evaluated at `k`.

        Parameters
        ----------
        k : array_like
            Quantiles.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        logsf : ndarray
            Log of the survival function evaluated at `k`.

        R  i   g        i    (    (   Rm   R  R#   R   Rn   Ro   Rp   R(   R   RU  R'   R    RX   RR  R  R  R   R  R   (   Rq   R   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR:     s$    
$c         O` sk  |  j  | |   \ } } } t t | | f  \ } } t t t |   } |  j |   | | k @} | d k | d k  @} | d k | @} | | @}	 t t |	  d |  j d d }
 t |
 | d k |	 |	 k |  j	 d  t |
 | |  j
  t j |	  rPt |	 | f | | f  } | d | d  } } t |
 |	 |  j |   |  n  |
 j d k rg|
 d S|
 S(   s+  
        Percent point function (inverse of `cdf`) at q of the given RV.

        Parameters
        ----------
        q : array_like
            Lower tail probability.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        k : array_like
            Quantile corresponding to the lower tail probability, q.

        i    i   RW  t   typecodeR  i(    (   Rm   R  R#   R   Rn   R  R   R  R    Ro   Rp   RX   R  R   R  R   (   Rq   Ry   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR;     s"    
!' c         O` sk  |  j  | |   \ } } } t t | | f  \ } } t t t |   } |  j |   | | k @} | d k | d k  @} | d k | @} | | @}	 t t |	  d |  j d d }
 t |
 | d k |	 |	 k |  j	  t |
 | |  j
 d  t j |	  rPt |	 | f | | f  } | d | d  } } t |
 |	 |  j |   |  n  |
 j d k rg|
 d S|
 S(   s4  
        Inverse survival function (inverse of `sf`) at q of the given RV.

        Parameters
        ----------
        q : array_like
            Upper tail probability.
        arg1, arg2, arg3,... : array_like
            The shape parameter(s) for the distribution (see docstring of the
            instance object for more information).
        loc : array_like, optional
            Location parameter (default=0).

        Returns
        -------
        k : ndarray or scalar
            Quantile corresponding to the upper tail probability, q.

        i    i   RW  R  R  i(    (   Rm   R  R#   R   Rn   R  R   R  R    Rp   Ro   RX   R  R   R  R   (   Rq   Ry   R^   Ri   R   Rs   R%  RT  RV  R   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<   0  s"    
!# c         ` sW   t   d  r t  j  St    f d    j  j  j d     j  Sd  S(   NR  c         ` s   t   j |      S(   N(   R   RN   (   Rx   (   R^   Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   <lambda>a  s    g      ?(   R   R>   R  R  Ro   Rp   R;   R  (   Rq   R^   (    (   R^   Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<  ]  s    i  g|=i    c
      	   ` s    d k r$     f d   }
 n      f d   }
  j     | d k ra  j } n
 |  } | d k r  j } n
 |  } | r  j | d     j |    } n d }  j d    } t |
 | | |  j | | |	  } | | S(   s  
        Calculate expected value of a function with respect to the distribution
        for discrete distribution by numerical summation.

        Parameters
        ----------
        func : callable, optional
            Function for which the expectation value is calculated.
            Takes only one argument.
            The default is the identity mapping f(k) = k.
        args : tuple, optional
            Shape parameters of the distribution.
        loc : float, optional
            Location parameter.
            Default is 0.
        lb, ub : int, optional
            Lower and upper bound for the summation, default is set to the
            support of the distribution, inclusive (``ul <= k <= ub``).
        conditional : bool, optional
            If true then the expectation is corrected by the conditional
            probability of the summation interval. The return value is the
            expectation of the function, `func`, conditional on being in
            the given interval (k such that ``ul <= k <= ub``).
            Default is False.
        maxcount : int, optional
            Maximal number of terms to evaluate (to avoid an endless loop for
            an infinite sum). Default is 1000.
        tolerance : float, optional
            Absolute tolerance for the summation. Default is 1e-10.
        chunksize : int, optional
            Iterate over the support of a distributions in chunks of this size.
            Default is 32.

        Returns
        -------
        expect : float
            Expected value.

        Notes
        -----
        For heavy-tailed distributions, the expected value may or may not exist,
        depending on the function, `func`. If it does exist, but the sum converges
        slowly, the accuracy of the result may be rather low. For instance, for
        ``zipf(4)``, accuracy for mean, variance in example is only 1e-5.
        increasing `maxcount` and/or `chunksize` may improve the result, but may
        also make zipf very slow.

        The function is not vectorized.

        c         ` s   |    j  |     S(   N(   R  (   Rx   (   R^   R   Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s    c         ` s    |     j  |     S(   N(   R  (   Rx   (   R^   R,   R   Rq   (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s    i   g      ?g      ?N(   RS   Rn   Ro   Rp   R9   R;   R  R  (   Rq   R,   R^   R   R   R   R   t   maxcountt	   tolerancet	   chunksizeR  R  Rx  R   (    (   R^   R,   R   Rq   s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRA   d  s     4

)$N(    (   R   R   R   R%   RS   R  Rt   R  Rk   R  R  R  R=  R	  R4   RN   RO   R7   R8   R9   R:   R;   R<   R<  R   RA   (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRQ   
  s4   	/									$	%	'	(	&	*	(	-	i  g|=i    c         C` s  | | | k rB t  j | | d |  } |  |  }	 t  j |	  S| | k  rW | } n  | | k rl | } n  d \ }
 } x t | | d d | d | D]o } |
 | j 7}
 t  j |  |   } | | 7} t |  | | j k  r Pn  |
 | k r t j d t  | Sq Wx t | d | d d | d | D]o } |
 | j 7}
 t  j |  |   } | | 7} t |  | | j k  rPn  |
 | k r0t j d t  Pq0q0W| S(   s4   Helper for computing the expectation value of `fun`.i   i    g        R  R  s   expect(): sum did not converge(   i    g        (	   RX   R   R\  t   _iter_chunkedRz   t   abst   warningst   warnt   RuntimeWarning(   R  R   R   Rx  R  R  R  R  t   suppR   t   countt   totRx   t   delta(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s8    		&
+
i   c   
      c` s   | d k r t  d   n  | d k r: t  d |   n  | d k rL d n d } t | |  } |  } xc | | | d k  r t | t | |   } | | } t j | | | |  }	 | | 7} |	 Vqk Wd S(   sV  Iterate from x0 to x1 in chunks of chunksize and steps inc.

    x0 must be finite, x1 need not be. In the latter case, the iterator is
    infinite.
    Handles both x0 < x1 and x0 > x1. In the latter case, iterates downwards
    (make sure to set inc < 0.)

    >>> [x for x in _iter_chunked(2, 5, inc=2)]
    [array([2, 4])]
    >>> [x for x in _iter_chunked(2, 11, inc=2)]
    [array([2, 4, 6, 8]), array([10])]
    >>> [x for x in _iter_chunked(2, -5, inc=-2)]
    [array([ 2,  0, -2, -4])]
    >>> [x for x in _iter_chunked(2, -9, inc=-2)]
    [array([ 2,  0, -2, -4]), array([-6, -8])]

    i    s   Cannot increment by zero.s$   Chunk size must be positive; got %s.i   iN(   R   R  R  RX   R   (
   Rx  t   x1R  R  R  t   stepsizeRx   R  t   stepR  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s    

R  c           B` sn   e  Z d  Z d e d d d d d d d d d d  Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z RS(   s   A 'sample' discrete distribution defined by the support and values.

       The ctor ignores most of the arguments, only needs the `values` argument.
    i    g:0yE>i   c         C` s  t  t |   j |  | d  k r1 t d   n  t d | d | d | d | d | d | d | d	 | d
 |	 d |
 d |  |  _ | d  k r t } n  | |  _ | |  _	 | |  _
 |	 |  _ |  j |  _ | \ } } t |  t |  k r t d   n  t j t j |  d  s!t d   n  t j t j |   } t j t j |  | d  |  _ t j t j |  | d  |  _ |  j d |  _ |  j d |  _ t j |  j d d |  _ d |  _ |  j d |  j g d d d d  |  j | | |
  d  S(   Ns(   rv_sample.__init__(..., values=None,...)Ro   Rp   R   R  R  R  R  R   Rr   R   Rw   s'   xk and pk need to have the same length.i   s    The sum of provided pk is not 1.i    iR[  R   R   R   s   loc=0R   s   loc, 1(   R   RQ   Rt   RS   R   R   R7  R$   R  R  R  Rr   R<  R$  R   RX   t   allcloseR\  t   argsortR   t   taket   xkR  Ro   Rp   t   cumsumt   qvalsR   R  R  (   Rq   Ro   Rp   R   R  R  R  R  R   Rr   R   Rw   R  R  t   indx(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyRt   
  s<    					!!	c         C` sU   t  j g  |  j D] } | | k ^ q g  |  j D] } t  j | |  d ^ q/ d  S(   Ni    (   RX   t   selectR  R  R   (   Rq   Rx   R   t   p(    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  7  s    %c         C` sU   t  j | d  d   d  f |  j  \ } } t  j | | k d d d } |  j | S(   NR[  ii   (   RX   R   RS   R  R!   R  (   Rq   Rx   t   xxt   xxkR  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR	  ;  s    +c         C` sB   t  j | d |  j  \ } } t | | k d d } |  j | S(   N.R[  i(   .N(   RX   R   RS   R  R!   R  (   Rq   Ry   t   qqt   sqqR  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  @  s    c         C` sb   |  j  j |  j  } |  j d  k rO t j | d d } |  j |  d } n |  j |  } | S(   Nt   ndmini   i    (   Ru   R  R  RS   RX   t   arrayR  (   Rq   R  R  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR  E  s    c         C` s   t  |  j  S(   N(   R>   R  (   Rq   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR<  P  s    c         C` s:   t  |  } t j |  j | t j d f |  j d d S(   N.R[  i    (   R#   RX   R\  R  t   newaxisR  (   Rq   RU   (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR   S  s    N(   R   R   R   R%   RS   Rt   R  R	  R  R  R<  R   (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyR    s   +					c         C` s   g  } g  } xv |  D]n \ } } | j  d  r4 q n  | j d  rb t | |  rb | j |  n  t | |  r | j |  q q W| | f S(   s|  
    Collect names of statistical distributions and their generators.

    Parameters
    ----------
    namespace_pairs : sequence
        A snapshot of (name, value) pairs in the namespace of a module.
    rv_base_class : class
        The base class of random variable generator classes in a module.

    Returns
    -------
    distn_names : list of strings
        Names of the statistical distributions.
    distn_gen_names : list of strings
        Names of the generators of the statistical distributions.
        Note that these are not simply the names of the statistical
        distributions, with a _gen suffix added.

    Rs   t   _gen(   R   t   endswitht
   issubclassR   R   (   t   namespace_pairst   rv_base_classt   distn_namest   distn_gen_namesR   RW  (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   get_distribution_namesX  s    (   t
   __future__R    R   R   t   scipy._lib.sixR   R   R   t   scipy._lib._utilR   R   RA  R   R   R*   R  t
   scipy.miscR   t   _distr_paramsR   R	   R
   R   R  t   scipy.specialR   R   R   R   R   R   t   scipyR   R   R   t   numpyR   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   RX   t
   _constantsR)   R/   R+   R   t   _doc_rvst   _doc_pdft   _doc_logpdft   _doc_pmft   _doc_logpmft   _doc_cdft   _doc_logcdft   _doc_sft
   _doc_logsft   _doc_ppft   _doc_isft   _doc_momentt
   _doc_statst   _doc_entropyt   _doc_fitt   _doc_expectt   _doc_expect_discretet   _doc_mediant	   _doc_meant   _doc_vart   _doc_stdt   _doc_intervalR   t   _doc_allmethodst   _doc_default_longsummaryt   _doc_default_frozen_notet   _doc_default_examplet   _doc_default_locscalet   _doc_defaultt   _doc_default_before_notesR   R{   R  t   _doc_disc_methodsR-   R   t   _doc_disc_methods_err_varnameR  t   _doc_default_discrete_examplet   _doc_default_discrete_locscalet   _doc_default_disct   dirR  R   t	   NameErrorRS   RW   Rb   Re   Rg   t   objectRh   R   R   R   R   R   R   RP   R  R  R>   RQ   R  R  R  R  (    (    (    s@   lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyt   <module>   s:  .	

		-		



&	
*



2	 		a	%			      t		:/  )#S