Fits a locality-weighted linear surrogate around one input: perturb x with Gaussian noise, weight each perturbed sample by an exponential locality kernel pi(z) = exp(-||z-x||^2 / (2*sigma^2)), fit w* = argmin_w sum_i pi_i*(f(z_i) - f(x) - w^T(z_i-x))^2 + l2_lambda*||w||^2 via fit_weighted_linear_regression.
More...
#include <lime.hpp>
|
| Attribution | explain (const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, int64_t target_index, int64_t num_samples, float sigma, float l2_lambda, unsigned seed, DeviceBackend *backend) const |
| | Computes the LIME local surrogate explanation for one output index.
|
| |
Fits a locality-weighted linear surrogate around one input: perturb x with Gaussian noise, weight each perturbed sample by an exponential locality kernel pi(z) = exp(-||z-x||^2 / (2*sigma^2)), fit w* = argmin_w sum_i pi_i*(f(z_i) - f(x) - w^T(z_i-x))^2 + l2_lambda*||w||^2 via fit_weighted_linear_regression.
- Note
- Takes a forward-pass callable, not ExplainerContext& – makes model-agnosticism true by construction (there is nothing else in the type signature to call), per campaign_exai_dl_library_phase3_surrogate_explainers.md's Context section. Works with any callable a caller provides, including but not limited to an ExplainerContext::forward_pass wrapped in a lambda.
-
Targets are centered on f(x) (not fit with a separate intercept term) – the local linear model is g(z) = f(x) + w^T(z-x), so g(x) = f(x) trivially; only w (the local sensitivity, this method's actual Attribution) needs fitting.
-
A pure graph-free explainer – no core (Tensor/ComputationGraph/Autograd/Module) or ExplainerContext changes needed.
-
Device-generic host boundary: perturbation and the surrogate fit run on the host; each perturbed sample is uploaded beside the input and only f(z)[target] is read back.
◆ explain()
| Attribution pulsatrix::LIME::explain |
( |
const std::function< Tensor(const Tensor &)> & |
predict, |
|
|
const Tensor & |
input, |
|
|
int64_t |
target_index, |
|
|
int64_t |
num_samples, |
|
|
float |
sigma, |
|
|
float |
l2_lambda, |
|
|
unsigned |
seed, |
|
|
DeviceBackend * |
backend |
|
) |
| const |
|
inline |
Computes the LIME local surrogate explanation for one output index.
- Parameters
-
| predict | Forward-pass callable: input Tensor in, output Tensor out. |
| input | Input to explain. |
| target_index | Which output element to explain (0-based, flat index). |
| num_samples | How many perturbed samples to draw. |
| sigma | Perturbation std. dev. and locality-kernel width (charter/LIME convention: a single sigma controls both, per technique_lime.md's own default-heuristic framing). |
| l2_lambda | Ridge regularization strength for the surrogate fit. |
| seed | RNG seed, for reproducibility. |
| backend | Backend to allocate intermediate tensors through. |
- Returns
- An Attribution with method "lime", values = the local linear coefficients (same shape as input), and metadata recording the sampling parameters used.
- Exceptions
-
| std::invalid_argument | if num_samples <= 0 or sigma <= 0 – external boundary (campaign_exai_dl_library_adversarial_hardening.md, Mission 2, finding 11): escalated from PULSATRIX_ASSERT-only, which in Release left num_samples<=0 reaching vector::reserve as a huge (wrapped) size_t, throwing an unhelpful std::length_error instead of a clear, actionable error. |
The documentation for this class was generated from the following file: