Skip to main content

Maths functions

Project description

https://travis-ci.org/cjrh/cjrh_math.svg?branch=master https://coveralls.io/repos/github/cjrh/cjrh_math/badge.svg?branch=master https://img.shields.io/pypi/pyversions/cjrh_math.svg https://img.shields.io/github/tag/cjrh/cjrh_math.svg https://img.shields.io/badge/install-pip%20install%20cjrh_math-ff69b4.svg https://img.shields.io/pypi/v/cjrh_math.svg https://img.shields.io/badge/calver-YYYY.MM.MINOR-22bfda.svg

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.

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
cjrh_math-2017.11.1-py2.py3-none-any.whl (13.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Nov 10, 2017
cjrh_math-2017.11.1.tar.gz (6.3 kB) Copy SHA256 hash SHA256 Source None Nov 10, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page