Constants
IsClose and IsZero for floating-point comparisons throughout the library.
NDCG
DCG of the actual ranked list against the ideal DCG (the best possible ordering of the same items). A score of 1.0 indicates a perfect ranking; 0.0 means no relevant items were retrieved. Returns 0.0 when the ideal DCG is zero.
[]string
required
The ranked list of item identifiers returned by the system, ordered from most to least relevant.
map[string]int
required
A map of item identifier to integer relevance grade. Higher grades indicate greater relevance. Items not present in the map are treated as grade 0.
int
required
The cutoff depth. Only the first
k positions are evaluated.float64 — DCG of the predicted ranking divided by the ideal DCG, in the range [0, 1].
Example
The ideal top-3 ranking would be “A” (grade 3), “E” (grade 3), “B” (grade 2). The actual top-3 is “A” (3), “B” (2), “C” (1). The actual DCG is lower because “E” was not retrieved at rank 2, giving NDCG ≈ 0.727.
DCG
i (0-indexed) is:
[]int
required
A slice of integer relevance grades in rank order. The first element is rank 1, the second is rank 2, and so on.
float64 — the summed discounted gain across all positions.
IsClose
AbsTol and RelTol. The comparison uses the formula:
float64
required
The first value to compare.
float64
required
The second value to compare.
bool — true if a and b are within tolerance of each other.
IsZero
IsClose(a, 0.0).
float64
required
The value to test.
bool — true if a is within tolerance of 0.0.