nearest_label

std.geometry.nearest_label · Level L2

One-nearest-neighbour classification: the label of the point closest to q. ArgMin gives the position; a mask built from Iota reads the label there.

labels[argminⱼ ‖Pⱼ − q‖²]

Signature

nearest_label(q: f64[d], points: f64[m, d], labels: f64[m]) → f64[]

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

qf64[d]pointsf64[m, d]labelsf64[m]SubtractdiffIotaposMultiplysqReduceSumdistArgMinkEqualpickMultiplychosenReduceSumlabellabelf64[]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size.
  • Equal to the reference labels[np.argmin(np.sum((points - q) ** 2, axis=1))] in exact rational arithmetic, on all 40 test cases.
  • All 40 float64 results are exact: the error is zero.
  • Interpreter and NumPy backend return bit-identical results.
Accuracy in detail
correctly rounded (the float64 nearest the exact value)
100%
bit-equal to the NumPy formula in float64
98%
largest error, in units in the last place
0

Identity

Calls
—
Called by
—
sha256:56bda334dbb114b0a4f4d95c2a5bd87bc3521b9ceef514a2925d749846ceaf68

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.