
    uki              	           d dl Zd dlmZ d dlm Z d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ dded	ed
edefdZdded	ed
edefdZded	edefdZded	edefdZy)    N)lax)numpy)_const)promote_args_inexact)xlogyxlog1py)Array	ArrayLikekplocreturnc           	         t        d| ||      \  } }}t        | d      }t        | d      }t        j                  | |      }t	        ||      t        t        j                  ||      |       z   }t        j                  t        j                  t        j                  ||      t        j                  ||            t        j                   |      S )ax  Bernoulli log probability mass function.

  JAX implementation of :obj:`scipy.stats.bernoulli` ``logpmf``

  The Bernoulli probability mass function is defined as

  .. math::

     f(k) = \begin{cases}
       1 - p, & k = 0 \\
       p, & k = 1 \\
       0, & \mathrm{otherwise}
     \end{cases}

  Args:
    k: arraylike, value at which to evaluate the PMF
    p: arraylike, distribution shape parameter
    loc: arraylike, distribution offset

  Returns:
    array of logpmf values

  See Also:
    - :func:`jax.scipy.stats.bernoulli.cdf`
    - :func:`jax.scipy.stats.bernoulli.pmf`
    - :func:`jax.scipy.stats.bernoulli.ppf`
  zbernoulli.logpmfr      )r   
_lax_constr   subr   r   jnpwhere
logical_orltgtnpinf)r   r   r   zeroonex	log_probss          Y/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/scipy/stats/bernoulli.pylogpmfr      s    8 ##5q!SA)!Q	Aq	$1a#	ggao!AqkGCGGCOaR88)	3>>#&&D/366!S>B66'9
& &    c                 B    t        j                  t        | ||            S )aq  Bernoulli probability mass function.

  JAX implementation of :obj:`scipy.stats.bernoulli` ``pmf``

  The Bernoulli probability mass function is defined as

  .. math::

     f(k) = \begin{cases}
       1 - p, & k = 0 \\
       p, & k = 1 \\
       0, & \mathrm{otherwise}
     \end{cases}

  Args:
    k: arraylike, value at which to evaluate the PMF
    p: arraylike, distribution shape parameter
    loc: arraylike, distribution offset

  Returns:
    array of pmf values

  See Also:
    - :func:`jax.scipy.stats.bernoulli.cdf`
    - :func:`jax.scipy.stats.bernoulli.logpmf`
    - :func:`jax.scipy.stats.bernoulli.ppf`
  )r   expr   )r   r   r   s      r   pmfr#   >   s    8 
1c"	##r    c           	         t        d| |      \  } }t        | d      t        | d      }}t        j                  |       t        j                  |      z  ||k  z  ||kD  z  t	        j
                  | |      t        j                  t	        j                  | |      t	        j
                  | |            t	        j                  | |      g}t        j                  |||z
  |g}t        j                  ||      S )a  Bernoulli cumulative distribution function.

  JAX implementation of :obj:`scipy.stats.bernoulli` ``cdf``

  The Bernoulli cumulative distribution function is defined as:

  .. math::

     f_{cdf}(k, p) = \sum_{i=0}^k f_{pmf}(k, p)

  where :math:`f_{pmf}(k, p)` is the Bernoulli probability mass function
  :func:`jax.scipy.stats.bernoulli.pmf`.

  Args:
    k: arraylike, value at which to evaluate the CDF
    p: arraylike, distribution shape parameter
    loc: arraylike, distribution offset

  Returns:
    array of cdf values

  See Also:
    - :func:`jax.scipy.stats.bernoulli.logpmf`
    - :func:`jax.scipy.stats.bernoulli.pmf`
    - :func:`jax.scipy.stats.bernoulli.ppf`
  zbernoulli.cdfr   r   )r   r   r   isnanr   r   logical_andger   nanselect)r   r   r   r   condsvalss         r   cdfr,   ]   s    6 
oq!	4$!QA
1a 0$IIaL399Q<1t8,C8FF1dOOOCFF1dOSVVAs^4FF1cN	% &&$a	%$	E4	  r    qc                 v   t        d| |      \  } }t        | d      t        | d      }}t        j                  t        j                  |       t        j                  |      z  ||k  z  ||kD  z  | |k  z  | |kD  z  t
        j                  t        j                  t        j                  | ||z
        ||            S )a.  Bernoulli percent point function.

  JAX implementation of :obj:`scipy.stats.bernoulli` ``ppf``

  The percent point function is the inverse of the cumulative
  distribution function, :func:`jax.scipy.stats.bernoulli.cdf`.

  Args:
    k: arraylike, value at which to evaluate the PPF
    p: arraylike, distribution shape parameter
    loc: arraylike, distribution offset

  Returns:
    array of ppf values

  See Also:
    - :func:`jax.scipy.stats.bernoulli.cdf`
    - :func:`jax.scipy.stats.bernoulli.logpmf`
    - :func:`jax.scipy.stats.bernoulli.pmf`
  zbernoulli.ppfr   r   )	r   r   r   r   r%   r   r(   r   le)r-   r   r   r   s       r   ppfr0      s    * 
oq!	4$!QA
1a 0$	IIaL399Q<1t8,C8AHESQFFIIcffQa $,
 r    )r   )r   r   jax._srcr   r   jax._src.lax.laxr   r   jax._src.numpy.utilr   jax._src.scipy.specialr   r   jax._src.typingr	   r
   r   r#   r,   r0    r    r   <module>r7      s      ! 1 4 1 ,"&i "&I "&I "&e "&J$9 $ $ $5 $>$!9 $! $!u $!N9  u r    