robustx.generators.CE_methods package

Submodules

robustx.generators.CE_methods.BinaryLinearSearch module

class robustx.generators.CE_methods.BinaryLinearSearch.BinaryLinearSearch(ct, custom_distance_func=None)[source]

Bases: CEGenerator

A counterfactual explanation generator that uses binary linear search to find counterfactual explanations.

Inherits from the CEGenerator class and implements the _generation_method to perform binary linear search for generating counterfactuals.

_task

The task to solve, inherited from CEGenerator.

Type:

Task

__customFunc

A custom distance function, inherited from CEGenerator.

Type:

callable, optional

robustx.generators.CE_methods.GuidedBinaryLinearSearch module

class robustx.generators.CE_methods.GuidedBinaryLinearSearch.GuidedBinaryLinearSearch(ct, custom_distance_func=None)[source]

Bases: CEGenerator

robustx.generators.CE_methods.KDTreeNNCE module

class robustx.generators.CE_methods.KDTreeNNCE.KDTreeNNCE(ct, custom_distance_func=None)[source]

Bases: CEGenerator

A counterfactual explanation generator that uses KD-Tree for nearest neighbor counterfactual explanations.

Inherits from the CEGenerator class and implements the _generation_method to find counterfactual explanations using KD-Tree for nearest neighbors.

_task

The task to solve, inherited from CEGenerator.

Type:

Task

__customFunc

A custom distance function, inherited from CEGenerator.

Type:

callable, optional

robustx.generators.CE_methods.MCE module

class robustx.generators.CE_methods.MCE.MCE(ct)[source]

Bases: CEGenerator

A counterfactual explanation generator that uses Mixed-Integer Linear Programming (MILP) to find counterfactual explanations.

Inherits from the CEGenerator class and implements the _generation_method to find counterfactual explanations using MILP with the Gurobi optimizer.

_task

The task to solve, inherited from CEGenerator.

Type:

Task

__customFunc

A custom distance function, inherited from CEGenerator.

Type:

callable, optional

opt

An optimizer instance for setting up and solving the MILP problem.

Type:

OptSolver

robustx.generators.CE_methods.NNCE module

class robustx.generators.CE_methods.NNCE.NNCE(ct, custom_distance_func=None)[source]

Bases: CEGenerator

A counterfactual explanation generator that uses a nearest-neighbor counterfactual explanation (NNCE) approach.

Inherits from CEGenerator and calculates counterfactual explanations based on the nearest neighbor in the training data with the desired prediction.

_task

The task to solve, inherited from CEGenerator.

Type:

Task

__customFunc

A custom distance function, inherited from CEGenerator.

Type:

callable, optional

robustx.generators.CE_methods.Wachter module

class robustx.generators.CE_methods.Wachter.CostLoss[source]

Bases: Module

Custom loss function to calculate the absolute difference between two tensors.

Inherits from nn.Module.

forward(x1, x2)[source]

Computes the forward pass of the loss function.

@param x1: The first tensor (e.g., the original instance). @param x2: The second tensor (e.g., the counterfactual instance). @return: The absolute difference between x1 and x2.

class robustx.generators.CE_methods.Wachter.Wachter(ct, custom_distance_func=None)[source]

Bases: CEGenerator

A counterfactual explanation generator that uses Wachter’s method for finding counterfactual explanations.

Inherits from CEGenerator and implements the _generation_method to find counterfactuals using gradient descent.

Module contents