7
$\begingroup$

Regarding machine learning methods but dealing with arbitrary floating-point precision. It sounds cool to me but I am unsure if this would be of any use...

Did anyone ever encountered cases where, for example, a logistic regression task needs to be carried out with an extremely high precision? Can it make sense? I am looking for opinions from ML experts.

Edit: If not arbitrary high, maybe quadruple precision could be useful?

$\endgroup$
3
  • $\begingroup$ Are you talking about arbitrary precision that is fixed by the programmer / as a hyperparameter, or arbitrary-precision types like exact-rational? The former is already pretty much covered by the standard libraries such as Torch. The latter is much more involved, and probably would require many fundamental changes to architecture to work out at all. $\endgroup$ Commented Jan 12, 2022 at 14:23
  • $\begingroup$ @leftaroundabout: floating-point precision for the numbers set by the programmer. $\endgroup$
    – maciek
    Commented Jan 12, 2022 at 15:55
  • $\begingroup$ Gaussian processes can benefit from high precision arithmetic in the noiseless case. $\endgroup$ Commented Jan 13, 2022 at 20:56

2 Answers 2

22
$\begingroup$

No, it is almost never a problem. First of all, there's a measurement error—even physicists account for it, while the rest of us rarely can be lucky enough for as precise measurements as theirs. Second, you are dealing with sampled data, so there is error due to sampling. Finally, we have all kinds of biases and noise in the data. In the end, we are usually far from having precise data, so we don’t need algorithms more precise than the data itself.

More than this, there is research showing that you can train neural networks with low (8-bit, 2-bit) precision without performance drop. Some argue that this might even have a regularizing effect. It can probably be extended to some degree to other models.

$\endgroup$
5
  • $\begingroup$ Thank you @Tim for the information. But then maybe a DEcreased precision is desired? How about writing methods that compute on bfloat16? (I just googled it out) $\endgroup$
    – maciek
    Commented Jan 11, 2022 at 22:51
  • 2
    $\begingroup$ @maciek with lower precision you have additional problems with errors due to precision and rounding. This is an active area of research, as mentioned above there are results showing that at least in some cases we can use lower precision. $\endgroup$
    – Tim
    Commented Jan 11, 2022 at 22:57
  • 5
    $\begingroup$ +1. In my experience is it always better to invest in more precise input data, rather than a higher precision algorithm/architecture. Don't buy the micrometer to "measure with a micrometer, mark with chalk, cut with an axe." $\endgroup$ Commented Jan 12, 2022 at 8:05
  • 1
    $\begingroup$ “ we don’t need algorithms more precise than the data itself” some methods are extraordinarily ill-conditioned so you may need many more decimal places in the calculations than in the final result (or to use a better algorithm). $\endgroup$ Commented Jan 12, 2022 at 16:02
  • $\begingroup$ @SpehroPefhany yes, that statement is imprecise. What I meant is that if you can record your data as 32-bit floats with some margin (the values don't hit the precision bounds) than you unlikely need more precision for the parameters. Sure, the parameters can get higher or lower than the data, so you need to account for this, but it would be usually unlikely that you need an order of magnitude more precision for parameters vs data. $\endgroup$
    – Tim
    Commented Jan 12, 2022 at 16:11
5
$\begingroup$

Yes, precision can be problematic on multiple fronts. First, regression itself generally approaches a flat region, like the bottom of a parabola, where the minimum loss function of the regression is located. This typically halves the number of significant figures in the loss function and may reduce the precision of any parameters of a model even more than that. Second, in order to calculate some transcendental functions one may need much higher precision for the calculation process itself than are available for the functional value when that process is completed. See https://blogs.ubc.ca/infiniteseriesmodule/units/unit-3-power-series/taylor-series/maclaurin-expansion-of-sinx/ For example, look at how the intermediate terms of the series expansion of sin(x) achieve large magnitudes before convergence for the sin(12 radians)

enter image description here

This shows that although sin(x) is bounded above and below by $\pm1$, the individual terms are sometimes $\pm20000$, so if we are not careful, the absolute error from those terms could be greater than 1. Now it is true that one can, rather than take the sine of 12, transform that request so that the calculation is performed in the region of principal sine, for which the precision problem is mitigated (but not eliminated), however, the point here is that to guarantee any particular precision for a function, more precision may be necessary during the calculation than is returned when that functional answer is produced.

Edit: The additional OP edit question is whether quadruple precision is enough. The correct answer is sometimes. To see what precision is needed some type of error propagation analysis is needed. Also see propagation of uncertainty and the delta method. That will tell you what the function for fitting needs for precision, if you know what that is. Then one has to account for the precision loss for the loss functions used during regression, and most software allows you to specify what that is. One should then augment the data calculation precision to include both the functional precision loss and the regression precision loss.

In the sine example above, one can find the maximum absolute term magnitude in low precision, let's call that $\Delta$, and then set the precision at $D+\log_{10}(\Delta)$, where $D$ is the precision desired, and only then calculate each term value at the higher precision for later summation. Some software routines augment precision automatically during summation, others do not, and if not, then the error propagation from summation would be added to the precision request for $\sin(x)$.

One final suggestion. Calculating what precision is needed for which problem can be daunting and in some cases for which the algorithms are not well characterized, e.g., some machine learning routines, are not reasonably achievable. In that case, one could proceed heuristically by increasing precision until it no longer makes a difference to the precision desired in the answer. But, don't be surprised if that turns out to be a larger number of significant figures than one would guess without doing such a test.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.