The median that chooses only one middle
A regression metric’s median helper agrees on odd sample counts but reports the lower middle value for even counts.
What’s going wrong
ML practice for NumFOCUS / PyTorch-Ignite. This historical teaching adaptation isolates a documented median repair in original Bugger code; it does not execute the upstream package.
An evaluator uses a median helper to summarize numeric observations. For an even number of observations it returns the lower middle value instead of the midpoint promised by the evaluation contract. Odd-sized examples still look correct. Repair summarize without changing the observations or dropping duplicates.
Read {"values":[8,2,4,10]} from stdin. values contains 0 to 128 integers, each from -1000000 to 1000000. Negative numbers, zero, duplicate observations and any input order are valid. Sort a copy by numeric value. For an odd count the median is the central value; for an even nonzero count it is the arithmetic mean of the two central values. Empty input has a null median under this exercise’s explicit policy.
Print {"median":6.0,"count":4}. count is the number of input observations, including duplicates. Return a floating-point JSON number for a nonempty median, rounded with Python round(value, 6), as the starter does. The inputs satisfy these bounds. The upstream tensor shapes, distributed aggregation and model inference are outside this reduction.
Expected behavior
Return the central order statistic for odd counts and the midpoint of both central order statistics for even counts, preserving every observation.
Reproduction
{"values":[8,2,4,10]}{"median":6.0,"count":4}{"values":[9,1,5]}{"median":5.0,"count":3}{"values":[]}{"median":null,"count":0}Before you begin
- Sorting
- List indices
- Median definition
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.