Skip to content

cjrh/cjrh_math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

https://travis-ci.org/cjrh/cjrh_math.svg?branch=master https://coveralls.io/repos/github/cjrh/cjrh_math/badge.svg?branch=master Image Image Image Image Image

cjrh_math

A collection of handy maths functions.

Streaming mean and variance

Sometimes it can be very useful to update an existing mean and variance with new data, rather than have to calculate it again over the whole set. The functions below implement one of the algorithms described in Wikipedia.

def update_mean(n: int, mean: float, value: float) -> float

Given a new value, calculate a new mean using the existing mean and the size of data, n, seen so far.

def update_pvariance(n: int, mean: float, var: float, value: float) -> float
def update_variance(n: int, mean: float, var: float, value: float) -> float

Given a new value, calculate a new variance using the existing mean, existing variance var, and the size of data, n, seen so far.

Note that update_variance() is for sample variance while update_pvariance() is for population variance.

All functions are pure and therefore thread-safe.

About

Handy math routines

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages