Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerically stable accumulation of intensity variance #214

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

ddahlbom
Copy link
Member

@ddahlbom ddahlbom commented Jan 3, 2024

Replace running calculation of variance with running calculation of M=(n-1)*σ², where n is the number of samples.

The modifications reproduce previous results when M is divided by n-1. Note that there is currently no interface for retrieving this data. Any future interface will need to divide by n-1 to recover the variance.

@@ -128,7 +128,7 @@ end
# Merge correlations and check if result equal to running calculation.
sc_merged = merge_correlations([sc1, sc2])
@test sc0.data ≈ sc_merged.data
@test sc0.variance ≈ sc_merged.variance
@test sc0.M[1] ≈ sc_merged.M[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this hold for the whole M array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Fixed.

@kbarros
Copy link
Member

kbarros commented Jan 4, 2024

Overall looks good to me, but maybe one test got weakened. Eventually we might want to consider merging with an OnlineStatistics structure, but that's not available yet.

@ddahlbom
Copy link
Member Author

ddahlbom commented Jan 4, 2024

Sorry, the weakened test was an oversight. It is fixed.

@kbarros kbarros merged commit 8cf79e2 into main Jan 4, 2024
4 checks passed
@kbarros kbarros deleted the numerically-stable-variance-calc branch January 4, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants