The checkpoint that remembers only half the metric
A mutual-information checkpoint restores probability sums but loses inherited entropy and observation state, corrupting fresh and resumed evaluation.
What’s going wrong
ML practice. This historical teaching reduction adapts a repaired PyTorch-Ignite checkpoint defect in original Bugger code. It does not run the actual framework, and the historical repair is not a current upstream task to resubmit.
A streaming mutual-information metric gives correct results until it crosses a checkpoint boundary. Loading into a fresh metric loses a previously computable result. Loading into a metric that has already seen observations can silently combine unrelated evaluation state. Investigate the inherited serialization contract without changing the entropy definition, update arithmetic, reset behavior or snapshot isolation.
Read one JSON object {"classes":2,"commands":[...]} from stdin. classes is one fixed global class count from 2 to 4, shared by every named metric. There are 0 to 40 commands. Metric names and checkpoint keys are nonempty case-sensitive ASCII strings of at most 16 characters. An unknown metric name creates an empty metric before its command executes.
Commands are: update {"op":"update","metric":"a","rows":[[1,0],[1,1]]}; save {"op":"save","metric":"a","key":"best"}; load with the same fields and op "load"; reset {"op":"reset","metric":"a"}; and compute {"op":"compute","metric":"a"}. Each update contains 0 to 8 rows. Every row has exactly classes nonnegative integer weights from 0 to 9 and has a positive sum. Normalize each row independently into a probability vector p; each row is one observation regardless of its weight sum. Inputs satisfy these bounds.
For n observations, let probability_sum be the per-class sum of their probability vectors and entropy_sum be the sum of their individual entropies. Entropy uses natural logarithms: H(p) = -sum(p[c] * ln(p[c])) over positive components; a zero component contributes zero. marginalEntropy is H(probability_sum / n); conditionalEntropy is entropy_sum / n; mutualInformation is max(0, marginalEntropy - conditionalEntropy). Keep unrounded sufficient statistics internally. Round only the final three outputs with Python round(value, 6), emitting floating-point JSON numbers and canonical 0.0 for either sign of zero.
Save must capture an independent snapshot of all three sufficient statistics: count, entropy_sum and probability_sum. A later save to the same key replaces that checkpoint only. A load always refers to a previously saved key and replaces the destination metric's complete accumulated state, even if that metric already contains other observations. It must not change the checkpoint, its source metric, or any other metric. Later updates continue from the restored state. Reset empties only its named metric. Compute reads state without changing it.
Print one array entry per compute command, in command order, containing {"n":2,"marginalEntropy":0.562335,"conditionalEntropy":0.346574,"mutualInformation":0.215762}. Updates, saves, loads and resets do not emit entries. For n equal to zero, all three entropy/information fields are null and n is 0; this is an explicit teaching policy rather than an upstream framework exception. With no compute commands, print []. Use only the Python standard library.
Expected behavior
Restore all inherited and derived sufficient statistics as one metric state, preserving immutable checkpoints, destination replacement, continued aggregation and read-only computation.
Reproduction
{"classes":2,"commands":[{"op":"update","metric":"train","rows":[[1,0],[0,1]]},{"op":"save","metric":"train","key":"best"},{"op":"load","metric":"fresh","key":"best"},{"op":"compute","metric":"fresh"}]}[{"n":2,"marginalEntropy":0.693147,"conditionalEntropy":0.0,"mutualInformation":0.693147}]{"classes":2,"commands":[{"op":"update","metric":"metric","rows":[[1,1]]},{"op":"compute","metric":"metric"}]}[{"n":1,"marginalEntropy":0.693147,"conditionalEntropy":0.693147,"mutualInformation":0.0}]{"classes":2,"commands":[{"op":"update","metric":"source","rows":[[1,0],[0,1]]},{"op":"save","metric":"source","key":"saved"},{"op":"update","metric":"dirty","rows":[[1,1]]},{"op":"load","metric":"dirty","key":"saved"},{"op":"compute","metric":"dirty"}]}[{"n":2,"marginalEntropy":0.693147,"conditionalEntropy":0.0,"mutualInformation":0.693147}]Before you begin
- The original metric-state lesson and Python inheritance
- Probability normalization, natural logarithms and entropy
- Sufficient statistics, mutable snapshots and checkpoint continuation
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.