`class RunningMean(object):`

Running mean calculator.

This class can be used to calculate the mean of elements from a list, tuple, iterable or any other data source. The mean is calculated on the fly without explicitly summing the values, so it can be used for data sets with arbitrary item count. Also capable of returning the standard deviation (also calculated on the fly)

Method | `__complex__` |
Undocumented |

Method | `__float__` |
Undocumented |

Method | `__init__` |
RunningMean(items=None, n=0.0, mean=0.0, sd=0.0) |

Method | `__int__` |
Undocumented |

Method | `__len__` |
Undocumented |

Method | `__repr__` |
Undocumented |

Method | `__str__` |
Undocumented |

Method | `add` |
RunningMean.add(value, repeat=1) |

Method | `add` |
RunningMean.add(values) |

Method | `clear` |
Resets the running mean calculator. |

Property | `mean` |
Returns the current mean |

Property | `result` |
Returns the current mean and standard deviation as a tuple |

Property | `sd` |
Returns the current standard deviation |

Property | `var` |
Returns the current variation |

Instance Variable | `_mean` |
Undocumented |

Instance Variable | `_nitems` |
Undocumented |

Instance Variable | `_sd` |
Undocumented |

Instance Variable | `_sqdiff` |
Undocumented |

RunningMean(items=None, n=0.0, mean=0.0, sd=0.0)

Initializes the running mean calculator.

There are two possible ways to initialize the calculator. First, one can provide an iterable of items; alternatively, one can specify the number of items, the mean and the standard deviation if we want to continue an interrupted calculation.

Parameters | |

items | the items that are used to initialize the running mean calcuator. If items is given, n, mean and sd must be zeros. |

n | the initial number of elements already processed. If this is given, items must be None. |

mean | the initial mean. If this is given, items must be None. |

sd | the initial standard deviation. If this is given, items must be None. |

RunningMean.add(value, repeat=1)

Adds the given value to the elements from which we calculate the mean and the standard deviation.

Parameters | |

value | the element to be added |

repeat | number of repeated additions |

RunningMean.add(values)

Adds the values in the given iterable to the elements from which we calculate the mean. Can also accept a single number. The left shift (`<<`) operator is aliased to this function, so you can use it to add elements as well:

>>> rm=RunningMean() >>> rm << [1,2,3,4] >>> rm.result # doctest:+ELLIPSIS (2.5, 1.290994...)

Parameters | |

values:iterable | the element(s) to be added |