paulnovello / HSIC-Attribution-Method

13 stars 1 forks source link

The environment version #1

Open RuoyuChen10 opened 1 year ago

RuoyuChen10 commented 1 year ago

Thanks for your amazing work. When I try the demo in ipynb, it raises the error:

No module named 'xplique.attributions.sobol'

It seems that the latest xplique version doesn't support sobol. Can you tell which xplique version do you use? Thanks.

RuoyuChen10 commented 1 year ago

I solve it by make a little change in file xplique_addons.py:

import tensorflow as tf
import tensorflow_probability as tfp

import xplique.attributions.global_sensitivity_analysis.perturbations as PerturbationFunction
from xplique.attributions import *
from xplique.metrics import *
from xplique.attributions.global_sensitivity_analysis.samplers import *
from xplique.attributions.global_sensitivity_analysis.hsic_estimators import *
from xplique.types import Callable, Union, Optional, Tuple
from xplique.commons import batch_tensor, repeat_labels
from xplique.attributions.base import BlackBoxExplainer, sanitize_input_output
from xplique.attributions.global_sensitivity_analysis.perturbations import amplitude, inpainting, blurring
from xplique.attributions.global_sensitivity_analysis.sobol_attribution_method import *
class HsicAttributionMethod(SobolAttributionMethod):

    def __init__(
        self,
        model,
        grid_size,
        nb_design,
        sampler,
        estimator,
        perturbation_function,
        batch_size=256
    ):

        BlackBoxExplainer.__init__(self, model, batch_size)

        self.grid_size = grid_size
        self.nb_design = nb_design

        if isinstance(perturbation_function, str):
            if perturbation_function == "inpainting":
              self.perturbation_function = PerturbationFunction.inpainting
            else:
              self.perturbation_function = PerturbationFunction.blurring
            # self.perturbation_function = PerturbationFunction.from_string(perturbation_function)
        else:
            self.perturbation_function = perturbation_function

        self.sampler = sampler 
        self.estimator = estimator

        self.masks = self.sampler(grid_size**2, nb_design).reshape((-1, grid_size, grid_size, 1))

Then will be ok.

paulnovello commented 1 year ago

Thank you very much for pointing out this issue. The error comes from a recent update of Xplique (0.4.2 -> 0.4.3), that changed the namespaces of the GSA based attribution methods to include HSIC. I have updated the README to indicate that the repo uses Xplique 0.4.2 and will not work with 0.4.3.

However, since important efforts have been made by me and my team to add HSIC attribution method directly in Xplique, I choose not to update the code of the present repo, which will no longer be maintained. You can find the new (nicer, and more robust) implementation of HSIC at https://github.com/deel-ai/xplique.

That said, this code might still be useful if you want to assess the interactions because this feature is not yet included in xplique.