1 vin.diagnostics.summary_stats

vin.diagnostics.summary_stats

Small tensor statistics used by VIN diagnostic summaries.

The helpers in this module support human-readable VIN reports such as aria_nbv.vin.diagnostics.summarize.summarize_vin_v3. They intentionally avoid stateful torchmetrics objects and rollout-specific mask semantics from aria_nbv.rri_metrics because summaries are one-shot diagnostics over whatever finite tensor values are available.

1.1 Functions

Name Description
finite_1d Return finite values from values as a detached float32 vector.
ordinal_ranks Assign one-based average ranks, preserving tied observations.
pearson_corr Compute Pearson correlation over jointly finite, position-aligned values.
quantile_stats Summarize finite values with the VIN report’s compact quantile schema.
spearman_corr Compute standard average-tie Spearman correlation over paired rows.

1.1.1 finite_1d

vin.diagnostics.summary_stats.finite_1d(values)

Return finite values from values as a detached float32 vector.

1.1.1.1 Parameters

values: Tensor with arbitrary shape and numeric dtype.

1.1.1.2 Returns

Tensor One-dimensional float32 tensor containing only finite values. The returned tensor is detached from autograd so diagnostics cannot keep a training graph alive.

1.1.2 ordinal_ranks

vin.diagnostics.summary_stats.ordinal_ranks(values)

Assign one-based average ranks, preserving tied observations.

Values must be a one-dimensional finite vector. Equal values receive the average of the ranks they occupy, matching the standard Spearman tie rule.

1.1.3 pearson_corr

vin.diagnostics.summary_stats.pearson_corr(x, y)

Compute Pearson correlation over jointly finite, position-aligned values.

Inputs must have equal shapes and share a device. They are flattened only after that alignment check; a pair is retained only when both values at its original position are finite. Float64 inputs retain float64 precision, and other real numeric inputs are computed in float32. No gradients are kept.

1.1.3.1 Theory

Each finite vector is centered relative to its first observation, then scaled only when needed to keep the mean finite, and normalized by its L2 norm. The reported value is sum(x_centered / ||x_centered|| * y_centered / ||y_centered||). The positive scaling leaves Pearson correlation unchanged while preventing an absolute variance threshold from depending on the units of either vector.

Returns None when shapes or devices differ, fewer than two paired finite observations remain, either centered vector has zero norm, or the normalized result is nonfinite. This pooled helper does not define how a caller should combine independent batch items or select valid candidates.

1.1.4 quantile_stats

vin.diagnostics.summary_stats.quantile_stats(values)

Summarize finite values with the VIN report’s compact quantile schema.

1.1.4.1 Parameters

values: Tensor with arbitrary shape.

1.1.4.2 Returns

dict[str, float] | None {"min", "median", "p95", "mean"} for finite values, or None when the input contains no finite values.

1.1.5 spearman_corr

vin.diagnostics.summary_stats.spearman_corr(x, y)

Compute standard average-tie Spearman correlation over paired rows.

Apply the same original-position, joint-finite admission as pearson_corr, average-rank each retained vector, then correlate the ranks. Constants or fewer than two paired observations have no defined Spearman correlation and return None.

Back to top