`L i5ddlZddlmZddlmZmZddlmZm Z dgZ dZ dZ d Z eegegeed hgd d d ddZy)N)linear_sum_assignment) StrOptionsvalidate_params) check_arraycheck_consistent_lengthconsensus_scorecpt|t|d}t||\}}t||\}}||||fS)z9Unpacks the row and column arrays and checks their shape.ct|dS)NF) ensure_2d)r)xs h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/metrics/cluster/_bicluster.pyz)_check_rows_and_columns..s {16)rmap)abchecksa_rowsa_colsb_rowsb_colss r_check_rows_and_columnsr sDQQ 6F^NFF^NFF 666 ))rc||zj||zjz}|j|jz}|j|jz}|||z|z z S)z:Jaccard coefficient on the elements of the two biclusters.)sum)rrrr intersectiona_sizeb_sizes r_jaccardrsfVO((*fvo-B-B-DDL ZZ\FJJL (F ZZ\FJJL (F 6F?\9 ::rc.t||\}}}}|jd}|jd}tjt |D cgc]0} t |D cgc]} ||| || || || c} 2c} } } | Scc} wcc} } w)zComputes pairwise similarity matrix. result[i, j] is the Jaccard coefficient of a's bicluster i and b's bicluster j. r)rshapenparrayrange) rr similarityrrrrn_an_bijresults r_pairwise_similarityr+!s&=Q%B"FFFF ,,q/C ,,q/C XX3Z NSSVZ XZq 6!9fQi C X F M Y s B B =B B jaccard)rrr%T)prefer_skip_nested_validation)r%c|dk(rt}t|||}td|z \}}t|d}t|d}t |||fj t ||z S)aXThe 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 `. 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 `__. 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)rr+rlenfloatrmax)rrr%matrix row_indices col_indicesr&r's rr r 4svpY !!Q 3F4S6\BK ad)C ad)C  [01557#c3-G HHr)numpyr"scipy.optimizerutils._param_validationrrutils.validationrr__all__rrr+tuplecallabler rrr=sm0BD  *;&WWYK!89 #' )26I6Ir