Commit a9bbf74
For standard deviation of `fparam/aparam`, $\sigma = \sqrt{\frac{1}{N}
\sum_{i=1}^{N} (x_i - \bar{x})^2}=\sqrt{\frac{\sum x_i^2}{N} - \left(
\frac{\sum x_i}{N} \right)^2}$.
When all `fparam`/`aparam` have equal values in one dimension,
$\frac{\sum x_i^2}{N} - \left( \frac{\sum x_i}{N} \right)^2$ equals
zero.
However, it sometimes becomes a very small negative number(for example,
1e-18) due to numerical instability, so $\sqrt{\frac{\sum x_i^2}{N} -
\left( \frac{\sum x_i}{N} \right)^2}$ becomes `nan`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved numerical stability in variance/std calculations by ensuring
intermediate variance values are non-negative before taking the square
root. This prevents occasional floating-point underflow from producing
invalid results and yields more reliable statistical outputs across
edge-case inputs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3ab3779 commit a9bbf74
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
0 commit comments