metrics

metrics

DistanceMetric

Bases: StrEnum

Enum for different distance metrics.

Members
- L1_MANHATTAN:            L1 (Manhattan) distance                   = sum_i |x_i - y_i|
- L2_EUCLIDEAN:            L2 (Euclidean) distance                   = sqrt( sum_i (x_i - y_i)^2 )
- L2S_EUCLIDEAN_SQUARED:   L2 squared (Euclidean squared) distance   = sum_i (x_i - y_i)^2
                                  --> avoids computing square root
                                  --> and produces identical solutions for GEOMEAN_SEPARATION diversity metric

DiversityMetric

Bases: StrEnum

Enum for different diversity metrics.

Members
- MIN_SEPARATION:             Minimum separation of all selected vectors
- MEAN_SEPARATION:            Arithmetic mean separation of all selected vectors
- GEOMEAN_SEPARATION:         Geometric mean separation of all selected vectors
- APPROX_GEOMEAN_SEPARATION:  Approximate geometric mean separation of all selected vectors
                                  (uses faster, but still smooth approximations of log(.) and exp(.))
- NON_ZERO_SEPARATION_FRAC:   Fraction of separation values that are non-zero

compute

compute(separations: NDArray[float32]) -> float32

Compute diversity metric given separations of each vector wrt all others in selection.

Parameters

separations : NDArray[np.float32] Array of separation values.

Returns

np.float32 The computed diversity score.