ARM-software / CMSIS_5

CMSIS Version 5 Development Repository
http://arm-software.github.io/CMSIS_5/index.html
Apache License 2.0
1.33k stars 1.08k forks source link

arm_var_f32.c : Variance computation does not use common algorithm #697

Closed etiennedemontalivet closed 5 years ago

etiennedemontalivet commented 5 years ago

File Path: CMSIS_5/CMSIS/DSP/Source/StatisticsFunctions/arm_var_f32.c

I have just tested the ouptut of _arm_varf32. As detailed in the doc, it uses the algorithm : Result = sum(element - meanOfElements)^2) / numElement - 1 Should'nt it be instead : Result = sum(element - meanOfElements)^2) / numElement Same for the standard deviation ?

etiennedemontalivet commented 5 years ago

I would propose to compute variance and standard deviation always using numElement instead of numElement - 1 Attached are associated patches for variance and standard deviation, only for f32 format.

arm_std_f32_patch.txt arm_var_f32_patch.txt

christophe0606 commented 5 years ago

@etiennedemontalivet We have plan to rework those functions because they are not using the best algorithms in term of numerical stability.

The numElement - 1 is normal otherwise the estimator of the variance is biased.

You can look at the "Two-pass algorithm" here https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance

Now the bias is not the only important factor for an estimator. So, this function may not match all the needs.

etiennedemontalivet commented 5 years ago

Thanks for pointing that out.