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

Explanation-quality metrics in the Quantus families (roadmap XAI-5): faithfulness (deletion and insertion curves, with ROAD's imputation), randomization (the model-parameter randomization test) and complexity (sparseness and complexity). More...

#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include "pulsatrix/attribution.hpp"
#include "pulsatrix/module.hpp"
#include "pulsatrix/tensor.hpp"
Include dependency graph for explanation_metrics.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pulsatrix::Imputation
 How a removed feature is filled in when perturbing an input. More...
 
struct  pulsatrix::PerturbationOptions
 Options for DeletionCurve() and InsertionCurve(). More...
 
struct  pulsatrix::PerturbationCurve
 A perturbation curve: the target score after each fraction of features was changed. More...
 
struct  pulsatrix::RandomizationResult
 The model-parameter randomization test's result. More...
 

Namespaces

namespace  pulsatrix
 

Typedefs

using pulsatrix::PredictFn = std::function< Tensor(const Tensor &input)>
 The model as a function: input (with a leading batch dimension of 1) to outputs.
 
using pulsatrix::ExplainFn = std::function< Attribution(const Tensor &input)>
 Explains input using the model in its current state.
 

Functions

float pulsatrix::Sparseness (const Attribution &attribution)
 Gini index of the attribution magnitudes (Chalasani et al. 2020; Quantus Sparseness): 0 when relevance is spread evenly, approaching 1 when one feature holds it all.
 
float pulsatrix::Complexity (const Attribution &attribution)
 Entropy of the fractional contributions |a_i| / sum |a| (Bhatt et al. 2020; Quantus Complexity), natural log: 0 when one feature holds all relevance, ln n when spread evenly.
 
float pulsatrix::SpearmanRankCorrelation (const std::vector< float > &x, const std::vector< float > &y)
 Spearman rank correlation, with tied values given their average rank.
 
Tensor pulsatrix::Impute (const Tensor &input, const std::vector< bool > &removed, const Imputation &imputation)
 Returns input with every element whose removed flag is set filled by imputation.
 
PerturbationCurve pulsatrix::DeletionCurve (const PredictFn &predict, const Tensor &input, const Attribution &attribution, const PerturbationOptions &options={})
 Deletion (MoRF): removes features from most to least relevant, imputing them, and records the target score. A faithful attribution makes the score drop fast: lower AUC is better.
 
PerturbationCurve pulsatrix::InsertionCurve (const PredictFn &predict, const Tensor &input, const Attribution &attribution, const PerturbationOptions &options={})
 Insertion: starts from the fully imputed input and restores features from most to least relevant. A faithful attribution makes the score rise fast: higher AUC is better.
 
RandomizationResult pulsatrix::ModelParameterRandomizationTest (Module &model, const ExplainFn &explain, const Tensor &input, uint64_t seed)
 The model-parameter randomization test (Adebayo et al., "Sanity Checks for Saliency Maps", NeurIPS 2018), cascading: randomizes the model's layers from the output down, re-explains input after each, and measures how similar the explanation stays.
 
RandomizationResult pulsatrix::ModelParameterRandomizationTest (Module &model, const ExplainFn &explain, const Tensor &input, uint64_t seed, const std::vector< std::string > &layers)
 ModelParameterRandomizationTest over layers, in the order given: each a prefix of named_parameters() names, such as "layers.11", randomized cumulatively.
 

Detailed Description

Explanation-quality metrics in the Quantus families (roadmap XAI-5): faithfulness (deletion and insertion curves, with ROAD's imputation), randomization (the model-parameter randomization test) and complexity (sparseness and complexity).

Note
Explainer-agnostic: the faithfulness metrics take a prediction function and a finished Attribution; the randomization test takes a function that explains an input with the model as it currently is.