
    h                     :    S SK Jr  SSKJr  S/r S
SSSS.S	 jjrg)   )check_shape_equality   )contingency_tableadapted_rand_errorN)    g      ?)tableignore_labelsalphac                   Ub  U b  [        X5        Uc  [        U UUSSS9nOUnUS:  d  US:  a  [        S5      eUR                  UR                  -  UR	                  5       -
  nUR	                  SS9R                  5       nUR	                  S	S9R                  5       nXw-  UR	                  5       -
  n	X-  UR	                  5       -
  n
Xi-  nXj-  nXdU	-  SU-
  U
-  -   -  nSU-
  nXU4$ )
a$  Compute Adapted Rand error as defined by the SNEMI3D contest. [1]_

Parameters
----------
image_true : ndarray of int
    Ground-truth label image, same shape as im_test.
image_test : ndarray of int
    Test image.
table : scipy.sparse array in crs format, optional
    A contingency table built with skimage.evaluate.contingency_table.
    If None, it will be computed on the fly.
ignore_labels : sequence of int, optional
    Labels to ignore. Any part of the true image labeled with any of these
    values will not be counted in the score.
alpha : float, optional
    Relative weight given to precision and recall in the adapted Rand error
    calculation.

Returns
-------
are : float
    The adapted Rand error.
prec : float
    The adapted Rand precision: this is the number of pairs of pixels that
    have the same label in the test label image *and* in the true image,
    divided by the number in the test image.
rec : float
    The adapted Rand recall: this is the number of pairs of pixels that
    have the same label in the test label image *and* in the true image,
    divided by the number in the true image.

Notes
-----
Pixels with label 0 in the true segmentation are ignored in the score.

The adapted Rand error is calculated as follows:

:math:`1 - \frac{\sum_{ij} p_{ij}^{2}}{\alpha \sum_{k} s_{k}^{2} +
(1-\alpha)\sum_{k} t_{k}^{2}}`,
where :math:`p_{ij}` is the probability that a pixel has the same label
in the test image *and* in the true image, :math:`t_{k}` is the
probability that a pixel has label :math:`k` in the true image,
and :math:`s_{k}` is the probability that a pixel has label :math:`k`
in the test image.

Default behavior is to weight precision and recall equally in the
adapted Rand error calculation.
When alpha = 0, adapted Rand error = recall.
When alpha = 1, adapted Rand error = precision.


References
----------
.. [1] Arganda-Carreras I, Turaga SC, Berger DR, et al. (2015)
       Crowdsourcing the creation of image segmentation algorithms
       for connectomics. Front. Neuroanat. 9:142.
       :DOI:`10.3389/fnana.2015.00142`
Farray)r	   	normalizesparse_typeg        g      ?zalpha must be between 0 and 1r   )axisr   )r   r   
ValueErrordatasumravel)
image_true
image_testr   r	   r
   p_ij	sum_p_ij2a_ib_isum_a2sum_b2	precisionrecallfscoreares                  ]/var/www/fran/franai/venv/lib/python3.13/site-packages/skimage/metrics/_adapted_rand_error.pyr   r      s   z *"8Z4} '
 s{eck899 		DII%
2I
(((

 
 
"C
(((

 
 
"C Y"FY"F"IF&.AI+??@F
,C6!!    )NN)_shared.utilsr   _contingency_tabler   __all__r    r!   r    <module>r&      s+    0 1
  !%`"/34s`"r!   