pulsatrix 1.1.0
Loading...
Searching...
No Matches
concept_relevance.hpp
Go to the documentation of this file.
1
25#pragma once
26
27#include <cstdint>
28#include <vector>
29
32#include "pulsatrix/lrp.hpp"
33#include "pulsatrix/tensor.hpp"
34
35namespace pulsatrix {
36
43 std::vector<int64_t> channels;
44};
45
47using ConceptCondition = std::vector<ConceptMask>;
48
54[[nodiscard]] Tensor LayerRelevance(const LRP& lrp, ExplainerContext& ctx, const Tensor& input, const LRPTarget& target, NodeId layer,
55 DeviceBackend* backend);
56
62[[nodiscard]] std::vector<double> ChannelRelevance(const Tensor& layer_relevance);
63
73[[nodiscard]] std::vector<Attribution> ConditionalHeatmaps(const LRP& lrp, ExplainerContext& ctx, const Tensor& input, const LRPTarget& target,
74 const std::vector<ConceptCondition>& conditions, DeviceBackend* backend);
75
77enum class ReferenceMode {
82};
83
93[[nodiscard]] std::vector<int64_t> ConceptReferenceSamples(const LRP& lrp, ExplainerContext& ctx, const Tensor& candidates, int64_t target,
94 NodeId layer, int64_t channel, int64_t k, ReferenceMode mode,
95 DeviceBackend* backend);
96
97} // namespace pulsatrix
First-class explanation result type – values, method, and metadata together.
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:248
Wraps an ordered chain of Modules, running them via Module::forward_traced to build a real Computatio...
Definition explainer_context.hpp:67
Whole-model LRP: runs the forward pass, seeds relevance at the chosen output(s), and propagates it to...
Definition lrp.hpp:168
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Stable interface every explainer gets, regardless of type (charter Part 2 SS2).
LRP – whole-model Layer-wise Relevance Propagation explainer.
Definition acquisition_functions.hpp:16
ReferenceMode
How ConceptReferenceSamples() ranks inputs.
Definition concept_relevance.hpp:77
@ Activation
By the channel's largest activation over positions.
@ Relevance
By the channel's relevance for the target class, summed over positions.
std::vector< Attribution > ConditionalHeatmaps(const LRP &lrp, ExplainerContext &ctx, const Tensor &input, const LRPTarget &target, const std::vector< ConceptCondition > &conditions, DeviceBackend *backend)
One input heatmap per condition: LRP from target with the relevance zeroed, at each masked layer,...
std::vector< ConceptMask > ConceptCondition
One conditional heatmap's masks, at most one per layer.
Definition concept_relevance.hpp:47
size_t NodeId
Stable identifier for a Node within its owning ComputationGraph.
Definition node.hpp:18
std::vector< double > ChannelRelevance(const Tensor &layer_relevance)
Each row's relevance per channel, summed over the remaining dimensions: (N, C) values,...
std::vector< int64_t > ConceptReferenceSamples(const LRP &lrp, ExplainerContext &ctx, const Tensor &candidates, int64_t target, NodeId layer, int64_t channel, int64_t k, ReferenceMode mode, DeviceBackend *backend)
The k inputs of candidates that show a channel best, best first: the reference samples by which CRP s...
Tensor LayerRelevance(const LRP &lrp, ExplainerContext &ctx, const Tensor &input, const LRPTarget &target, NodeId layer, DeviceBackend *backend)
The relevance at layer for explaining target: the layer's shape, (N, C, ...).
Keep the relevance of these channels at this layer, and zero the rest.
Definition concept_relevance.hpp:38
std::vector< int64_t > channels
Indices along the layer's second dimension (channels of an (N, C, H, W) layer, units of an (N,...
Definition concept_relevance.hpp:43
NodeId layer
The node: module i's output is node i + 1. Between 1 and the number of modules.
Definition concept_relevance.hpp:40
What LRP explains: one target class (and optionally one contrast class) per row of the network's (N,...
Definition lrp.hpp:44
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).