MATH 314 Homework 03
Welford's online algorithm for computing the mean and variance/standard deviation work with just one data point at a time, as if the data were streaming in and you didn't have the memory or ability to store past data.
I prefer to write the math a bit differently than the Wikipedia page linked above, but to the same effect. Initialize . Update these variables with a new observation
Write a Python class called
OnlineMeanStd
, which implements the following API:om = OnlineMeanStd() om.update(1) om.update(2) om.update(3) om.mean() om.std() om.count() om.size()
Note that the mathematics above track the biased variance, where as I'm asking for unbiased standard deviation . The class method
std()
needs to make the appropriate conversion:The constructor should accept a size argument, which defaults to 1, that sets the number of means and standard deviations to be tracked.