piscis.metrics#

Functions#

compute_metrics(→ Union[Dict[str, float], ...)

Compute evaluation metrics from predicted and ground truth spot coordinates. Adapted from deepBlink.

_compute_metrics(→ Tuple[Dict[str, float], ...)

Compute evaluation metrics from a given distance matrix.

linear_sum_assignment(→ Tuple[numpy.ndarray, ...)

Solve the linear sum assignment problem for a given cost matrix.

Module Contents#

piscis.metrics.compute_metrics(coords_pred: numpy.ndarray, coords: numpy.ndarray, evaluation_metrics: str | Sequence[str] = 'f1', distance_metric: str = 'euclidean', distance_thresholds: float | Iterable = 1.0, epsilon: float = 1e-07, return_df: bool = False) Dict[str, float] | Tuple[Dict[str, float], pandas.DataFrame]#

Compute evaluation metrics from predicted and ground truth spot coordinates. Adapted from deepBlink.

Parameters:
coords_prednp.ndarray

Predicted spot coordinates.

coordsnp.ndarray

Ground truth spot coordinates.

evaluation_metricsUnion[str, Sequence[str]], optional

Evaluation metric or a list of evaluation metrics. Supported evaluation metrics are ‘f1’, ‘precision’, ‘recall’, ‘tp’, ‘fp’, and ‘fn’. Default is ‘f1’.

distance_metricstr, optional

Distance metric used to compute the distances between predicted and ground truth spot coordinates. Default is ‘euclidean’.

distance_thresholdsUnion[float, Iterable], optional

Distance threshold or a list of distance thresholds for matching predicted and ground truth spot coordinates. Default is 1.0.

epsilonfloat, optional

Small constant for numerical stability. Default is 1e-7.

return_dfbool, optional

Whether to return a DataFrame with additional information. Default is False.

Returns:
integral_metricsDict[str, float]

Dictionary of aggregate metrics integrated over the distance thresholds.

dfpd.DataFrame, optional

DataFrame with additional information. Only returned if return_df is True.

References

[1]

Eichenberger, Bastian, et al. “BBQuercus/deepBlink: Threshold independent detection and localization of diffraction-limited spots.” GitHub, BBQuercus/deepBlink.

piscis.metrics._compute_metrics(distance_matrix: numpy.ndarray, evaluation_metrics: str | Sequence[str], distance_threshold: float, epsilon: float) Tuple[Dict[str, float], Tuple[numpy.ndarray, numpy.ndarray]]#

Compute evaluation metrics from a given distance matrix.

Parameters:
distance_matrixnp.ndarray

Distance matrix.

evaluation_metricsUnion[str, Sequence[str]]

Evaluation metric or a list of evaluation metrics. Supported evaluation metrics are ‘f1’, ‘precision’, ‘recall’, ‘tp’, ‘fp’, and ‘fn’.

distance_thresholdfloat

Distance threshold for matching predicted and ground truth spot coordinates.

epsilonfloat

Small constant for numerical stability.

piscis.metrics.linear_sum_assignment(cost_matrix: numpy.ndarray, threshold: float | None = None) Tuple[numpy.ndarray, numpy.ndarray]#

Solve the linear sum assignment problem for a given cost matrix.

Parameters:
cost_matrixnp.ndarray

Cost matrix.

thresholdfloat, optional

Threshold for matching. Default is None.

Returns:
matchesTuple[np.ndarray, np.ndarray]

Tuple of row and column indices of the matches.