DiCEExplainer<T>

Models & Types · AiDotNet.Interpretability.Explainers

DiCE (Diverse Counterfactual Explanations) explainer using genetic algorithm-based search.

Implements: IGPUAcceleratedExplainer<T>, ILocalExplainer<T, DiCEExplanation<T>>

For Beginners

DiCE generates MULTIPLE diverse counterfactual explanations, not just one. This is much more useful in practice because:

  1. Multiple options: “You could get a loan by EITHER increasing income OR

reducing debt” instead of just one path

  1. Diversity: The counterfactuals are intentionally different from each other
  2. Actionability: Respects constraints like “you can’t become younger”
  3. Realism: Changes are minimal and realistic

How DiCE works: Uses a genetic algorithm to evolve a population of candidate counterfactuals, optimizing for:

  • Validity: Must achieve the target prediction
  • Proximity: Stay close to the original instance
  • Sparsity: Change as few features as possible
  • Diversity: Counterfactuals should differ from each other

Example output: Original: Loan denied (income=$40k, debt=$30k, employed=No) Counterfactual 1: Loan approved (income=$50k, debt=$30k, employed=No) Counterfactual 2: Loan approved (income=$40k, debt=$20k, employed=No) Counterfactual 3: Loan approved (income=$40k, debt=$30k, employed=Yes)

Each shows a DIFFERENT way to get approved!

Constructors

Constructor Summary
DiCEExplainer(Func<Matrix<T>, Vector<T>> predictFunction, int numFeatures, int numCounterfactuals, int populationSize, int maxGenerations, double diversityWeight, double proximityWeight, double sparsityWeight, double targetThreshold, double mutationRate, double crossoverRate, string[] featureNames, T[] featureMins, T[] featureMaxs, bool[] featuresMutable, FeatureType[] featureTypes, int? randomState) Initializes a new DiCE explainer.

Properties

Property Summary
bool IsGPUAccelerated { get; }
bool SupportsGlobalExplanations { get; }
bool SupportsLocalExplanations { get; }
string MethodName { get; }

Methods

Method Summary
DiCEExplanation<T> Explain(Vector<T> instance) Generates diverse counterfactual explanations for an instance.
DiCEExplanation<T> ExplainWithTarget(Vector<T> instance, T targetValue) Generates diverse counterfactual explanations for a specific target.
DiCEExplanation<T>[] ExplainBatch(Matrix<T> instances)
void SetGPUHelper(GPUExplainerHelper<T> helper)