> ## Documentation Index
> Fetch the complete documentation index at: https://fpde-80-mintlify-48090872.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Method overview

> Understand prototypes, target-rival contrasts, and FPDE variants

FPDE is a post-hoc feature attribution method for classification.
It explains one input by contrasting that input with a prototype for a target class and a prototype for a rival class.

The result is one attribution value per feature.
Positive values support the target class.
Negative values support the rival class.

## When to use FPDE

Use FPDE when you have:

* A feature matrix where each column has a consistent meaning
* Class labels for training samples
* A classifier that exposes `predict_proba` and `classes_`
* A need to explain target-versus-rival evidence at the feature level

FPDE does not retrain or modify the classifier.
It uses training data to build prototypes, then uses those prototypes to explain individual inputs.

## Core terms

| Term         | Meaning                                                                                        |
| ------------ | ---------------------------------------------------------------------------------------------- |
| Prototype    | A representative class feature vector. FPDE `0.1.0` builds one class-mean prototype per class. |
| Target class | The class being explained, often the classifier's predicted class.                             |
| Rival class  | The contrast class, often the second-highest-probability class.                                |
| Evidence     | The scalar target-versus-rival contrast decomposed by FPDE.                                    |
| Attribution  | A per-feature contribution to the evidence value.                                              |
| Anchor       | A reference vector used by Cos-FPDE before computing cosine contrasts.                         |
| Baseline     | A replacement vector used for deletion and insertion perturbation curves.                      |

## Prototype construction

`class_mean_prototypes(X, y)` computes one prototype per class by averaging all training rows with that class label.
`FPDEEngine.fit(X_train, y_train, model)` builds the same prototype state and stores it for repeated explanations.

For repeated workflows, prefer `FPDEEngine` because it reuses:

* Class-mean prototypes
* Prototype labels
* Mean and zero anchors
* The baseline vector
* Label-to-prototype lookup state

## Target and rival selection

When you use `FPDEEngine` with a model, FPDE chooses the local contrast from `predict_proba`.

<Steps>
  <Step title="Select the target class">
    The target class is the highest-probability class.
  </Step>

  <Step title="Select the rival class">
    The rival class is the second-highest-probability class.
  </Step>

  <Step title="Map labels to prototypes">
    FPDE maps both labels to their fitted class-mean prototypes.
  </Step>
</Steps>

When you call lower-level functions directly, pass `positive_label` and `negative_label`.
If you omit `negative_label`, FPDE selects a non-target prototype according to the selected mode.

## Diff-FPDE

Diff-FPDE decomposes the difference in squared distances from the input to the rival and target prototypes.

```text theme={null}
E_diff = ||x - p_neg||^2 - ||x - p_pos||^2
phi_j  = (x_j - p_neg_j)^2 - (x_j - p_pos_j)^2
```

The attribution values sum to the Diff-FPDE evidence.
A positive feature value means that feature supports the target class under this squared-distance contrast.

## Cos-FPDE

Cos-FPDE decomposes a regularized cosine-similarity contrast.

```text theme={null}
E_cos = cos_eps(x - anchor, p_pos - anchor)
        - cos_eps(x - anchor, p_neg - anchor)
```

Cos-FPDE is an exact coordinate decomposition of the cosine contrast.
It is not a leave-one-feature-out causal effect, because the cosine denominator depends on all coordinates.

## Hyb-FPDE

Hyb-FPDE mixes Diff-FPDE and Cos-FPDE attribution vectors.

```text theme={null}
phi_hyb_j = lambda_hyb * phi_diff_j + (1 - lambda_hyb) * phi_cos_j
```

`lambda_hyb` must be in `[0, 1]`.

* `lambda_hyb=1.0` uses the Diff-FPDE endpoint.
* `lambda_hyb=0.0` uses the Cos-FPDE endpoint.
* Intermediate values blend both attribution vectors.

By default, Hyb-FPDE uses L1-normalized component attribution vectors before mixing.
Set `normalize="none"` when you want to mix the raw component scales.

## Where to go next

* Use [Explain one sample](/explain-one) for a practical local explanation.
* Use [Select lambda\_hyb](/select-lambda) to choose a fixed mixture weight.
* Use [Interpreting results](/interpreting-results) to read signs and evidence values correctly.
