ó
|£*^c           @   sŹ   d  Z  d d l Z d d l Z d d l Z d j d d d g  Z d d l Z d d d  Z
 d	 d
  Z d d  Z d d d  Z d d d  Z d   Z d   Z d d d  Z d   Z d   Z d S(   sT   
Utilities for generating random numbers, random sequences, and 
random selections.
i’’’’Ns   
s   Aric Hagberg (hagberg@lanl.gov)s   Dan Schult(dschult@colgate.edu)s    Ben Edwards(bedwards@cs.unm.edu)i2   c   	      K   s©   t  j d t  d } |  } xs | | k  r | |  |  } g  | D]* } t | t t t |   d   ^ qA } t j |  r | S| d 7} q Wt j	 d |   d  S(   Ns&   create_degree_sequence() is deprecatedi    i   s/   Exceeded max (%d) attempts at a valid sequence.(
   t	   _warningst   warnt   DeprecationWarningt   mint   maxt   intt   roundt   nxt   is_valid_degree_sequencet   NetworkXError(	   t   nt	   sfunctiont	   max_triest   kwdst   triest   max_degt   trialseqt   st   seq(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   create_degree_sequence   s    	7g      š?c         C   s&   g  t  |   D] } t j |  ^ q S(   sH   
    Return sample sequence of length n from a Pareto distribution.
    (   t   ranget   randomt   paretovariate(   R
   t   exponentt   i(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   pareto_sequenceC   s    g       @c         C   s*   g  t  |   D] } t j | d  ^ q S(   sK   
    Return sample sequence of length n from a power law distribution.
    i   (   R   R   R   (   R
   R   R   (    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   powerlaw_sequenceJ   s    i   c   	      C   sę   | d k  r t  d   n  |  d k r6 t  d   n  | d k	 rR t j |  n  |  d } d | } xy t rį d t j   } t j   } t | | d |  } d d | | } | | | d | d | | k ri Pqi qi W| S(   s%  Return a random value chosen from the Zipf distribution.

    The return value is an integer drawn from the probability distribution
    ::math::

        p(x)=\frac{x^{-\alpha}}{\zeta(\alpha,x_{min})},

    where `\zeta(\alpha,x_{min})` is the Hurwitz zeta function.        

    Parameters
    ----------
    alpha : float 
      Exponent value of the distribution
    xmin : int
      Minimum value
    seed : int
      Seed value for random number generator

    Returns
    -------
    x : int
      Random value from Zipf distribution

    Raises
    ------
    ValueError:
      If xmin < 1 or
      If alpha <= 1

    Notes
    -----
    The rejection algorithm generates random values for a the power-law
    distribution in uniformly bounded expected time dependent on
    parameters.  See [1] for details on its operation.

    Examples
    --------
    >>> nx.zipf_rv(alpha=2, xmin=3, seed=42) # doctest: +SKIP

    References
    ----------
    ..[1] Luc Devroye, Non-Uniform Random Variate Generation, 
       Springer-Verlag, New York, 1986.
    i   s   xmin < 1s   a <= 1.0g      š?i   N(   t
   ValueErrort   NoneR   t   seedt   TrueR   (	   t   alphat   xminR   t   a1t   bt   ut   vt   xt   t(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   zipf_rvP   s     -

	$c         C   s&   g  t  |   D] } t | |  ^ q S(   s£   Return a sample sequence of length n from a Zipf distribution with
    exponent parameter alpha and minimum value xmin.

    See Also
    --------
    zipf_rv
    (   R   R'   (   R
   R   R    t   _(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   zipf_sequence   s    c         C   s)   g  t  |   D] } t j d |   ^ q S(   sI   
    Return sample sequence of length n from a uniform distribution.
    i    (   R   R   t   uniform(   R
   R   (    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   uniform_sequence   s    c         C   sf   g  } | j  d  t t |    } x: t d t |    D]# } | j  | | |  | |  q; W| S(   sE   Return normalized cumulative distribution from discrete distribution.g        i    (   t   appendt   floatt   sumR   t   len(   t   distributiont   cdft   psumR   (    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   cumulative_distribution   s    !c   	      C   s   d d l  } | d k	 r! | } n* | d k	 r< t |  } n t j d   g  t |   D] } t j   ^ qX } g  | D] } | j | |  d ^ qw } | S(   s*  
    Return sample sequence of length n from a given discrete distribution
    or discrete cumulative distribution. 

    One of the following must be specified.  

    distribution = histogram of values, will be normalized
    
    cdistribution = normalized discrete cumulative distribution

    i’’’’Ns8   discrete_sequence: distribution or cdistribution missingi   (   t   bisectR   R3   R   R	   R   R   t   bisect_left(	   R
   R0   t   cdistributionR4   R1   R   t   inputseqR   R   (    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   discrete_sequenceŖ   s    		%)c         C   s`   | t  |   k r! t d   n  t   } x) t  |  | k  rU | j t |    q- Wt |  S(   s   Return k items without replacement from a weighted sample.

    The input is a dictionary of items with weights as values.
    s   sample larger than population(   R/   R   t   sett   addt   weighted_choicet   list(   t   mappingt   kt   sample(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   random_weighted_sampleÉ   s    	c         C   sW   t  j    t |  j    } x4 |  j   D]& \ } } | | 8} | d k  r) | Sq) Wd S(   st   Return a single element from a weighted sample.

    The input is a dictionary of items with weights as values.
    i    N(   R   R.   t   valuest   items(   R=   t   rndR>   t   w(    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyR;   Õ   s
    
(   t   __doc__R   t   syst   networkxR   t   joint
   __author__t   warningsR    R   R   R   R   R'   R)   R+   R3   R8   R@   R;   (    (    (    sr   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/random_sequence.pyt   <module>   s"   	0>
			