73 double lower = -std::numeric_limits<double>::infinity();
74 double upper = std::numeric_limits<double>::infinity();
76 [[nodiscard]]
bool holds(
float value)
const {
return lower < value && value <=
upper; }
102 [[nodiscard]]
bool applies_to(
const std::vector<float>& x)
const;
116 const std::vector<Tensor>& background,
const AnchorOptions& options = {});
120[[nodiscard]] std::string
DescribeAnchor(
const Anchor& anchor,
const std::vector<std::string>& feature_names = {});
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
A small strict JSON value, parser and deterministic writer (RFC 8259).
Definition acquisition_functions.hpp:16
Anchor FindAnchor(const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, const std::vector< Tensor > &background, const AnchorOptions &options={})
Finds an anchor for the model's prediction on input.
JsonValue ToJson(const AttackResult &result, const AttackOptions &options)
The result as a pulsatrix.attack.v1 document, without the adversarial inputs.
double KlLowerBound(double p, double level)
The smallest q <= p with BernoulliKl(p, q) <= level.
double KlUpperBound(double p, double level)
The largest q >= p with BernoulliKl(p, q) <= level.
double BernoulliKl(double p, double q)
KL divergence between Bernoulli(p) and Bernoulli(q), with p and q clipped to (0, 1).
std::string DescribeAnchor(const Anchor &anchor, const std::vector< std::string > &feature_names={})
IF income > 0.71 AND debt <= -0.12 THEN class 1 (precision 0.97, coverage 0.21).
FindAnchor's settings. The defaults are the reference implementation's, except a beam of 2 and epsilo...
Definition anchors.hpp:43
std::vector< double > percentiles
Where the features are cut, in percent of the background.
Definition anchors.hpp:66
int64_t batch_size
Samples drawn at a time for a candidate.
Definition anchors.hpp:60
int64_t beam_size
Candidates kept at each anchor size.
Definition anchors.hpp:58
double epsilon_stop
An anchor is accepted when its precision is at least the threshold and its lower bound above threshol...
Definition anchors.hpp:56
int64_t max_anchor_size
The most predicates in an anchor, counting both sides of an interval; 0 for no limit.
Definition anchors.hpp:64
double delta
The confidence bounds hold with probability 1 - delta.
Definition anchors.hpp:47
double precision_threshold
The precision an anchor must reach (the paper's τ).
Definition anchors.hpp:45
uint64_t seed
Definition anchors.hpp:67
int64_t max_samples_per_candidate
The most samples drawn for one candidate.
Definition anchors.hpp:62
double epsilon
KL-LUCB stops when the best candidates are separated from the rest to within this.
Definition anchors.hpp:49
lower < x[feature] <= upper; a missing side is infinite.
Definition anchors.hpp:71
double lower
Definition anchors.hpp:73
bool holds(float value) const
Definition anchors.hpp:76
int64_t feature
Definition anchors.hpp:72
double upper
Definition anchors.hpp:74
FindAnchor()'s result.
Definition anchors.hpp:80
std::vector< AnchorPredicate > predicates
The rule, one interval per feature, in the order the search first constrained each....
Definition anchors.hpp:85
int64_t samples
Samples behind the estimate.
Definition anchors.hpp:92
bool applies_to(const std::vector< float > &x) const
Whether x (flattened) satisfies every predicate.
int64_t predicted_class
The class the model gives the input (its largest output), which the anchor keeps.
Definition anchors.hpp:82
bool meets_threshold
Whether it reached the threshold. When no anchor does, this is the most precise candidate found,...
Definition anchors.hpp:97
double precision_lower
Its KL confidence bounds at 1 - delta.
Definition anchors.hpp:89
double coverage
The share of the background the rule applies to.
Definition anchors.hpp:94
double precision
The share of sampled inputs satisfying the rule that kept the class.
Definition anchors.hpp:87
double precision_upper
Definition anchors.hpp:90
int64_t model_calls
Calls to the model over the whole search.
Definition anchors.hpp:99
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).