ó
    †ñ:i&  ã                  óÜ   • % S SK Jr  S SKJrJr  S SKJr  S SKr	SSK
Jr  SSKJr  SSK
Jr  \(       a  S S	KJr  SS
 jrS rS rS rS rS rS rS rSS jr\\-  \-  S-  rS\S'   SS jrg)é    )Úannotations)ÚTYPE_CHECKINGÚ	TypeAliasNé   )ÚExplanation)ÚOpChainé   )Úcolors)ÚColormapc                óB  • [        U [        R                  5      (       a  U $ [        U [        5      (       a  U S:X  a  [        R
                  $ [        U [        5      (       a  U S:X  a  [        R                  $  [        R                  " U 5      $ ! [         a    U s $ f = f)zCConverts a color specification alias into its actual representationÚshap_redÚ	shap_blue)
Ú
isinstanceÚnpÚndarrayÚstrr
   Úred_rgbÚblue_rgbÚpltÚget_cmapÚ
ValueError)Úcolors    ÚT/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/shap/plots/_utils.pyÚconvert_colorr      s|   € ä�%œŸ™×$Ñ$ØˆÜ	�Eœ3×	Ñ	 E¨ZÓ$7Ü�~‰~ÐÜ	�Eœ3×	Ñ	 E¨[Ó$8Ü�‰Ðð	Ü—<’< Ó&Ð&øÜó 	ØŠLð	ús   Á9B ÂBÂBc                óP  • [        [        U 5      [        5      (       a  U R                  [	        U5      5      n [        [        U 5      [        5      (       aO  [        S U R                   5       5      (       a  U R                  n U $ U R                  R                  R                  n U $ )Nc              3  ó>   #   • U  H  oR                   S :H  v •  M     g7f)ÚargsortN)Úname)Ú.0Úops     r   Ú	<genexpr>Ú#convert_ordering.<locals>.<genexpr>#   s   é € ÐBÒ.A¨�w‰w˜)Ö#Ò.Aùs   ‚)
Ú
issubclassÚtyper   Úapplyr   ÚanyÚ
op_historyÚvaluesr   Úflip)ÚorderingÚshap_valuess     r   Úconvert_orderingr,      s|   € Ü”$�x“.¤'×*Ñ*Ø—>‘>¤+¨kÓ":Ó;ˆÜ”$�x“.¤+×.Ñ.ÜÑB¨h×.AÒ.AÓB×BÑBØ—‘ˆHð €Oð  ×'Ñ'×,Ñ,×3Ñ3ˆHØ€Oó    c                óŒ  • [         R                  " U5      nUR                  5       n[        [	        U5      S-
  5       H‚  nX5   nX5S-      nUS-   n[        US-   [	        U5      5       H-  n	X9   n
XU
4   U::  d  M  XU4   U:”  d  XJ   XG   :  d  M)  U
nU	nM/     [        X…S-   S5       H  n	X9S-
     X9'   M     XsUS-   '   M„     U$ )zmReturns a sorted order of the values where we respect the clustering order when dist[i,j] < cluster_thresholdr	   éÿÿÿÿ)r   r   ÚcopyÚrangeÚlen)ÚdistÚclust_orderÚcluster_thresholdÚfeature_orderÚ
clust_indsÚiÚind1Únext_indÚnext_ind_posÚjÚind2s              r   Úget_sort_orderr>   *   sð   € ô —’˜KÓ(€Jà!×&Ñ&Ó(€Mä”3�}Ó%¨Ñ)Ö*ˆØÑˆØ  Q¡Ñ'ˆØ˜1‘uˆÜ�q˜1‘uœc -Ó0Ö1ˆAØ Ñ#ˆDð
 ˜$�JÑÐ#4Õ4ð ˜h˜Ñ'Ð*;Ó;¸zÑ?OÐR\ÑRfÕ?fØ#�HØ#$’Lñ 2ô" �|¨¡U¨BÖ/ˆAà,°©UÑ3ˆMÓñ 0ð  (�a˜!‘eÓñ1 +ð6 Ðr-   c                ó¨  • UR                   S   S-   nSn[        R                  n[        UR                   S   5       Hk  n[	        XS4   5      n[	        XS4   5      nXb:  d  M(  Xr:  d  M/  [        R
                  " X   5      [        R
                  " X   5      -   nX„:  d  Mg  UnUnMm     [	        XS4   5      n[	        XS4   5      nXg:”  a  Un	UnU	nUR                  5       n
[        U
R                   S   5       H¯  n[	        X¥S4   5      n[	        X¥S4   5      nX·:X  a  XjUS4'   O8X·:”  a3  X¥S4==   S-  ss'   X³U-   :X  a  XjUS4'   OX³U-   :”  a  X¥S4==   S-  ss'   XÇ:X  a  XjUS4'   Mr  XÇ:”  d  My  X¥S4==   S-  ss'   XÃU-   :X  a  XjUS4'   M—  XÃU-   :”  d  M¡  X¥S4==   S-  ss'   M±     [        R                  " X£SS9n
[        U
5        X¦U4$ )zGThis merges the two clustered leaf nodes with the smallest total value.r   r	   )Úaxis)	Úshaper   Úinfr1   ÚintÚabsr0   ÚdeleteÚfill_counts)r(   Úpartition_treeÚMÚptindÚmin_valr8   r9   r=   ÚvalÚtmpÚpartition_tree_newÚi0Úi1s                r   Úmerge_nodesrP   S   sù  € à×Ñ˜QÑ !Ñ#€Aà€EÜ�f‰f€GÜ�>×'Ñ'¨Ñ*Ö+ˆÜ�> Q $Ñ'Ó(ˆÜ�> Q $Ñ'Ó(ˆØ�8˜�Ü—&’&˜™Ó&¬¯ª°±Ó)=Ñ=ˆCØ�}Ø�Ø’ñ ,ô ˆ~ Q˜hÑ'Ó(€DÜˆ~ Q˜hÑ'Ó(€DØƒ{ØˆØˆØˆà'×,Ñ,Ó.ÐÜÐ%×+Ñ+¨AÑ.Ö/ˆÜÐ# q DÑ)Ó*ˆÜÐ# q DÑ)Ó*ˆØ‹:Ø'+˜q !˜tÒ$Ø‹YØ !˜tÓ$¨Ñ)Ó$Ø˜Q‘Y‹Ø+/ 1 a 4Ò(Ø˜a‘i“Ø" a 4Ó(¨AÑ-Ó(à‹:Ø'+˜q !˜tÓ$Ø�YØ !˜tÓ$¨Ñ)Ó$Ø˜Q‘Y‹Ø+/ 1 a 4Ó(Ø˜a‘i•Ø" a 4Ó(¨AÑ-Õ(ñ' 0ô( ŸšÐ#5À1ÑEÐô Ð"Ô#à TÐ)Ð)r-   c                óœ   • / n/ n[        UR                  S   S-
  XX#5        [        R                  " U5      [        R                  " U5      4$ )zêReturns the x and y coords of the lines of a dendrogram where the leaf order is given.

Note that scipy can compute these coords as well, but it does not allow you to easily specify
a specific leaf order, hence this reimplementation.
r   r	   )Ú_dendrogram_coords_recrA   r   Úarray)Úleaf_positionsrG   ÚxoutÚyouts       r   Údendrogram_coordsrW   ‡   sF   € ð !€DØ €DÜ˜>×/Ñ/°Ñ2°QÑ6¸ÐX\Ôcä�8Š8�D‹>œ2Ÿ8š8 D›>Ð)Ð)r-   c                ó2  • UR                   S   S-   nU S:  a	  XU-      S4$ [        X S4   5      U-
  n[        X S4   5      U-
  n[        XaX#U5      u  p‰[        XqX#U5      u  p«X S4   nUR                  XˆXª/5        UR                  XœXË/5        XŠ-   S-  U4$ )Nr   r	   r   )rA   rC   rR   Úappend)ÚposrT   rG   rU   rV   rH   ÚleftÚrightÚx_leftÚy_leftÚx_rightÚy_rightÚy_currs                r   rR   rR   ”   sÀ   € Ø×Ñ˜QÑ !Ñ#€Aà
ˆQƒwØ A™gÑ&¨Ð)Ð)äˆ~ 1˜fÑ%Ó&¨Ñ*€DÜ� A˜vÑ&Ó'¨!Ñ+€Eä+¨DÀ.ÐX\Ó]�N€FÜ-¨eÀ^Ð[_Ó`Ñ€Gà ˜FÑ#€Fà‡K�K� Ð2Ô3Ø‡K�K� Ð1Ô2àÑ Ñ! 6Ð)Ð)r-   c           	     ó`  • U R                   S   S-   nU R                  5       n[        UR                   S   5       Hï  nSnX4S4   U:  a2  [        X4S4   5      n[	        U[
        R                  " X   5      5      nO6[        X4S4   5      U-
  n[	        U[
        R                  " X6S4   5      5      nX4S4   U:  a2  [        X4S4   5      n[	        U[
        R                  " X   5      5      nO6[        X4S4   5      U-
  n[	        U[
        R                  " X6S4   5      5      nXSUS4'   Mñ     U$ )zaThis fills the forth column of the partition tree matrix with the max leaf value in that cluster.r   r	   é   )rA   r0   r1   rC   Úmaxr   rD   )rG   Úleaf_valuesrH   Únew_treer8   rK   Úinds          r   Úfill_internal_max_valuesrh   ¨   s"  € à×Ñ˜QÑ !Ñ#€AØ×"Ñ"Ó$€HÜ�8—>‘> !Ñ$Ö%ˆØˆØ�q�D‰>˜AÓÜ�h !˜t‘nÓ%ˆCÜ�cœ2Ÿ6š6 +Ñ"2Ó3Ó4‰Cä�h !˜t‘nÓ%¨Ñ)ˆCÜ�cœ2Ÿ6š6 (°¨6Ñ"2Ó3Ó4ˆCØ�q�D‰>˜AÓÜ�h !˜t‘nÓ%ˆCÜ�cœ2Ÿ6š6 +Ñ"2Ó3Ó4‰Cä�h !˜t‘nÓ%¨Ñ)ˆCÜ�cœ2Ÿ6š6 (°¨6Ñ"2Ó3Ó4ˆCØ��A�‹ñ &ð €Or-   c                ó^  • U R                   S   S-   n[        U R                   S   5       H  nSnXS4   U:  a  [        XS4   5      nUS-  nO[        XS4   5      U-
  nX0US4   -  nXS4   U:  a  [        XS4   5      nUS-  nO[        XS4   5      U-
  nX0US4   -  nX0US4'   M�     g)zThis updates ther   r	   rc   N)rA   r1   rC   )rG   rH   r8   rK   rg   s        r   rF   rF   ¾   sâ   € à×Ñ˜QÑ !Ñ#€AÜ�>×'Ñ'¨Ñ*Ö+ˆØˆØ˜Q˜$Ñ !Ó#Ü�n¨ TÑ*Ó+ˆCØ�1‰H‰Cä�n¨ TÑ*Ó+¨aÑ/ˆCØ # q &Ñ)Ñ)ˆCØ˜Q˜$Ñ !Ó#Ü�n¨ TÑ*Ó+ˆCØ�1‰H‰Cä�n¨ TÑ*Ó+¨aÑ/ˆCØ # q &Ñ)Ñ)ˆCØ"�q˜!�tÓò ,r-   c                ó‚  • Uc  / nUc  [        X5      n U R                  S   S-
  nU R                  S   S-   nUS:  a  UR                  X$-   5        g [        XS4   5      U-
  n[        XS4   5      U-
  nUS:¼  a  XS4   OXU-      nUS:¼  a  XS4   OXU-      nXx:  a  Un	UnU	n[	        XXS5        [	        XXc5        U$ )Nr   r	   rc   )rh   rA   rY   rC   Ú	sort_inds)
rG   re   rZ   ÚindsrH   r[   r\   Úleft_valÚ	right_valrL   s
             r   rk   rk   Ò   sî   € Ø�|Øˆà
�{Ü1°.ÓNˆØ×"Ñ" 1Ñ%¨Ñ)ˆà×Ñ˜QÑ !Ñ#€Aà
ˆQƒwØ�‰�C‘GÔØäˆ~ 1˜fÑ%Ó&¨Ñ*€DÜ� A˜vÑ&Ó'¨!Ñ+€Eà*.°!«)ˆ~ A˜gÒ&¸ÈAÁXÑ9N€HØ,1°Q«J� a˜xÒ(¸KÐPQÉ	Ñ<R€IàÓØˆØˆØˆäˆn¨4Ô6Üˆn¨5Ô7à€Kr-   r   ÚAxisLimitSpecc               óx  • [        U [        5      (       a@   [        U R                  S5      R	                  S5      5      n[        R                  " X5      $ [        U [        5      (       a1  U(       a  [        U R                  5      $ [        U R                  5      $ U $ ! [
         a  n[        S5      UeSnAff = f)ak  Handle axis limits in "percentile(float)" format or from Explanation objects.

Parameters
----------
ax_limit : LimitSpec
    Represents one of the lower or upper bounds of an xlim / ylim of a plot.
    Can be in "percentile(float)" format, a float or an :class:`.Explanation` object that has been aggregated
    into a single value, e.g. ``explanation[:, "feature_name"].percentile(20)``.

ax_values : np.ndarray
    The values represented by the axis in question. Usually the SHAP values or the feature values. Only used if
    ``ax_limit`` is a string of the "percentile(float)" form.

is_shap_axis : bool
    Whether the ``ax_limit`` is describing the axis representing SHAP values, or not. Only relevant when
    ``ax_limit`` is an :class:`.Explanation` object. It is assumed that when False, the axis is representing
    the feature values instead of the SHAP values.

zpercentile(Ú)z9Only strings of the format `percentile(x)` are supported.N)r   r   ÚfloatÚremoveprefixÚremovesuffixr   r   Únanpercentiler   r(   Údata)Úax_limitÚ	ax_valuesÚis_shap_axisÚ
percentageÚes        r   Úparse_axis_limitr|   õ   sŸ   € ô( �(œC× Ñ ð	aÜ˜x×4Ñ4°]ÓC×PÑPÐQTÓUÓVˆJô ×Ò 	Ó6Ð6Ü�(œK×(Ñ(æ)5Œu�X—_‘_Ó%ÐO¼5ÀÇÁÓ;OÐOà€Oøô ó 	aÜÐXÓYÐ_`Ð`ûð	aús   —)B Â
B9Â(B4Â4B9)r   zstr | np.ndarrayÚreturnznp.ndarray | Colormap | str)NN)rw   ro   rx   z
np.ndarrayry   Úboolr}   zfloat | None)Ú
__future__r   Útypingr   r   Úmatplotlib.pyplotÚpyplotr   Únumpyr   Ú r   Úutilsr   r
   Úmatplotlib.colorsr   r   r,   r>   rP   rW   rR   rh   rF   rk   r   rr   ro   Ú__annotations__r|   © r-   r   Ú<module>r‰      sp   ðÞ "ç +å Û å Ý Ý æÝ*ôòò&òR1*òh
*ò*ò(ò,#ô(ð@ '¨Ñ,¨uÑ4°tÑ;€ˆyÓ ;õr-   