pulsatrix 1.1.0
Loading...
Searching...
No Matches
contrastive.hpp File Reference

The contrastive explanation method (CEM; Dhurandhar et al., "Explanations based on the Missing", NeurIPS 2018): pertinent negatives, what is absent from an input and would change its class if present, and pertinent positives, the least of the input that keeps its class on its own (XAI-4). More...

#include <cstdint>
#include <string>
#include <vector>
#include "pulsatrix/explainer_context.hpp"
#include "pulsatrix/json.hpp"
#include "pulsatrix/tensor.hpp"
Include dependency graph for contrastive.hpp:

Go to the source code of this file.

Classes

struct  pulsatrix::ContrastiveOptions
 CEM's settings. The defaults are the paper's MNIST settings, scaled to its 1,000 steps. More...
 
struct  pulsatrix::ContrastiveResult
 A pertinent negative or positive. More...
 

Namespaces

namespace  pulsatrix
 

Functions

ContrastiveResult pulsatrix::FindPertinentNegative (ExplainerContext &ctx, const Tensor &input, const ContrastiveOptions &options={})
 The pertinent negative of input: what would have to be added, where the input has nothing, to change its class.
 
ContrastiveResult pulsatrix::FindPertinentPositive (ExplainerContext &ctx, const Tensor &input, const ContrastiveOptions &options={})
 The pertinent positive of input: the least of it that the model still gives its class.
 
JsonValue pulsatrix::ToJson (const ContrastiveResult &result, const std::string &kind)
 The result as a pulsatrix.contrastive.v1 document; kind is "pertinent_negative" or "pertinent_positive".
 

Detailed Description

The contrastive explanation method (CEM; Dhurandhar et al., "Explanations based on the Missing", NeurIPS 2018): pertinent negatives, what is absent from an input and would change its class if present, and pertinent positives, the least of the input that keeps its class on its own (XAI-4).

Both are found by FISTA on an elastic-net objective, with a binary search over the weight of the prediction loss, as in the paper. With x the input, t0 its class, z the model's outputs and b the absence value of each feature (the baseline, 0 by default):

  • a pertinent negative is the sparsest δ >= 0 on features absent from x (x_j == b_j) such that x + δ is no longer class t0. It minimizes c · max(z_t0(x + δ) - max_{i != t0} z_i(x + δ), -κ) + β |δ|_1 + |δ|_2^2;
  • a pertinent positive is the sparsest part δ of x - b, each feature between b_j and x_j, such that b + δ alone is still class t0. It minimizes c · max(max_{i != t0} z_i(b + δ) - z_t0(b + δ), -κ) + β |δ|_1 + |δ|_2^2.

The paper also adds an autoencoder's reconstruction error to keep δ on the data manifold; that term isn't here, so on images a pertinent negative can look like noise to a person.