robustx.generators.robust_CE_methods package
Submodules
robustx.generators.robust_CE_methods.APAS module
- class robustx.generators.robust_CE_methods.APAS.APAS(task, CE_generator=<class 'robustx.generators.CE_methods.KDTreeNNCE.KDTreeNNCE'>, alpha=0.999)[source]
Bases:
CEGenerator
A counterfactual explanation generator that uses any CEGenerator class and a ApproximateDeltaRobustnessEvaluator evaluator to find counterfactual explanations that are approximately robust against model changes.
Inherits from the CEGenerator class and implements the _generation_method to generate counterfactual examples with approximate robustness checks using a specified confidence alpha. The method iterates over positive instances and evaluates their robustness, returning those with stable counterfactuals.
This is a similar implementation of Marzari et. al “Rigorous Probabilistic Guarantees for Robust Counterfactual Explanations”, ECAI 2024
- CE_generator specific to this class, but utilizes the task and model from the RecourseCE base class.
- alpha = confidence level in the robustness evaluator
robustx.generators.robust_CE_methods.ArgEnsembling module
- class robustx.generators.robust_CE_methods.ArgEnsembling.ArgEnsembling(dl, models)[source]
Bases:
CEGenerator
A counterfactual explanation generator that deals with the model multiplicity / predictive multiplicity scenario. Use computational argumentation to resolve conflicts, select the models which agree on classification results, and whose counterfactuals are valid on the other models in the set.
This is a simplified version of Jiang et al. AAMAS 2024 paper, not implementing preferences over models.
- models
The set of models with which the model multiplicity problem is instantiated
- dl
The dataset
robustx.generators.robust_CE_methods.DiverseRobustCE module
- class robustx.generators.robust_CE_methods.DiverseRobustCE.DiverseRobustCE(ct, custom_distance_func=None)[source]
Bases:
CEGenerator
A counterfactual explanation generator that returns a set of diverse counterfactuals for the purpose of robustness against input perturbations, i.e. similar inputs will receive similar counterfactuals.
robustx.generators.robust_CE_methods.MCER module
- class robustx.generators.robust_CE_methods.MCER.MCER(ct, evaluator=<class 'robustx.robustness_evaluations.DeltaRobustnessEvaluator.DeltaRobustnessEvaluator'>)[source]
Bases:
CEGenerator
A counterfactual explanation generator that uses the Mixed-Integer Linear Programming (MILP) method and a robustness evaluator to find counterfactual explanations that are robust against perturbations.
Inherits from CEGenerator and combines MCE with a robustness evaluation mechanism.
- __customFunc
A custom distance function, inherited from CEGenerator.
- Type:
callable, optional
- evaluator
An instance of the DeltaRobustnessEvaluator for evaluating robustness.
- Type:
robustx.generators.robust_CE_methods.ModelMultiplicityMILP module
- class robustx.generators.robust_CE_methods.ModelMultiplicityMILP.ModelMultiplicityMILP(dl, models)[source]
Bases:
CEGenerator
robustx.generators.robust_CE_methods.PROPLACE module
- class robustx.generators.robust_CE_methods.PROPLACE.PROPLACE(ct)[source]
Bases:
CEGenerator
A counterfactual explanation generator that finds provably robust counterfactual explanations for MLPs.
Inherits from the CEGenerator class and implements the _generation_method to perform MILP based robust optimisation.
- achieved
boolean variable indicating whether to end the robust optimisation procedure
- x_prime_star
optimal counterfactual
- x_prime_current
current counterfactual as the robust optimisation proceeds
- layers
list of model dimensions for each layer
- neg_value
the undesirable class label
- delta
hyperparameter, the infinity-norm magnitude of model parameter perturbations
- orig_w
weight dictionary of the original model
- orig_b
bias dictionary of the original model
- w_primes
the list of the worst perturbations’ weight dictionaries computed by robust optimisation
- b_primes
the list of the worst perturbations’ bias dictionaries computed by robust optimisation
- rnce
the RNCE recourse generator, used upfront for obtaining the plausible region
robustx.generators.robust_CE_methods.RNCE module
- class robustx.generators.robust_CE_methods.RNCE.RNCE(task)[source]
Bases:
CEGenerator
A counterfactual explanation generator that finds robust nearest counterfactual examples using KDTree.
Inherits from the CEGenerator class and implements the _generation_method to find counterfactual examples that are robust to perturbations. It leverages KDTree for nearest neighbor search and uses a robustness evaluator to identify robust instances in the training data.
- intabs
An evaluator for checking the robustness of instances to perturbations.
- Type:
- getCandidates(robustInit, delta, bias_delta, column_name='target', neg_value=0)[source]
Retrieves candidate instances from the dataset that are robust to perturbations.
@param robustInit: If True, only robust instances are considered. @param delta: The tolerance for robustness in the feature space. @param bias_delta: The bias tolerance for robustness in the feature space. @param column_name: The name of the target column. @param neg_value: The value considered negative in the target variable. @return: A DataFrame containing robust instances from the dataset.
robustx.generators.robust_CE_methods.ROAR module
- class robustx.generators.robust_CE_methods.ROAR.ROAR(ct, custom_distance_func=None)[source]
Bases:
CEGenerator
A CE generator that uses gradient based robust optimisation, targeting robustness to model changes, for linear models. Below codes are adapted from the carla-recourse library https://github.com/carla-recourse/CARLA: https://github.com/carla-ce/CARLA/blob/main/carla/ce_methods/catalog/roar/library/roar.py
robustx.generators.robust_CE_methods.STCE module
- class robustx.generators.robust_CE_methods.STCE.STCE(ct, custom_distance_func=None)[source]
Bases:
CEGenerator
A counterfactual explanation generator that uses the T-Rex method for finding robust counterfactual explanations.
Inherits from the CEGenerator class and implements the _generation_method to find counterfactual examples with robustness checks using a specified base method and evaluator. The method iterates over positive instances and evaluates their robustness, returning those with stable counterfactuals.
- None specific to this class, but utilizes the task and model from the CEGenerator base class.