pulsatrix 1.1.0
Loading...
Searching...
No Matches
contrastive.hpp
Go to the documentation of this file.
1
21#pragma once
22
23#include <cstdint>
24#include <string>
25#include <vector>
26
28#include "pulsatrix/json.hpp"
29#include "pulsatrix/tensor.hpp"
30
31namespace pulsatrix {
32
36 float kappa = 0.0f;
38 float beta = 0.1f;
40 float c_init = 10.0f;
42 int search_steps = 9;
44 int steps = 1000;
45 float learning_rate = 0.01f;
47 std::vector<float> baseline;
49 std::vector<float> upper;
50};
51
55 bool found = false;
57 int64_t original_class = 0;
60 int64_t explanation_class = 0;
62 std::vector<float> delta;
64 std::vector<float> explanation;
66 double l1 = 0.0;
67 std::vector<int64_t> features;
69 float c = 0.0f;
70};
71
81 const ContrastiveOptions& options = {});
82
88 const ContrastiveOptions& options = {});
89
92[[nodiscard]] JsonValue ToJson(const ContrastiveResult& result, const std::string& kind);
93
94} // namespace pulsatrix
Wraps an ordered chain of Modules, running them via Module::forward_traced to build a real Computatio...
Definition explainer_context.hpp:67
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
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).
A small strict JSON value, parser and deterministic writer (RFC 8259).
Definition acquisition_functions.hpp:16
JsonValue ToJson(const AttackResult &result, const AttackOptions &options)
The result as a pulsatrix.attack.v1 document, without the adversarial inputs.
ContrastiveResult FindPertinentPositive(ExplainerContext &ctx, const Tensor &input, const ContrastiveOptions &options={})
The pertinent positive of input: the least of it that the model still gives its class.
ContrastiveResult FindPertinentNegative(ExplainerContext &ctx, const Tensor &input, const ContrastiveOptions &options={})
The pertinent negative of input: what would have to be added, where the input has nothing,...
CEM's settings. The defaults are the paper's MNIST settings, scaled to its 1,000 steps.
Definition contrastive.hpp:34
float kappa
The margin κ the class change (or keep) must reach in the outputs.
Definition contrastive.hpp:36
std::vector< float > upper
The most a pertinent negative may raise each feature to; empty for no limit.
Definition contrastive.hpp:49
float c_init
The first weight c of the prediction loss; the binary search moves it.
Definition contrastive.hpp:40
int steps
FISTA iterations in each round.
Definition contrastive.hpp:44
float beta
The L1 weight β: larger gives sparser explanations.
Definition contrastive.hpp:38
float learning_rate
Definition contrastive.hpp:45
std::vector< float > baseline
Each feature's absence value; empty for 0.
Definition contrastive.hpp:47
int search_steps
Rounds of the binary search over c.
Definition contrastive.hpp:42
A pertinent negative or positive.
Definition contrastive.hpp:53
bool found
Whether one was found. When not, the other fields describe the input unchanged.
Definition contrastive.hpp:55
int64_t explanation_class
The class of the explanation: another class for a pertinent negative, the same one for a pertinent po...
Definition contrastive.hpp:60
int64_t original_class
The model's class for the input.
Definition contrastive.hpp:57
float c
The weight c of the explanation returned.
Definition contrastive.hpp:69
std::vector< float > delta
δ, one value per feature.
Definition contrastive.hpp:62
std::vector< int64_t > features
Definition contrastive.hpp:67
std::vector< float > explanation
What the model sees: x + δ for a pertinent negative, b + δ for a pertinent positive.
Definition contrastive.hpp:64
double l1
|δ|_1, and the features δ changes.
Definition contrastive.hpp:66
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).