
    0Ph:                         d dl Zd dlmZ ddlmZmZ ddlmZm	Z	 dgZ
d Zd Zd	 Z eegege ed
h          gdd          d
dd            ZdS )    N)linear_sum_assignment   )
StrOptionsvalidate_params)check_arraycheck_consistent_lengthconsensus_scorec                     t          |   t          |  d }t          ||           \  }}t          ||          \  }}||||fS )z9Unpacks the row and column arrays and checks their shape.c                 $    t          | d          S )NF)	ensure_2d)r   )xs    b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/metrics/cluster/_bicluster.py<lambda>z)_check_rows_and_columns.<locals>.<lambda>   s    {1666     )r   map)abchecksa_rowsa_colsb_rowsb_colss          r   _check_rows_and_columnsr      sQ    QQ66F^^NFF^^NFF666))r   c                    | |z                                   ||z                                   z  }|                                  |                                 z  }|                                 |                                 z  }|||z   |z
  z  S )z:Jaccard coefficient on the elements of the two biclusters.)sum)r   r   r   r   intersectiona_sizeb_sizes          r   _jaccardr      st    VO((**fvo-B-B-D-DDLZZ\\FJJLL(FZZ\\FJJLL(F6F?\9::r   c                    	 t          | |          \  j        d         }j        d         	t          j        	fdt	          |          D                       }|S )zComputes pairwise similarity matrix.

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

    r   c                 R    g | ]"fd t                    D             #S )c           	      \    g | ](}                   |         |                   )S  r#   ).0jr   r   r   r   i
similaritys     r   
<listcomp>z3_pairwise_similarity.<locals>.<listcomp>.<listcomp>-   s9    XXXZZq	6!9fQiCCXXXr   )range)r$   r&   r   r   r   r   n_br'   s    @r   r(   z(_pairwise_similarity.<locals>.<listcomp>,   sU     	
 	
 	
 YXXXXXXXXUSVZZXXX	
 	
 	
r   )r   shapenparrayr)   )
r   r   r'   n_aresultr   r   r   r   r*   s
     `  @@@@@r   _pairwise_similarityr0   !   s     &=Q%B%B"FFFF
,q/C
,q/CX	
 	
 	
 	
 	
 	
 	
 	
 	
3ZZ	
 	
 	
 F Mr   jaccard)r   r   r'   T)prefer_skip_nested_validation)r'   c                   |dk    rt           }t          | ||          }t          d|z
            \  }}t          | d                   }t          |d                   }|||f                                         t          ||          z  S )ad  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')
    np.float64(1.0)
    r1   g      ?r   )r   r0   r   lenr   max)r   r   r'   matrixrow_indicescol_indicesr.   r*   s           r   r	   r	   4   s    p Y
!!Q
33F4S6\BBK
ad))C
ad))C+{*+//11CSMMAAr   )numpyr,   scipy.optimizer   utils._param_validationr   r   utils.validationr   r   __all__r   r   r0   tuplecallabler	   r#   r   r   <module>r@      s       0 0 0 0 0 0 B B B B B B B B D D D D D D D D
* * *; ; ;  & WWYK!8!89 
 #'   )2 6B 6B 6B 6B 6B 6B 6Br   