Skip to main content
Import the public package as fpde.
This page documents the public API exported by fpde and fpde.core.

FPDEEngine

Use FPDEEngine for repeated explanations, batch explanations, Hyb-FPDE, grid search, validation-based lambda selection, and Bayesian-FPDE lambda posterior selection.

FPDEEngine.fit

Fits reusable FPDE state from training data. Returns an FPDEEngine.

engine.explain_one

Explains one sample with fixed-lambda Hyb-FPDE. Returns (attributions, details). The details dictionary includes target_label, rival_label, target_probability, lambda_hyb, evidence, exactness_residual, positive_score, and negative_score.

engine.explain_batch

Explains many samples with fixed-lambda Hyb-FPDE. Returns (attribution_matrix, details). If include_details=False, details is an empty list.

engine.explain_matrix

Returns only the attribution matrix for a batch.
Searches Diff-FPDE, Cos-FPDE, and Hyb-FPDE candidate settings. Returns a HybFPDEGridSearchResult.

engine.select_lambda

Selects lambda_hyb by held-out deletion and insertion validation. Returns a HybFPDEValidationSelectionResult.

engine.select_bayesian_lambda

Builds a Bayesian posterior over unique lambda_hyb candidates using the same held-out deletion and insertion validation score as select_lambda. Returns a BayesianFPDELambdaSelectionResult.

engine.explain_one_bayesian

Explains one sample using selection.posterior_mean_lambda, where selection is a BayesianFPDELambdaSelectionResult. Returns (attributions, details). The details dictionary includes the usual fixed-lambda fields plus lambda_source, posterior_mean_lambda, map_lambda, credible_interval, posterior_entropy, and effective_candidates.

engine.explain_batch_bayesian

Explains many samples with the Bayesian posterior-mean lambda_hyb. Returns (attribution_matrix, details).

engine.explain_matrix_bayesian

Returns only the Bayesian-FPDE attribution matrix for a batch.

Prototype helpers

class_mean_prototypes

Builds one mean prototype per class. Returns (prototypes, labels).

select_prototype_pair

Selects the positive and negative prototype indices for a local contrast. Returns (positive_index, negative_index).

prepare_fpde_context

Precomputes reusable prototypes, anchors, baseline, and feature metadata. Returns an FPDEContext.

Explanation functions

Use these functions when you want direct control over prototypes and labels.

diff_fpde

Computes a Diff-FPDE explanation for one target/rival prototype pair.

cos_fpde

Computes a Cos-FPDE explanation for one target/rival prototype pair.

explain_with_selected_prototypes

Selects prototypes and computes a public Diff-FPDE or Cos-FPDE explanation. Use FPDEEngine for Hyb-FPDE.

Metrics and probability helpers

regularized_cosine

Returns cosine similarity with epsilon-regularized norms.

top_two_labels

Returns (target_label, rival_label, probability_vector) for one sample. model must implement predict_proba and expose classes_.

predict_proba_for_label

Returns the predict_proba(X) column for label.

perturbation_curves

Computes deletion and insertion curves for one attribution vector. Features are ranked by signed positive attribution in descending order.

Result objects

Common errors