pulsatrix 1.1.0
Loading...
Searching...
No Matches
sensitivity.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstdint>
8#include <functional>
9#include <vector>
10
12#include "pulsatrix/tensor.hpp"
13
14namespace pulsatrix {
15
18 std::vector<float> low;
19 std::vector<float> high;
20};
21
23[[nodiscard]] SensitivityBounds DeltaBounds(const Tensor& input, float delta);
24
32[[nodiscard]] SensitivityBounds ScaledDeltaBounds(const Tensor& input, const std::vector<Tensor>& background,
33 float num_std = 1.0f);
34
41[[nodiscard]] SensitivityBounds RangeBounds(const std::vector<Tensor>& background, float lower_percentile = 0.05f,
42 float upper_percentile = 0.95f);
43
46 int64_t feature_index = 0;
47 float value = 0.0f;
48 float low = 0.0f;
49 float high = 0.0f;
50 float output_low = 0.0f;
51 float output_high = 0.0f;
52
54 [[nodiscard]] float swing() const;
56 [[nodiscard]] float slope() const;
57};
58
61 int64_t target_index = 0;
62 float output = 0.0f;
63 std::vector<FeatureSensitivity> features;
64};
65
76[[nodiscard]] LocalSensitivityResult ComputeLocalSensitivity(const std::function<Tensor(const Tensor&)>& predict,
77 const Tensor& input, int64_t target_index,
78 const SensitivityBounds& bounds,
79 const std::vector<int64_t>& features = {});
80
95[[nodiscard]] Attribution Occlusion(const std::function<Tensor(const Tensor&)>& predict, const Tensor& input,
96 int64_t target_index, const std::vector<int64_t>& window,
97 const std::vector<int64_t>& strides, float baseline = 0.0f);
98
99} // namespace pulsatrix
First-class explanation result type – values, method, and metadata together.
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Definition acquisition_functions.hpp:16
SensitivityBounds ScaledDeltaBounds(const Tensor &input, const std::vector< Tensor > &background, float num_std=1.0f)
x -/+ num_std standard deviations of each feature over background, so every feature moves by a compar...
Attribution Occlusion(const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, int64_t target_index, const std::vector< int64_t > &window, const std::vector< int64_t > &strides, float baseline=0.0f)
Occlusion (Zeiler and Fergus 2014) with Captum 0.9's semantics: a window slides over the input with t...
LocalSensitivityResult ComputeLocalSensitivity(const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, int64_t target_index, const SensitivityBounds &bounds, const std::vector< int64_t > &features={})
Sets each feature in turn to its low and then its high bound, leaving the others at the input's value...
SensitivityBounds DeltaBounds(const Tensor &input, float delta)
x - delta and x + delta for every feature.
SensitivityBounds RangeBounds(const std::vector< Tensor > &background, float lower_percentile=0.05f, float upper_percentile=0.95f)
Each feature's lower and upper percentile over background (linear interpolation, as numpy....
An explanation result: the raw attribution values, the method that produced them, and any relevant me...
Definition attribution.hpp:23
How one feature's low and high value move the output, everything else held fixed.
Definition sensitivity.hpp:45
float output_low
The target output with the feature at low
Definition sensitivity.hpp:50
float swing() const
|output_high - output_low|: the bar length in a tornado chart.
float low
Definition sensitivity.hpp:48
int64_t feature_index
Definition sensitivity.hpp:46
float value
The input's own value.
Definition sensitivity.hpp:47
float output_high
... and at high
Definition sensitivity.hpp:51
float slope() const
(output_high - output_low) / (high - low): a finite-difference slope; 0 if high == low.
float high
Definition sensitivity.hpp:49
One-at-a-time sensitivity of one output around one input.
Definition sensitivity.hpp:60
int64_t target_index
Definition sensitivity.hpp:61
std::vector< FeatureSensitivity > features
Definition sensitivity.hpp:63
float output
The target output at the unchanged input.
Definition sensitivity.hpp:62
The low and high value to try for every feature of an input (flat order).
Definition sensitivity.hpp:17
std::vector< float > low
Definition sensitivity.hpp:18
std::vector< float > high
Definition sensitivity.hpp:19
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).