xai4tsc.evaluation.evaluate
evaluate() entry point and the METRICS / QUANTUS_METRICS registries.
Attributes
Functions
|
Evaluate an explanation using the named metric from the METRICS registry. |
|
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 aModelBaseinstance).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
Noneif 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 anEvaluatorBasesubclass (instantiated with its constructor params at evaluation time). The fixed set of Quantus-library metrics is wired in package-side (viaQUANTUS_METRICSand the singleQuantusEvaluator), so users only ever register their ownEvaluatorBasesubclasses.- 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
EvaluatorBasesubclass.
- xai4tsc.evaluation.evaluate.QUANTUS_METRICS
- xai4tsc.evaluation.evaluate.METRICS: dict[str, type | collections.abc.Callable]