xai4tsc.evaluation.evaluate

evaluate() entry point and the METRICS / QUANTUS_METRICS registries.

Attributes

logger

QUANTUS_METRICS

METRICS

Functions

evaluate(→ float | numpy.ndarray | None)

Evaluate an explanation using the named metric from the METRICS registry.

register_metric(→ None)

Register a custom metric class.

Module Contents

xai4tsc.evaluation.evaluate.logger
xai4tsc.evaluation.evaluate.evaluate(model: torch.nn.Module, metric: str, explanation: xai4tsc.xai.explain.Explanation, data: numpy.ndarray | None = None, labels: numpy.ndarray | None = None, metric_class_params: dict | None = None, metric_call_params: dict | None = None, device: str = 'cpu') float | numpy.ndarray | None

Evaluate an explanation using the named metric from the METRICS registry.

Parameters:
  • model – A Module (typically a ModelBase instance).

  • metric (str) – Registry key for the metric to run.

  • explanation (Explanation) – Explanation dataclass containing exp_values.

  • data (np.ndarray, optional) – Input samples.

  • labels (np.ndarray, optional) – Ground-truth labels.

  • metric_class_params (dict, optional) – Keyword arguments for the metric constructor.

  • metric_call_params (dict, optional) – Keyword arguments for the metric __call__.

  • device (str) – Compute device.

Returns:

Metric score, or None if the metric is not registered.

Return type:

float or np.ndarray or None

xai4tsc.evaluation.evaluate.register_metric(name: str, metric_class: type) None

Register a custom metric class.

Mirrors register_model() / register_explainer(): metric_class must be an EvaluatorBase subclass (instantiated with its constructor params at evaluation time). The fixed set of Quantus-library metrics is wired in package-side (via QUANTUS_METRICS and the single QuantusEvaluator), so users only ever register their own EvaluatorBase subclasses.

Parameters:
  • name – Key used to reference the metric in experiment configs.

  • metric_class – The metric class to register.

Raises:

TypeError – If metric_class is not an EvaluatorBase subclass.

xai4tsc.evaluation.evaluate.QUANTUS_METRICS
xai4tsc.evaluation.evaluate.METRICS: dict[str, type | collections.abc.Callable]