pulsatrix
Loading...
Searching...
No Matches
pulsatrix::LRP Class Reference

Whole-model LRP: runs the forward pass, seeds relevance at the chosen output(s), and propagates it to the input through every module's own propagate_relevance() rule. More...

#include <lrp.hpp>

Public Member Functions

 LRP (LRPRuleConfig config=LRPRuleConfig{})
 Uniform rule: every module applies config.
 
 LRP (LRPComposite composite, std::string name="custom")
 Per-layer rules from a composite; name is reported as "composite:<name>".
 
Attribution explain (ExplainerContext &ctx, const Tensor &input, int64_t target_index, DeviceBackend *backend) const
 Explains target_index for every row, OutputValue seed.
 
Attribution explain (ExplainerContext &ctx, const Tensor &input, const LRPTarget &target, DeviceBackend *backend) const
 Explains the given target(s) / contrast(s).
 
const LRPRuleConfig & config () const
 The uniform config (default-constructed when this LRP uses a composite).
 
const LRPComposite & composite () const
 The composite, or an empty function for a uniform-rule LRP.
 

Static Public Member Functions

static LRP epsilon_plus (float epsilon=1e-6f)
 Zennit EpsilonPlus preset (lrp_composite::epsilon_plus).
 
static LRP epsilon_gamma_box (float low, float high, float gamma=0.25f, float epsilon=1e-6f)
 Zennit EpsilonGammaBox preset (lrp_composite::epsilon_gamma_box).
 
static LRP epsilon_alpha2_beta1 (float epsilon=1e-6f)
 Zennit EpsilonAlpha2Beta1 preset (lrp_composite::epsilon_alpha2_beta1).
 

Detailed Description

Whole-model LRP: runs the forward pass, seeds relevance at the chosen output(s), and propagates it to the input through every module's own propagate_relevance() rule.

Note
The per-layer rules are the ones each Module implements (see each module's propagate_relevance() doc); either one config is passed to all of them, or an LRPComposite chooses one per module. A module asked for a rule it does not implement throws (ExplainerContext::relevance_pass) – there is no silent fallback to epsilon. With LRPRuleConfig::epsilon_bias_in_denominator set, bias terms absorb relevance, and the AttnLRP softmax / attention rules do not conserve exactly, so sum(values) matches the seeded total only for conservative stacks. The Attribution's metadata reports both sums.
Device-generic: the seed is assembled on the host (one device->host copy of the network output when seeding with output values) and uploaded through backend, which must be the backend the network's output lives on.

Constructor & Destructor Documentation

◆ LRP() [1/2]

pulsatrix::LRP::LRP ( LRPRuleConfig  config = LRPRuleConfig{})
inlineexplicit

Uniform rule: every module applies config.

◆ LRP() [2/2]

pulsatrix::LRP::LRP ( LRPComposite  composite,
std::string  name = "custom" 
)
inlineexplicit

Per-layer rules from a composite; name is reported as "composite:<name>".

Exceptions
std::invalid_argumentif composite is empty.

Member Function Documentation

◆ composite()

const LRPComposite & pulsatrix::LRP::composite ( ) const
inline

The composite, or an empty function for a uniform-rule LRP.

◆ config()

const LRPRuleConfig & pulsatrix::LRP::config ( ) const
inline

The uniform config (default-constructed when this LRP uses a composite).

◆ epsilon_alpha2_beta1()

static LRP pulsatrix::LRP::epsilon_alpha2_beta1 ( float  epsilon = 1e-6f)
inlinestatic

Zennit EpsilonAlpha2Beta1 preset (lrp_composite::epsilon_alpha2_beta1).

◆ epsilon_gamma_box()

static LRP pulsatrix::LRP::epsilon_gamma_box ( float  low,
float  high,
float  gamma = 0.25f,
float  epsilon = 1e-6f 
)
inlinestatic

Zennit EpsilonGammaBox preset (lrp_composite::epsilon_gamma_box).

◆ epsilon_plus()

static LRP pulsatrix::LRP::epsilon_plus ( float  epsilon = 1e-6f)
inlinestatic

Zennit EpsilonPlus preset (lrp_composite::epsilon_plus).

◆ explain() [1/2]

Attribution pulsatrix::LRP::explain ( ExplainerContext &  ctx,
const Tensor &  input,
const LRPTarget &  target,
DeviceBackend *  backend 
) const
inline

Explains the given target(s) / contrast(s).

Returns
Attribution{"lrp", relevance (input's shape), metadata}: rule (the uniform rule's name, or "composite:<name>"), rules (each module's rule, comma-separated, forward order), epsilon (the uniform config's), seed, targets, contrasts, relevance_out_sum, relevance_in_sum.
Exceptions
std::invalid_argumentif the network output isn't rank-2, a target/contrast list has neither 1 nor N entries, an index is out of range, or a row's contrast equals its target (that seed is all zeros and explains nothing), a module does not implement its rule, or a rule's parameters are invalid.
std::logic_errorif the context's last forward pass was patched (relevance_pass()).

◆ explain() [2/2]

Attribution pulsatrix::LRP::explain ( ExplainerContext &  ctx,
const Tensor &  input,
int64_t  target_index,
DeviceBackend *  backend 
) const
inline

Explains target_index for every row, OutputValue seed.


The documentation for this class was generated from the following file: