-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should be used after a time-integration to verify expected accuracy.
- Loading branch information
Showing
6 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
mutable struct OnlineStatistics{T} | ||
n::Int | ||
μ::T | ||
M::Float64 | ||
|
||
function OnlineStatistics{T}() where T | ||
new(0, T(NaN), T(NaN)) | ||
end | ||
end | ||
|
||
function accum!(o::OnlineStatistics{T}, x) where T | ||
o.n += 1 | ||
if o.n == 1 | ||
o.μ = x | ||
o.M = 0.0 | ||
else | ||
μ_prev = o.μ | ||
o.μ += (x - μ_prev) / o.n | ||
o.M += real((x - o.μ)' * (x - μ_prev)) | ||
end | ||
o | ||
end | ||
|
||
# If Statistics becomes in scope, define methods Statistics.{mean, var} instead | ||
mean(o::OnlineStatistics) = o.μ | ||
var(o::OnlineStatistics; corrected=true) = corrected ? o.M/(o.n-1) : o.M/o.n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters