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

Anchors (Ribeiro, Singh and Guestrin, "Anchors: High-Precision Model-Agnostic Explanations", AAAI 2018): an if-then rule around one input that keeps the model's prediction with high probability, whatever the other features do (XAI-4). More...

#include <cstdint>
#include <functional>
#include <limits>
#include <string>
#include <vector>
#include "pulsatrix/json.hpp"
#include "pulsatrix/tensor.hpp"
Include dependency graph for anchors.hpp:

Go to the source code of this file.

Classes

struct  pulsatrix::AnchorOptions
 FindAnchor's settings. The defaults are the reference implementation's, except a beam of 2 and epsilon_stop. More...
 
struct  pulsatrix::AnchorPredicate
 lower < x[feature] <= upper; a missing side is infinite. More...
 
struct  pulsatrix::Anchor
 FindAnchor()'s result. More...
 

Namespaces

namespace  pulsatrix
 

Functions

Anchor pulsatrix::FindAnchor (const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, const std::vector< Tensor > &background, const AnchorOptions &options={})
 Finds an anchor for the model's prediction on input.
 
std::string pulsatrix::DescribeAnchor (const Anchor &anchor, const std::vector< std::string > &feature_names={})
 IF income > 0.71 AND debt <= -0.12 THEN class 1 (precision 0.97, coverage 0.21).
 
JsonValue pulsatrix::ToJson (const Anchor &anchor, const std::vector< std::string > &feature_names={})
 The anchor as a pulsatrix.anchor.v1 document; an infinite bound is null.
 
The KL bounds KL-LUCB uses (Kaufmann and Kalyanakrishnan 2013), as in the reference code.
double pulsatrix::BernoulliKl (double p, double q)
 KL divergence between Bernoulli(p) and Bernoulli(q), with p and q clipped to (0, 1).
 
double pulsatrix::KlUpperBound (double p, double level)
 The largest q >= p with BernoulliKl(p, q) <= level.
 
double pulsatrix::KlLowerBound (double p, double level)
 The smallest q <= p with BernoulliKl(p, q) <= level.
 

Detailed Description

Anchors (Ribeiro, Singh and Guestrin, "Anchors: High-Precision Model-Agnostic Explanations", AAAI 2018): an if-then rule around one input that keeps the model's prediction with high probability, whatever the other features do (XAI-4).

An anchor answers "how to still be this": which conditions, if they hold, keep the prediction. IF income > 0.71 AND debt <= -0.12 THEN class 1, with

  • precision: the share of inputs satisfying the rule that the model gives class 1, estimated by sampling, with a confidence bound;
  • coverage: the share of the background data the rule applies to.

The predicates are the reference implementation's for ordinal features: each feature is cut at the background's percentiles (quartiles by default), and every half-line at a cut that contains the input is a predicate, x > e for cuts below the input and x <= e for cuts above it. An anchor may hold two on one feature, which make an interval. An input satisfying the anchor is drawn by taking a random background row and, for each anchored feature, a background value inside its interval; features are drawn independently of one another, as the reference implementation does when too few rows satisfy every predicate at once.

The search is the paper's: a beam search that adds one predicate at a time, using KL-LUCB to find the most precise candidates with few model calls, and keeps, among the anchors whose precision clears the threshold, the one with the highest coverage.

Note
Precision is estimated, not guaranteed (Anchor::precision_lower is the bound), and an anchor can cover a sliver of the data: read both.