Skip to main content

Online statistics for Numpy arrays.

Project description

numpy-onlinestats

PyPI pre-commit.ci status unit tests Documentation Status

This is a Python package for element-wise streaming statistics of Numpy arrays, meaning that arrays can be added one-by-one. This is much more memory-efficient than first collecting all arrays before calculating statstics. One major usecase is Bayesian modeling, where the posterior distribution is often intractable and can only be approximated via sampling. This concerns both MCMC and variational inference meethods. MCMC is inherently sampling-based, while variational inference methods can have derived quantities or structured posteriors that do not admit closed-form expressions for properties of their distribution.

numpy-onlinestats approximates quantiles and cumulative distribution functions using the t-digest algorithm (in particular, it uses this implementation) and calculates exact moments using a numerically stable algorithm.

Requirements

  • Python 3.10 or newer
  • A C++20 compatible compiler (developed with GCC 13 using -std=c++20)

Sample code

import numpy as np
import numpy_onlinestats as npo

stats = npo.NpOnlineStats(np.random.uniform((5, 3, 7)))
for i in range(100):
    stats.add(np.random.uniform((5, 3, 7)))

stats.quantile(0.25)
stats.mean()
stats.var()

Project details


Download files

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

Source Distribution

numpy-onlinestats-0.1.0.tar.gz (662.8 kB view hashes)

Uploaded Source

Built Distributions

numpy_onlinestats-0.1.0-cp311-cp311-win_amd64.whl (676.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

numpy_onlinestats-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

numpy_onlinestats-0.1.0-cp311-cp311-macosx_10_15_x86_64.whl (409.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.15+ x86-64

numpy_onlinestats-0.1.0-cp310-cp310-win_amd64.whl (676.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

numpy_onlinestats-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (221.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

numpy_onlinestats-0.1.0-cp310-cp310-macosx_10_15_x86_64.whl (409.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page