+
    LV-jz>  ã            
       ó$  € R t ^ RIt^ RIt^ RIHt ^RIHt ^ RIH	t	H
t
HtHtHtHt RR.t]! 4       ]! R R ^R	 R
RR7      RR R ll4       4       tR R lt]! 4       ]! R ^R ]R7      RRRRR^ RR/R R ll4       4       tR tR tR tR tR tR# )!z5
Created on Fri Apr  2 09:06:05 2021

@author: matth
N)Úspecial)Ú_axis_nan_policy_factory)Úarray_namespaceÚ
xp_promoteÚ	xp_deviceÚ	is_marrayÚ_share_masksÚxp_capabilitiesÚentropyÚdifferential_entropyc                 ó   € V # ©N© ©Úxs   &Úe/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/scipy/stats/_entropy.pyÚ<lambda>r      ó   € ‰aó    c                 ó.   € R V 9   d   V R ,          e   ^# ^# )Úqkr   )Úkwgss   &r   r   r      s!   € Ø�dŒl˜t D�zÒ5ˆð 	Øð	r   c                 ó   € V 3# r   r   ©r   Ú_s   &&r   r   r      s   € ¨q©dr   T)Ú	n_samplesÚ	n_outputsÚresult_to_tupleÚpairedÚ	too_smallc                óþ   € V ^8„  d   QhR\         P                  P                  R\         P                  P                  R,          R\        R,          R\        R\         P
                  \         P                  ,          /# )é   Úpkr   NÚbaseÚaxisÚreturn)ÚnpÚtypingÚ	ArrayLikeÚfloatÚintÚnumberÚndarray)Úformats   "r   Ú__annotate__r.      sh   € ÷ Jñ J”—	‘	×#Ñ#ð JÜ—	‘	×#Ñ# dÕ*ðJä˜$•,ðJô ðJô —‘œRŸZ™ZÕ'ñ	Jr   c           	     óâ  € Ve   V^ 8:  d   \        R4      h\        W4      p\        WRVR7      w  r\        P                  ! RR7      ;_uu_ 4        Ve)   \        WVR7      w  rWP                  WRR7      ,          pWP                  WRR7      ,          p RRR4       Vf   \        P                  ! V 4      pMo\        V4      '       dI   \        P                  ! V P                  VP                  4      pVP                  WPP                  R	7      pM\        P                  ! W4      pVP                  WSR
7      pVe   V\        P                  ! V4      ,          pV#   + '       g   i     LÏ; i)a”  
Calculate the Shannon entropy/relative entropy of given distribution(s).

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

If `qk` is not None, then compute the relative entropy
``D = sum(pk * log(pk / qk))``. This quantity is also known
as the Kullback-Leibler divergence.

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

Parameters
----------
pk : array_like
    Defines the (discrete) distribution. Along each axis-slice of ``pk``,
    element ``i`` is the  (possibly unnormalized) probability of event
    ``i``.
qk : array_like, 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).
axis : int, optional
    The axis along which the entropy is calculated. Default is 0.

Returns
-------
S : {float, array_like}
    The calculated entropy.

Notes
-----
Informally, the Shannon entropy quantifies the expected uncertainty
inherent in the possible outcomes of a discrete random variable.
For example,
if messages consisting of sequences of symbols from a set are to be
encoded and transmitted over a noiseless channel, then the Shannon entropy
``H(pk)`` gives a tight lower bound for the average number of units of
information needed per symbol if the symbols occur with frequencies
governed by the discrete distribution `pk` [1]_. The choice of base
determines the choice of units; e.g., ``e`` for nats, ``2`` for bits, etc.

The relative entropy, ``D(pk|qk)``, quantifies the increase in the average
number of units of information needed per symbol if the encoding is
optimized for the probability distribution `qk` instead of the true
distribution `pk`. Informally, the relative entropy quantifies the expected
excess in surprise experienced if one believes the true distribution is
`qk` when it is actually `pk`.

A related quantity, the cross entropy ``CE(pk, qk)``, satisfies the
equation ``CE(pk, qk) = H(pk) + D(pk|qk)`` and can also be calculated with
the formula ``CE = -sum(pk * log(qk))``. It gives the average
number of units of information needed per symbol if an encoding is
optimized for the probability distribution `qk` when the true distribution
is `pk`. It is not computed directly by `entropy`, but it can be computed
using two calls to the function (see Examples).

See [2]_ for more information.

