Skip to main content
Import public APIs from fpde. The fpde.core module also aggregates the same public API for compatibility.
This page documents stable public APIs for fpde 0.1.0.

FPDEEngine

Use FPDEEngine for repeated explanations, batch explanations, Hyb-FPDE, grid search, and validation-based lambda_hyb 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.

engine.select_lambda

Selects lambda_hyb by held-out deletion and insertion validation. Returns a HybFPDEValidationSelectionResult.
Searches Diff-FPDE, Cos-FPDE, and Hyb-FPDE candidate settings. Returns a HybFPDEGridSearchResult.

Shared parameters

Prototype helpers

Use these functions when you want manual control over prototype state.

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. Returns an FPDEExplanation.

cos_fpde

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

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.

parse_float_grid

Parses a float grid helper value. Use it when you need the same grid-parsing behavior as FPDE command or workflow code.

Result objects

Common errors

For a guided version of these fixes, see Troubleshooting.