ó
    Ñ]j?  ã                   ó�   • S SK rS SKJr  S SKJrJr  S SKJrJ	r	  S/r
S rS rS r\" \/\/\\" S	15      /S
.SS9S	S.S j5       rg)é    N)Úlinear_sum_assignment)Ú
StrOptionsÚvalidate_params)Úcheck_arrayÚcheck_consistent_lengthÚconsensus_scorec                 ód   • [        U 6   [        U6   S n[        X 5      u  p4[        X!5      u  pVX4XV4$ )z9Unpacks the row and column arrays and checks their shape.c                 ó   • [        U SS9$ )NF)Ú	ensure_2d)r   )Úxs    Ú_/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/metrics/cluster/_bicluster.pyÚ<lambda>Ú)_check_rows_and_columns.<locals>.<lambda>   s   € ”{ 1°Ò6ó    )r   Úmap)ÚaÚbÚchecksÚa_rowsÚa_colsÚb_rowsÚb_colss          r   Ú_check_rows_and_columnsr      s8   € ä˜QÑÜ˜QÑÙ6€FÜ˜“^�N€FÜ˜“^�N€FØ˜6Ð)Ð)r   c                 óä   • X-  R                  5       X-  R                  5       -  nU R                  5       UR                  5       -  nUR                  5       UR                  5       -  nXEU-   U-
  -  $ )z:Jaccard coefficient on the elements of the two biclusters.)Úsum)r   r   r   r   ÚintersectionÚa_sizeÚb_sizes          r   Ú_jaccardr      s`   € à‘O×(Ñ(Ó*¨f©o×-BÑ-BÓ-DÑD€Là�Z‰Z‹\˜FŸJ™J›LÑ(€FØ�Z‰Z‹\˜FŸJ™J›LÑ(€Fà F™?¨\Ñ9Ñ:Ð:r   c                 ó,  • [        X5      u  p4pVUR                  S   nUR                  S   n[        R                  " [	        U5       V	V
s/ s H/  n	[	        U5       V
s/ s H  o¢" X9   XI   XZ   Xj   5      PM     sn
PM1     sn
n	5      nU$ s  sn
f s  sn
n	f )zwComputes pairwise similarity matrix.

result[i, j] is the Jaccard coefficient of a's bicluster i and b's
bicluster j.

r   )r   ÚshapeÚnpÚarrayÚrange)r   r   Ú
similarityr   r   r   r   Ún_aÚn_bÚiÚjÚresults               r   Ú_pairwise_similarityr+   !   s—   € ô &=¸QÓ%BÑ"€F�FØ
�,‰,�q‰/€CØ
�,‰,�q‰/€CÜ�XŠXô ˜3”Zô	
â�ô NSÐSVÌZÓXÊZÈˆZ˜™	 6¡9¨f©i¸¹ÖCÉZÔXÙò	
ó€Fð €Mùò	 Yùó	
s   ÁB
ÁBÁ:B
ÂB
Újaccard)r   r   r%   T)Úprefer_skip_nested_validation)r%   c                óÜ   • US:X  a  [         n[        XU5      n[        SU-
  5      u  pE[        U S   5      n[        US   5      n[	        X4U4   R                  5       [        Xg5      -  5      $ )aÄ  The similarity of two sets of biclusters.

Similarity between individual biclusters is computed. Then the best
matching between sets is found by solving a linear sum assignment problem,
using a modified Jonker-Volgenant algorithm.
The final score is the sum of similarities divided by the size of
the larger set.

Read more in the :ref:`User Guide <biclustering>`.

Parameters
----------
a : tuple (rows, columns)
    Tuple of row and column indicators for a set of biclusters.

b : tuple (rows, columns)
    Another set of biclusters like ``a``.

similarity : 'jaccard' or callable, default='jaccard'
    May be the string "jaccard" to use the Jaccard coefficient, or
    any function that takes four arguments, each of which is a 1d
    indicator vector: (a_rows, a_columns, b_rows, b_columns).

Returns
-------
consensus_score : float
   Consensus score, a non-negative value, sum of similarities
   divided by size of larger set.

See Also
--------
scipy.optimize.linear_sum_assignment : Solve the linear sum assignment problem.

References
----------
* Hochreiter, Bodenhofer, et. al., 2010. `FABIA: factor analysis
  for bicluster acquisition
  <https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2881408/>`__.

Examples
--------
>>> from sklearn.metrics import consensus_score
>>> a = ([[True, False], [False, True]], [[False, True], [True, False]])
>>> b = ([[False, True], [True, False]], [[True, False], [False, True]])
>>> consensus_score(a, b, similarity='jaccard')
1.0
r,   g      ð?r   )r   r+   r   ÚlenÚfloatr   Úmax)r   r   r%   ÚmatrixÚrow_indicesÚcol_indicesr&   r'   s           r   r   r   4   sn   € ðp �YÓÜˆ
Ü! !¨
Ó3€FÜ4°S¸6±\ÓBÑ€KÜ
ˆa�‰d‹)€CÜ
ˆa�‰d‹)€CÜ� [Ð0Ñ1×5Ñ5Ó7¼#¸c»-ÑGÓHÐHr   )Únumpyr"   Úscipy.optimizer   Úsklearn.utils._param_validationr   r   Úsklearn.utils.validationr   r   Ú__all__r   r   r+   ÚtupleÚcallabler   © r   r   Ú<module>r=      sm   ðó Ý 0ç Gß IàÐ
€ò*ò;òñ& àˆWØˆWØ¡¨Y¨KÓ!8Ð9ñð
 #'ñð )2ô 6Ióñ6Ir   