2
$\begingroup$

I am building a small library for computing information retrieval metrics for classifiers (precision, recall, f1, accuracy, whatever). Typically each metric is built by calculating a single value for each object being classified (each metric will have its own formula there) and then calculating a single value (an average) aggregating all those single values; hence a mapper and a reducer.

With little formal training in numeric stability, I wonder what would be the most numerically stable way to calculate the average, and what might be the most interesting trade-offs between stability, avoidance of overflow, and computational complexity (performance).

Also any reference to a mathematical reading in this vein would be entirely welcome, for this, as well as for as similar future cases.

Thanks in advance!

$\endgroup$
  • $\begingroup$ By the way, the language I wrote this in (clojure), directly supports a numeric type of rational numbers, which makes an interesting deviation from many standard languages/libraries I know of, and may imply a specialized solution for this question. $\endgroup$ – matanster Jun 22 '17 at 4:00
  • $\begingroup$ Did you try Googling for "numerically stable average". The first non-SE answer will tell you about Kahan summation algorithm (which is the tricky bit of calculating the average). $\endgroup$ – Andrej Bauer Jun 23 '17 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.