You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion is a collection of notes regarding different algorithms of compensated summation and corresponding functions that calculate mean values.
The naive approach that is to add all elements of the input array together (we assume that one of the compensated summation algorithms is employed here ) and divide them by their total number. This is the fastest way to do so, however, it might lead to a potential overflow. Whereas it is highly unlikely for someone to have such ginormous outputs, it is not completely impossible.
The very first solution is to scale the data in advance. This:
Degrades performance even more due to creation of a temporary array and the scaling procedure itself1;
Potentially leads to loss of precision1, however, current tests can't reproduce this issue.
Another option is to sort input values by their magnitudes using . One should keep in mind this procedure is even more resource costly than the one described above. Regardless of that, if data contains both positive and negative values, sorting it should help with the overflow issue2. Nevertheless, any data of the same sign still suffers from that. Still, this reduces error accumulation in both cases3.
Finally, it is possible to combine both scaling and sorting, but that require further investigation.
The resulting chain of execution should be similar to the following code snipper:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This discussion is a collection of notes regarding different algorithms of compensated summation and corresponding functions that calculate mean values.
The naive approach that is to add all elements of the input array together (we assume that one of the compensated summation algorithms is employed here ) and divide them by their total number. This is the fastest way to do so, however, it might lead to a potential overflow. Whereas it is highly unlikely for someone to have such ginormous outputs, it is not completely impossible.
The very first solution is to scale the data in advance. This:
Another option is to sort input values by their magnitudes using . One should keep in mind this procedure is even more resource costly than the one described above. Regardless of that, if data contains both positive and negative values, sorting it should help with the overflow issue2. Nevertheless, any data of the same sign still suffers from that. Still, this reduces error accumulation in both cases3.
Finally, it is possible to combine both scaling and sorting, but that require further investigation.
The resulting chain of execution should be similar to the following code snipper:
The best solution at the moment to stick to the conventional KBK summation scheme and deal with potential ill-conditioned data later.
Footnotes
No exact estimates. ↩ ↩2
Find references. ↩
Find references. ↩
Beta Was this translation helpful? Give feedback.
All reactions