85 std::vector<SurrogateNode>
nodes;
88 [[nodiscard]]
int leaf(
const std::vector<float>& x)
const;
90 [[nodiscard]]
double predict(
const std::vector<float>& x)
const;
91 [[nodiscard]]
int depth()
const;
92 [[nodiscard]] int64_t
leaves()
const;
137 const std::vector<Tensor>& instances,
146 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
What each explainer answers: the nine question categories (Liao, Gruen and Miller,...
A small strict JSON value, parser and deterministic writer (RFC 8259).
Definition acquisition_functions.hpp:16
std::vector< double > FeatureImportance(const SurrogateTree &tree)
Each feature's share of the tree's impurity decrease (scikit-learn's feature_importances_).
SurrogateTree FitDecisionTree(const std::vector< std::vector< float > > &x, const std::vector< double > &y, SurrogateTask task, int64_t num_classes, const SurrogateTreeOptions &options)
Fits CART to rows x and targets y: class indices for classification, values for regression....
JsonValue ToJson(const AttackResult &result, const AttackOptions &options)
The result as a pulsatrix.attack.v1 document, without the adversarial inputs.
std::string DescribeSurrogateTree(const SurrogateTree &tree, const std::vector< std::string > &feature_names={})
The tree as nested if/else rules, one node per line: if income <= 41.5: ... class 1 (40 inputs,...
SurrogateTreeResult FitSurrogateTree(const std::function< Tensor(const Tensor &)> &predict, const std::vector< Tensor > &instances, const SurrogateTreeOptions &options={})
Labels instances with the model, holds out options.test_fraction of them, fits a tree to the rest and...
std::string_view to_string(XaiQuestion question)
SurrogateTask
What the surrogate imitates.
Definition surrogate_tree.hpp:38
@ Classification
The model's class: the index of its largest output. Fidelity is agreement.
@ Regression
One output's value. Fidelity is R².
How well the tree imitates the model.
Definition surrogate_tree.hpp:96
double test
On the held-out inputs; the number to report. NaN when nothing was held out.
Definition surrogate_tree.hpp:100
double train
On the inputs the tree was fitted to.
Definition surrogate_tree.hpp:98
int64_t test_size
Definition surrogate_tree.hpp:102
int64_t train_size
Definition surrogate_tree.hpp:101
One node. A leaf has feature -1.
Definition surrogate_tree.hpp:61
std::vector< int64_t > class_counts
Classification: how many training inputs of each class reached the node.
Definition surrogate_tree.hpp:74
double value
The mean target, or the majority class (lowest index on a tie).
Definition surrogate_tree.hpp:72
int64_t samples
Training inputs that reached the node.
Definition surrogate_tree.hpp:68
double impurity
Gini impurity, or the variance of the target.
Definition surrogate_tree.hpp:70
int left
Definition surrogate_tree.hpp:65
bool is_leaf() const
Definition surrogate_tree.hpp:76
int64_t feature
Definition surrogate_tree.hpp:62
double threshold
Inputs with x[feature] <= threshold go to left.
Definition surrogate_tree.hpp:64
int right
Definition surrogate_tree.hpp:66
How the tree is grown.
Definition surrogate_tree.hpp:46
int64_t target
Regression: the output (flat index) imitated.
Definition surrogate_tree.hpp:49
int max_depth
The deepest a leaf may be; the root is depth 0. Three or four levels stay readable.
Definition surrogate_tree.hpp:51
double test_fraction
FitSurrogateTree: the share of the inputs held out to measure fidelity, in [0, 1).
Definition surrogate_tree.hpp:55
int64_t min_samples_leaf
The fewest inputs a leaf may hold.
Definition surrogate_tree.hpp:53
uint64_t seed
FitSurrogateTree: seeds the held-out split.
Definition surrogate_tree.hpp:57
SurrogateTask task
Definition surrogate_tree.hpp:47
FitSurrogateTree()'s result.
Definition surrogate_tree.hpp:106
SurrogateFidelity fidelity
Definition surrogate_tree.hpp:108
std::vector< double > feature_importance
Each feature's total impurity decrease, weighted by the inputs it split, summing to 1 (scikit-learn's...
Definition surrogate_tree.hpp:111
SurrogateTree tree
Definition surrogate_tree.hpp:107
A fitted tree. nodes[0] is the root.
Definition surrogate_tree.hpp:80
int64_t num_classes
Classification: the number of classes (the model's output size).
Definition surrogate_tree.hpp:84
SurrogateTask task
Definition surrogate_tree.hpp:81
double predict(const std::vector< float > &x) const
The leaf's value: a class index, or the predicted target.
std::vector< SurrogateNode > nodes
Definition surrogate_tree.hpp:85
int64_t num_features
Definition surrogate_tree.hpp:82
int leaf(const std::vector< float > &x) const
The leaf x falls in.
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).