References
----------
.. [1] Shannon, C.E. (1948), A Mathematical Theory of Communication.
       Bell System Technical Journal, 27: 379-423.
       https://doi.org/10.1002/j.1538-7305.1948.tb01338.x
.. [2] Thomas M. Cover and Joy A. Thomas. 2006. Elements of Information
       Theory (Wiley Series in Telecommunications and Signal Processing).
       Wiley-Interscience, USA.


Examples
--------
The outcome of a fair coin is the most uncertain:

>>> import numpy as np
>>> from scipy.stats import entropy
>>> base = 2  # work in units of bits
>>> pk = np.array([1/2, 1/2])  # fair coin
>>> H = entropy(pk, base=base)
>>> H
1.0
>>> H == -np.sum(pk * np.log(pk)) / np.log(base)
True

The outcome of a biased coin is less uncertain:

>>> qk = np.array([9/10, 1/10])  # biased coin
>>> entropy(qk, base=base)
0.46899559358928117

The relative entropy between the fair coin and biased coin is calculated
as:

>>> D = entropy(pk, qk, base=base)
>>> D
0.7369655941662062
>>> np.isclose(D, np.sum(pk * np.log(pk/qk)) / np.log(base), rtol=4e-16, atol=0)
True

The cross entropy can be calculated as the sum of the entropy and
relative entropy`:

>>> CE = entropy(pk, base=base) + entropy(pk, qk, base=base)
>>> CE
1.736965594166206
>>> CE == -np.sum(pk * np.log(qk)) / np.log(base)
True

Nú+`base` must be a positive number or `None`.T)Ú	broadcastÚxpÚignore)Úinvalid©r2   ©r$   Úkeepdims)Úmask©r$   )Ú
ValueErrorr   r   r&   Úerrstater   Úsumr   Úentrr   Úrel_entrÚdataÚasarrayr8   ÚmathÚlog)r"   r   r#   r$   r2   ÚvecÚSs   &&&&   r   r
   r
      s  € ðx Ò˜D AœIÜÐFÓGÐGä	˜Ó	 €BÜ˜¨$°2Ô6�F€Bä	�Š˜X×	&Ö	&ØŠ>Ü! "¨RÔ0‰FˆBØ—f‘f˜R°T�fÓ:Õ:ˆBØ—&‘&˜°�&Ó6Õ6ˆ÷	 
'ð 
‚zÜ�lŠl˜2Ó‰ä�R�=Š=Ü×"Ò" 2§7¡7¨B¯G©GÓ4ˆCØ—*‘*˜S§w¡w�*Ó/‰Cä×"Ò" 2Ó*ˆCà
�‰ˆsˆÓ€AØÒØ	ŒT�XŠX�d‹^ÕˆØ€H÷% 
'×	&ús   ÁAEÅE.	c                 ó  € V ^ ,          pVP                   V,          pVP                  R4      pVf2   \        P                  ! \        P                  ! V4      R,           4      p^^V,          u;8:  d
   V8  g    R#  R# R# )é    Úwindow_lengthç      à?TF)ÚshapeÚgetrA   ÚfloorÚsqrt)ÚsamplesÚkwargsr$   ÚvaluesÚnrG   s   &&&   r   Ú"_differential_entropy_is_too_smallrQ   ¨   sh   € Ø�Q�Z€FØ�‰�TÕ€AØ—J‘J˜Ó/€MØÒÜŸ
š
¤4§9¢9¨Q£<°#Õ#5Ó6ˆØ��MÕ!Ö% AÕ%Ùð &ÙÙr   c                 ó   € V # r   r   r   s   &r   r   r   µ   r   r   c                 ó   € V 3# r   r   r   s   &&r   r   r   µ   s   € ¸A¹4r   )r   r   r   rG   r#   r$   ÚmethodÚautoc                óâ   € V ^8„  d   QhR\         P                  P                  R\        R,          R\        R,          R\        R\
        R\         P                  \         P                  ,          /# )r!   rO   rG   Nr#   r$   rT   r%   )r&   r'   r(   r*   r)   Ústrr+   r,   )r-   s   "r   r.   r.   ¸   sm   € ÷ |(ñ |(Ü�I‰I×Ñð|(ô ˜•:ð|(ô �$�,ð	|(ô
 ð|(ô ð|(ô ‡Y�Y”—‘Õñ|(r   c          
     óþ  € \        V 4      p\        V RVR7      p VP                  WR4      p V P                  R,          pVf2   \        P
                  ! \        P                  ! V4      R,           4      p^^V,          u;8:  d   V8  g   M \        RV RV R24      hVe   V^ 8:  d   \        R4      hVP                  V RR7      pR	\        R
\        R\        R\        R\        /pVP                  4       pWH9  d   R\        V4       2p	\        V	4      hVR8X  d   V^
8:  d   R
pMVR8:  d   RpMR	pW„,          ! WqVR7      p
Ve   V
\        P                  ! V4      ,          p
VP!                  W P"                  4      # )aŠ  Given a sample of a distribution, estimate the differential entropy.

Several estimation methods are available using the `method` parameter. By
default, a method is selected based the size of the sample.

Parameters
----------
values : sequence
    Sample from a continuous distribution.
window_length : int, optional
    Window length for computing Vasicek estimate. Must be an integer
    between 1 and half of the sample size. If ``None`` (the default), it
    uses the heuristic value

    .. math::
        \left \lfloor \sqrt{n} + 0.5 \right \rfloor

    where :math:`n` is the sample size. This heuristic was originally
    proposed in [2]_ and has become common in the literature.
base : float, optional
    The logarithmic base to use, defaults to ``e`` (natural logarithm).
axis : int, optional
    The axis along which the differential entropy is calculated.
    Default is 0.
method : {'vasicek', 'van es', 'ebrahimi', 'correa', 'auto'}, optional
    The method used to estimate the differential entropy from the sample.
    Default is ``'auto'``.  See Notes for more information.

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

Notes
-----
This function will converge to the true differential entropy in the limit

.. math::
    n \to \infty, \quad m \to \infty, \quad \frac{m}{n} \to 0

The optimal choice of ``window_length`` for a given sample size depends on
the (unknown) distribution. Typically, the smoother the density of the
distribution, the larger the optimal value of ``window_length`` [1]_.

The following options are available for the `method` parameter.

* ``'vasicek'`` uses the estimator presented in [1]_. This is
  one of the first and most influential estimators of differential entropy.
* ``'van es'`` uses the bias-corrected estimator presented in [3]_, which
  is not only consistent but, under some conditions, asymptotically normal.
* ``'ebrahimi'`` uses an estimator presented in [4]_, which was shown
  in simulation to have smaller bias and mean squared error than
  the Vasicek estimator.
* ``'correa'`` uses the estimator presented in [5]_ based on local linear
  regression. In a simulation study, it had consistently smaller mean
  square error than the Vasiceck estimator, but it is more expensive to
  compute.
* ``'auto'`` selects the method automatically (default). Currently,
  this selects ``'van es'`` for very small samples (<10), ``'ebrahimi'``
  for moderate sample sizes (11-1000), and ``'vasicek'`` for larger
  samples, but this behavior is subject to change in future versions.

All estimators are implemented as described in [6]_.

References
----------
.. [1] Vasicek, O. (1976). A test for normality based on sample entropy.
       Journal of the Royal Statistical Society:
       Series B (Methodological), 38(1), 54-59.
.. [2] Crzcgorzewski, P., & Wirczorkowski, R. (1999). Entropy-based
       goodness-of-fit test for exponentiality. Communications in
       Statistics-Theory and Methods, 28(5), 1183-1202.
.. [3] Van Es, B. (1992). Estimating functionals related to a density by a
       class of statistics based on spacings. Scandinavian Journal of
       Statistics, 61-72.
.. [4] Ebrahimi, N., Pflughoeft, K., & Soofi, E. S. (1994). Two measures
       of sample entropy. Statistics & Probability Letters, 20(3), 225-234.
.. [5] Correa, J. C. (1995). A new estimator of entropy. Communications
       in Statistics-Theory and Methods, 24(10), 2439-2449.
.. [6] Noughabi, H. A. (2015). Entropy Estimation Using Numerical Methods.
       Annals of Data Science, 2(2), 231-241.
       https://link.springer.com/article/10.1007/s40745-015-0045-9

Examples
--------
>>> import numpy as np
>>> from scipy.stats import differential_entropy, norm

Entropy of a standard normal distribution:

>>> rng = np.random.default_rng()
>>> values = rng.standard_normal(100)
>>> differential_entropy(values)
1.3407817436640392

Compare with the true entropy:

>>> float(norm.entropy())
1.4189385332046727

For several sample sizes between 5 and 1000, compare the accuracy of
the ``'vasicek'``, ``'van es'``, and ``'ebrahimi'`` methods. Specifically,
compare the root mean squared error (over 1000 trials) between the estimate
and the true differential entropy of the distribution.

>>> from scipy import stats
>>> import matplotlib.pyplot as plt
>>>
>>>
>>> def rmse(res, expected):
...     '''Root mean squared error'''
...     return np.sqrt(np.mean((res - expected)**2))
>>>
>>>
>>> a, b = np.log10(5), np.log10(1000)
>>> ns = np.round(np.logspace(a, b, 10)).astype(int)
>>> reps = 1000  # number of repetitions for each sample size
>>> expected = stats.expon.entropy()
>>>
>>> method_errors = {'vasicek': [], 'van es': [], 'ebrahimi': []}
>>> for method in method_errors:
...     for n in ns:
...        rvs = stats.expon.rvs(size=(reps, n), random_state=rng)
...        res = stats.differential_entropy(rvs, method=method, axis=-1)
...        error = rmse(res, expected)
...        method_errors[method].append(error)
>>>
>>> for method, errors in method_errors.items():
...     plt.loglog(ns, errors, label=method)
>>>
>>> plt.legend()
>>> plt.xlabel('sample size')
>>> plt.ylabel('RMSE (1000 trials)')
>>> plt.title('Entropy Estimator Error (Exponential Distribution)')

T)Úforce_floatingr2   rH   zWindow length (z7) must be positive and less than half the sample size (z).r0   r9   Úvasicekzvan esÚcorreaÚebrahimirU   z`method` must be one of iè  r5   éÿÿÿÿ)r   r   ÚmoveaxisrI   rA   rK   rL   r:   ÚsortÚ_vasicek_entropyÚ_van_es_entropyÚ_correa_entropyÚ_ebrahimi_entropyÚlowerÚsetrB   ÚastypeÚdtype)rO   rG   r#   r$   rT   r2   rP   Úsorted_dataÚmethodsÚmessageÚress   &$$$$      r   r   r   ³   sp  € ôj 
˜Ó	 €BÜ˜¨t¸Ô;€FØ�[‰[˜ rÓ*€FØ�‰�RÕ€AàÒÜŸ
š
¤4§9¢9¨Q£<°#Õ#5Ó6ˆà��MÕ!Ö% AÖ%ÜØ˜m˜_ð -*Ø*+¨¨Bð0ó
ð 	
ð
 Ò˜D AœIÜÐFÓGÐGà—'‘'˜& r�'Ó*€KàÔ*ØœØœØÔ,ØÔ'ð	)€Gð
 �\‰\‹^€FØÔØ,¬S°«\¨NÐ;ˆÜ˜Ó!Ð!à�ÔØ�Œ7Ø‰FØ�$ŒYØ‰FàˆFà
Ž/˜+¸Ô
<€CàÒØŒt�xŠx˜‹~Õˆð �9‰9�SŸ,™,Ó'Ð'r   c               óÆ   € V P                   RR V3,           pVP                  V R,          V4      pVP                  V RRR13,          V4      pVP                  W@V3RR7      # )z9Pad the data for computing the rolling window difference.N.r9   r]   ).:Né   N)rI   Úbroadcast_toÚconcat)ÚXÚmr2   rI   ÚXlÚXrs   &&$   r   Ú_pad_along_last_axisrt   w  s_   € ð �G‰G�C�RˆL˜A˜4Õ€EØ	�‰˜˜7� UÓ	+€BØ	�‰˜˜3 ¡˜8� eÓ	,€BØ�9‰9�b˜R�[ rˆ9Ó*Ð*r   c               ó  € V P                   R,          p\        WVR7      p V R^V,          R13,          V RRRV,          13,          ,
          pVP                  V^V,          ,          V,          4      pVP                  VRR7      # )z:Compute the Vasicek estimator as described in [6] Eq. 1.3.r5   .Nr9   r]   éþÿÿÿ)rI   rt   rB   Úmean)rp   rq   r2   rP   ÚdifferencesÚlogss   &&$   r   r`   r`   €  sr   € à	�‰��€AÜ˜Q bÔ)€AØ�C˜˜Q�™�K•. 1 S¨)¨B°­F¨) ^Õ#4Õ4€KØ�6‰6�!�Q�q•S•'˜KÕ'Ó(€DØ�7‰7�4˜bˆ7Ó!Ð!r   c               ó  € V P                   R,          pV RVR13,          V RRV) 13,          ,
          p^W1,
          ,          VP                  VP                  V^,           V,          V,          4      RR7      ,          pVP                  W^,           VP                  \        V 4      R7      pWRP                  ^V,          4      ,           \        P                  ! V4      ,           \        P                  ! V^,           4      ,
          # )z1Compute the van Es estimator as described in [6]..Nr9   ©rg   Údevicer]   )rI   r<   rB   Úarangerg   r   rA   )rp   rq   r2   rP   Ú
differenceÚterm1Úks   &&$    r   ra   ra   ‰  s¹   € ð 	
�‰��€AØ�3˜™�7•˜a  S q b S �kÕ)€JØˆq�s�G�b—f‘f˜RŸV™V Q q¥S¨!¥G¨jÕ$8Ó9À�fÓCÕC€EØ
�	‰	�!�q•S §¡´I¸a³Lˆ	ÓA€AØ—6‘6˜!˜A�#“;Õ¤§¢¨!£Õ,¬t¯xªx¸¸!½«}Õ<Ð<r   c               ó*  € V P                   R,          p\        WVR7      p V R^V,          R13,          V RRRV,          13,          ,
          pVP                  ^V^,           V P                  \	        V 4      R7      pVP                  WQ8*  ^V^,
          V,          ,           R4      pVP                  WSV,
          ^,           8¬  ^W5,
          V,          ,           V4      pVP                  W4,          Wa,          ,          4      pVP                  VRR7      # )	z3Compute the Ebrahimi estimator as described in [6].r5   .Nr{   g       @r9   r]   rv   )rI   rt   r}   rg   r   ÚwhererB   rw   )rp   rq   r2   rP   rx   ÚiÚciry   s   &&$     r   rc   rc   ”  sØ   € ð 	
�‰��€AÜ˜Q bÔ)€Aà�C˜˜Q�™�K•. 1 S¨)¨B°­F¨) ^Õ#4Õ4€Kà
�	‰	�!�Q�q•S §¡´	¸!³ˆ	Ó=€AØ	�‰�!‘&˜!˜q 1�u a�i�-¨Ó	,€BØ	�‰�!˜1•u˜q•y‘. ! q¥u¨a¥i¥-°Ó	4€Bà�6‰6�!•/ R¥VÕ,Ó-€DØ�7‰7�4˜bˆ7Ó!Ð!r   c               ó2  € V P                   R,          p\        WVR7      p VP                  ^V^,           \        V 4      R7      pVP                  V) V^,           \        V 4      R7      R,          pWE,           pWa,           ^,
          pVP	                  V RV3,          R	RR7      pV RV3,          V,
          p	VP                  W•,          R	R7      p
W2P                  V	^,          R	R7      ,          pVP	                  VP                  W«,          4      RR7      ) # )
z1Compute the Correa estimator as described in [6].r5   )r|   .Tr6   r9   r]   ):NNNNrv   )rI   rt   r}   r   rw   r<   rB   )rp   rq   r2   rP   rƒ   ÚdjÚjÚj0ÚXibarr~   ÚnumÚdens   &&$         r   rb   rb   ¤  sé   € ð 	
�‰��€AÜ˜Q bÔ)€Aà
�	‰	�!�Q�q•S¤¨1£ˆ	Ó.€AØ	�‰�A�2�q˜•s¤9¨Q£<ˆÓ	0°Õ	9€BØ	�€AØ	
���€Bà�G‰G�A�c˜2�g•J R°$ˆGÓ7€EØ�3˜�7•˜eÕ#€JØ
�&‰&�• Rˆ&Ó
(€CØ
�F‰F�:˜q•= rˆFÓ*Õ
*€CØ�G‰G�B—F‘F˜3�7“O¨"ˆGÓ-Ð-Ð-r   r]   )NNrF   )r]   )Ú__doc__rA   Únumpyr&   Úscipyr   Ú_axis_nan_policyr   Úscipy._lib._array_apir   r   r   r   r   r	   Ú__all__r
   rQ   r   rt   r`   ra   rc   rb   r   r   r   Ú<module>r’      sé   ðñó Û Ý Ý 6÷M÷ Mð Ð,Ð
-€ñ ÓÙÙñð Ñ!2¸4ØôöJóó ðJôZñ ÓÙÙ˜1Ñ.?Ø0ôð|(ð !%ð|(ð ð	|(ð
 ð|(ð ö|(ó	ó ð
|(ò~+ò"ò=ò"ô .r   