Others utils#

Here, we document other utility functions that might come in handy for Scores development.

ak_lpe(index, k, query, *[, self_query])

Mean distance from \(\approx k\)-th nearest neighbors.

batched_grad(outputs, inputs, *[, retain_graph])

Compute gradients for batched inputs/outputs.

dirmult_surprise(counts, alpha)

Compute DCM surprise.

fgm_direction(grad, *[, p, check])

Return FGM attack direction.

get_aggregator(aggr_or_ord)

Get a \(1\)D aggregator function.

kldiv(inputs, expected)

KL div for (potentially batched) \(1\)D inputs.

knn_label_count(index, labels, n_classes, k, ...)

Count labels of neighbors for batched queries.

multinomial_test(counts, prior, mode)

Prepare test after having observed counts, with prior belief.

normalize_samples(tensor, *, ord[, ...])

Vector-normalizes all samples if ord is provided.

torch_quantile(tensor, q[, dim, keepdim, ...])

Improved torch.quantile() for one scalar quantile.