Skip to content

API — nefi.metrics

Generated by scripts/gen_api_docs.py — do not edit by hand. Index

nefi.metrics

Reconstruction metrics.

nefi.metrics.basic

Basic reconstruction metrics (torch, device-agnostic). All take (pred, gt) tensors.

def dice(pred_mask, gt_mask) -> float

def evaluate(pred: Mapping[str, torch.Tensor] | torch.Tensor, gt: Mapping[str, torch.Tensor] | torch.Tensor, metrics: Mapping[str, Callable], field: str | None = None, *...

Apply a dict of metrics to (pred, gt); accepts field dicts (uses field or the first key).

def iou(pred_mask, gt_mask) -> float

def mae(pred, gt) -> float

def masked_ssim(pred, gt, mask, **kw) -> float

SSIM restricted to a support: values outside mask are zeroed in both inputs (NeTMY App. E.3).

def mse(pred, gt, mask=None) -> float

def psnr(pred, gt, data_range: float | None = None) -> float

Peak SNR in dB; data_range defaults to gt.max() - gt.min() (NeFTY uses α_max − α_min).

def relative_error(pred, gt) -> float

‖pred − gt‖₂ / ‖gt‖₂.

def rmse(pred, gt, mask=None) -> float

def ssim(pred, gt, data_range: float | None = None, window: int = 7, sigma: float = 1.5, k1: float = 0.01, k2: float = 0.03) -> float

Structural similarity. 2-D: standard; 3-D: averaged over slices along the last axis (NeFTY App. E.2); 1-D: 1-D Gaussian window.

def threshold_mask(x, threshold: float, mode: str = 'below') -> torch.Tensor

nefi.metrics.localization

Sparse-localization and distributional metrics — NeTMY App. E.3.

def gmsd(pred, gt, c: float = 0.0026, rescale: bool = True) -> float

Gradient Magnitude Similarity Deviation (NeTMY App. E.3; Xue et al. 2014).

def gradient_magnitude(x: torch.Tensor) -> torch.Tensor

Prewitt gradient magnitude sqrt((Dx ∗ x)² + (Dy ∗ x)²) with replicate padding.

def hungarian_f1(pred, gt, radius: float = 2.0, threshold: float = 0.05) -> float

Hungarian-matched localization F1 at a fixed radius (NeTMY App. E.3; 0 if degenerate).

def peak_match(pred, gt, radius: float = 2.0, threshold: float = 0.05) -> dict[str, float]

Hungarian peak matching counts: {"tp", "fp", "fn", "precision", "recall", "f1"}.

def peak_positions(x, threshold: float = 0.05, relative: bool = True) -> torch.Tensor

Local maxima of a 2-D map above a threshold (NeTMY App. E.3).

def sliced_wasserstein(pred, gt, n_proj: int = 128, seed: int = 0, pixel_units: bool = False) -> float

Sliced Wasserstein-2 distance between normalized mass maps (NeTMY App. E.3).

def wasserstein2_1d(x: torch.Tensor, a: torch.Tensor, b: torch.Tensor, squared: bool = False) -> torch.Tensor

Exact W2 between two discrete 1-D distributions on shared support points.

nefi.metrics.segmentation

Segmentation, depth and frequency-domain metrics (NeFTY App. E.2 / G.5).

def abs_rel(pred, gt, mask=None) -> float

Absolute relative depth error mean |d̂ − d*| / d* over valid pixels (Eigen et al.).

def binary_dilation(mask, radius: int = 1) -> torch.Tensor

Binary dilation of a 1-3-D mask with a (2r+1)^d box structuring element.

def delta_threshold(pred, gt, k: int = 1, mask=None, base: float = 1.25) -> float

Threshold accuracy |{p : max(d̂/d*, d*/d̂) < base^k}| / |P| (Eigen et al., NeFTY App. E.2).

def depth_rmse(pred, gt, mask=None) -> float

Depth RMSE sqrt(mean (d̂ − d*)²) over valid pixels (Eigen et al.).

def edge_f1(pred, gt, threshold: float = 0.5, dilate: int = 1, spacing: Sequence[float] | None = None) -> float

Defect Edge F1 (NeFTY App. G.5).

def field_gradient_magnitude(x, spacing: Sequence[float] | None = None) -> torch.Tensor

‖∇x‖ of a 1-3-D field by central differences (one-sided at the borders).

def iou_below(pred, gt, tau: float = 0.03) -> float

IoU of the sub-threshold masks {pred < τ} and {gt < τ} (NeFTY App. E.2: defect voxels have α < τ = 0.03, twice the upper end of the defect diffusivity range). Returns 1.0 when both masks are empty.

def radial_power_spectrum(x, n_bins: int | None = None, spacing: Sequence[float] | None = None, subtract_mean: bool = True) -> tuple[torch.Tensor, torch.Tensor]

Radially averaged power spectrum of a 1-3-D field (NeFTY App. G.5 / Fig. 9).