STUD-13. Improve numerical stability of mean statistic algorithm #525

Merged
altavir merged 1 commits from qwazer/kmath:STUD-13 into dev 2025-05-05 15:57:22 +03:00
Contributor

Replace naive summation that prone to floating-point errors (loss of precision) by Welford’s Online Algorithm which updates mean incrementally. The later algorithm is more numerically stable.
The cons is slightly higher computational overhead.

The test failed with previous implementation

    @Test
    fun numericalStability(){
        val data = doubleArrayOf(1.0e4, 1.0, 1.0, 1.0, 1.0);
        assertEquals(2000.8, Float64Field.mean.evaluateBlocking(Float64Buffer(data)));
    }  
Replace naive summation that prone to floating-point errors (loss of precision) by Welford’s Online Algorithm which updates mean incrementally. The later algorithm is more numerically stable. The cons is slightly higher computational overhead. The test failed with previous implementation ``` @Test fun numericalStability(){ val data = doubleArrayOf(1.0e4, 1.0, 1.0, 1.0, 1.0); assertEquals(2000.8, Float64Field.mean.evaluateBlocking(Float64Buffer(data))); } ````
qwazer added 1 commit 2025-05-05 15:42:06 +03:00
Replace naive summation that prone to floating-point errors (loss of precision) by Welford’s Online Algorithm which updates mean incrementally and more numerically stable.
 The cons is slightly higher computational overhead.
altavir approved these changes 2025-05-05 15:57:04 +03:00
altavir merged commit ce453129f0 into dev 2025-05-05 15:57:22 +03:00
Sign in to join this conversation.
No description provided.