Skip to content

Instantly share code, notes, and snippets.

@schmrlng
Created April 9, 2015 04:20
Show Gist options
  • Save schmrlng/d9cdfeeb6a534f276159 to your computer and use it in GitHub Desktop.
Save schmrlng/d9cdfeeb6a534f276159 to your computer and use it in GitHub Desktop.
O(n) functions for computing cumulative estimates of some basic statistics (useful e.g. for plotting how these estimates evolve).
cummean(x) = cumsum(x) ./ [1:length(x)]
cumvar(x, m = cummean(x)) = cumsum((1 - 1 ./ [1:length(x)]).*(x - [0, m[1:end-1]]).^2) ./ [1:length(x)]
cumcov(x, y, mx = cummean(x), my = cummean(y)) = cumsum((1 - 1 ./ [1:length(x)]).*(x - [0, mx[1:end-1]]).*(y - [0, my[1:end-1]])) ./ [1:length(x)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment