ó
    †ñ:i"!  ã                   ó>   • S SK rSSKJrJr  SSKJr   " S S\5      rg)é    Né   )ÚMaskedModelÚsafe_isinstanceé   )Ú	Explainerc                   ó\   ^ • \ rS rSrSrSU 4S jjrSSS.U 4S jjr\S 5       rS	 r	S
r
U =r$ )ÚAdditiveExplaineré   a  Computes SHAP values for generalized additive models.

This assumes that the model only has first-order effects. Extending this to
second- and third-order effects is future work (if you apply this to those models right now
you will get incorrect answers that fail additivity).
Nc           
      ó,  >• [         T
U ]  XXES9  [        US5      (       a:  UR                  U l        U R
                  c  UR                  U l        [        S5      e[        U R
                  S5      (       d   S5       e[        U R                  U R
                  U R                  U R                  [        R                  " U R
                  R                  S   5      5      n[        R                  " U R
                  R                  S   S-   U R
                  R                  S   4[         S9n[#        SU R
                  R                  S   S-   5       H  nS	XxUS-
  4'   M     U" U5      n	U	S
   U l        [        R                  " UR                  S   5      U l        [#        SU R
                  R                  S   S-   5       H$  nX˜   U R$                  -
  U R&                  US-
  '   M&     U R&                  R)                  5       U R$                  -   U l        g)a¬  Build an Additive explainer for the given model using the given masker object.

Parameters
----------
model : function
    A callable python object that executes the model given a set of input data samples.

masker : function or numpy.array or pandas.DataFrame
    A callable python object used to "mask" out hidden features of the form ``masker(mask, *fargs)``.
    It takes a single a binary mask and an input sample and returns a matrix of masked samples. These
    masked samples are evaluated using the model function and the outputs are then averaged.
    As a shortcut for the standard masking used by SHAP you can pass a background data matrix
    instead of a function and that matrix will be used for masking. To use a clustering
    game structure you can pass a ``shap.maskers.Tabular(data, hclustering="correlation")`` object, but
    note that this structure information has no effect on the explanations of additive models.

)Úfeature_namesÚlinearize_linkú0interpret.glassbox.ExplainableBoostingClassifierNziMasker not given and we don't yet support pulling the distribution centering directly from the EBM model!zshap.maskers.IndependentzFThe Additive explainer only supports the Tabular masker at the moment!r   )ÚdtypeFr   )ÚsuperÚ__init__r   Údecision_functionÚmodelÚmaskerÚ
intercept_Ú_expected_valueÚNotImplementedErrorr   Úlinkr   ÚnpÚzerosÚshapeÚonesÚboolÚrangeÚ_zero_offsetÚ_input_offsetsÚsum)Úselfr   r   r   r   r   ÚfmÚmasksÚiÚoutputsÚ	__class__s             €Ú\/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/shap/explainers/_additive.pyr   ÚAdditiveExplainer.__init__   sÊ  ø€ ô$ 	‰Ñ˜°mÐÑcä˜5Ð"T×UÑUØ×0Ñ0ˆDŒJà�{‰{Ñ"Ø',×'7Ñ'7�Ô$ô *Øóð ô ˜tŸ{™{Ð,F×GÑGð 	
ØTó	
ÐGô
 ˜Ÿ™ T§[¡[°$·)±)¸T×=PÑ=PÔRT×RZÒRZÐ[_×[fÑ[f×[lÑ[lÐmnÑ[oÓRpÓqˆÜ—’˜Ÿ™×*Ñ*¨1Ñ-°Ñ1°4·;±;×3DÑ3DÀQÑ3GÐHÔPTÑUˆÜ�q˜$Ÿ+™+×+Ñ+¨AÑ.°Ñ2Ö3ˆAØ#ˆE�Q˜‘U�(‹Oñ 4á�U“)ˆØ# A™JˆÔÜ Ÿhšh v§|¡|°A¡Ó7ˆÔÜ�q˜$Ÿ+™+×+Ñ+¨AÑ.°Ñ2Ö3ˆAØ)0©°d×6GÑ6GÑ)GˆD×Ñ  A¡Ó&ñ 4ð  $×2Ñ2×6Ñ6Ó8¸4×;LÑ;LÑLˆÕó    F©Ú	max_evalsÚsilentc                ó$   >• [         TU ]  " X1US.6$ )z^Explains the output of model(*args), where args represents one or more parallel iterable args.r+   )r   Ú__call__)r"   r,   r-   Úargsr'   s       €r(   r/   ÚAdditiveExplainer.__call__G   s   ø€ ô ‰wÒ À6ÒJÐJr*   c                 ó^   • [        U S5      (       a  U R                  S:w  a  [        S5      egg)z†Determines if this explainer can handle the given model.

This is an abstract static method meant to be implemented by each subclass.
r   r   z,Need to add support for interaction effects!TF)r   Úinteractionsr   )r   r   s     r(   Úsupports_model_with_maskerÚ,AdditiveExplainer.supports_model_with_maskerM   s2   € ô ˜5Ð"T×UÑUØ×!Ñ! QÓ&Ü)Ð*XÓYÐYØàr*   c          	      óˆ  • US   n[         R                  " [        U5      [        U5      45      n	[        [        U5      5       H  n
XŠ   XšU
4'   M     U R	                  U	5      U R
                  -
  U R                  -
  nUU R                  U Vs/ s H  oÌR                  PM     snU[        U R                  SS5      S.$ s  snf )z_Explains a single row and returns the tuple (row_values, row_expected_values, row_mask_shapes).r   Ú
clusteringN)ÚvaluesÚexpected_valuesÚmask_shapesÚmain_effectsr7   )r   r   Úlenr   r   r   r    r   r   Úgetattrr   )r"   r,   r;   Úerror_boundsÚ
batch_sizer&   r-   Úrow_argsÚxÚinputsr%   ÚphiÚas                r(   Úexplain_rowÚAdditiveExplainer.explain_rowZ   s¯   € à�Q‰KˆÜ—’œ3˜q›6¤3 q£6Ð*Ó+ˆÜ”s˜1“v–ˆAØ™4ˆF�a�4‹Lñ ð �j‰j˜Ó  4×#4Ñ#4Ñ4°t×7JÑ7JÑJˆð Ø#×3Ñ3Ù-5Ó6ªX¨ŸGœG©XÑ6ØÜ! $§+¡+¨|¸TÓBñ
ð 	
ùò 7s   ÂB?)r   r    r   r   )NNT)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r/   Ústaticmethodr4   rE   Ú__static_attributes__Ú__classcell__)r'   s   @r(   r	   r	      s@   ø† ñ÷6Mðp )-°U÷ Kð Kð ñ
ó ð
÷
ð 
r*   r	   )Únumpyr   Úutilsr   r   Ú
_explainerr   r	   © r*   r(   Ú<module>rS      s   ðÛ ç 0Ý !ôb
˜	õ b
r*   