Linear algebra library for Rust.
Go to file
Andrew Radcliffe 184f38b227 Replace known-problematic variance algorithm (for `column_variance`)
The existing algorithm for `column_variance` uses the textbook
formula (`E[X^2]` - E[X]^2), which is well-established to have
numerical issues. While the intention (traversal
of the elements in column-major order) of the extant algorithm
is apparent, we should not sacrifice precision when we do not need to
-- the two-pass algorithm for variance (N.B. the existing algorithm is
already a two-pass algorithm, anyway) using the formula `E[(x -
E[x])(x - E[x]])` can be substituted without issue.

Notably, the other variance implementations in the `statistics`
module use `E[(x -E[x])(x - E[x]])`. Loss of precision aside,
keeping the existing implementation of `column_variance`
causes the obvious absurdity:

```rust
use nalgebra::Matrix2x3;

let m = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
assert_ne!(m.column_variance().transpose(), m.transpose().row_variance());
```

We can eliminate both the loss of precision the glaring inconsistency
by switching to the implementation provided by this PR.

For a comprehensive analysis of variance algorithms, see this
[reference](https://ds.ifi.uni-heidelberg.de/files/Team/eschubert/publications/SSDBM18-covariance-authorcopy.pdf),
in particular, Table 2.  The "two-pass" described in the paper is the
implementation given in this PR. In terms of simplicity (hence, easier
to maintain), "two-pass" is a suitable choice; in terms of runtime
performance and precision, it is a good balance (c.f. Youngs & Cramer
and "textbook"). Furthermore, it is consistent with the variance
algorithm used in the other "*variance" algorithms in the `statistics`
module.
2023-11-16 16:25:22 -08:00
.github Use rayon as the feature name instead of par-iter 2023-01-14 15:59:11 +01:00
benches Use std::hint::black_box consistently. 2023-08-14 11:15:57 +07:00
examples Release v0.32.0 2023-01-14 17:04:22 +01:00
nalgebra-glm Fix and clarify license in crate metadata and add missing license files 2023-10-24 18:33:53 +02:00
nalgebra-lapack Fix and clarify license in crate metadata and add missing license files 2023-10-24 18:33:53 +02:00
nalgebra-macros Fix and clarify license in crate metadata and add missing license files 2023-10-24 18:33:53 +02:00
nalgebra-sparse Merge pull request #1312 from arscisca/dev-DefaultTrait 2023-11-12 23:27:37 +01:00
src Replace known-problematic variance algorithm (for `column_variance`) 2023-11-16 16:25:22 -08:00
tests Merge pull request #1315 from yotamofek/owned-view-iter 2023-11-12 23:29:41 +01:00
.gitignore .gitignore: add proptest-regressions to the ignored list. 2021-02-28 18:40:33 +01:00
CHANGELOG.md Update CHANGELOG 2023-07-09 12:35:05 +02:00
Cargo.toml Fix and clarify license in crate metadata and add missing license files 2023-10-24 18:33:53 +02:00
LICENSE Switch license to Apache v2.0 + update sponsor link. 2020-08-19 19:48:16 +02:00
README.md Release v0.32.3 2023-07-09 12:06:38 +02:00
clippy.toml Fix some warnings 2021-07-27 19:24:55 -04:00
rustfmt.toml Fix some warnings 2021-07-27 19:24:55 -04:00

README.md

crates.io

Build status crates.io

Users guide | Documentation | Forum


Linear algebra library for the Rust programming language.