Skip to main content

Online covariance

Project description

precise

Online covariance, correlation and precision matrix computations

Install

pip install precise 

Example

from precise.covariance.util import create_correlated_dataset
from precise.covariance.onlineempirical import online_empirical_cov
import numpy as np
from pprint import pprint

data = create_correlated_dataset(10000, (2.2, 4.4, 1.5),
                                 np.array([[0.2, 0.5, 0.7], [0.3, 0.2, 0.2], [0.5, 0.3, 0.1]]), (1, 5, 3))
s = online_empirical_cov(n_dim=data.shape[1])
for observation in data:
    s = online_empirical_cov(s=s, y=observation)
pprint(s)

This will return the running state, which includes the mean and cov

{'count': 10000,
 'cov': array([[0.38549265, 1.55198303, 0.73809891],
       [1.55198303, 9.41813338, 6.20756741],
       [0.73809891, 6.20756741, 4.79042088]]),
 'identity': array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]]),
 'mean': array([2.19919374, 4.42189785, 1.52406171]),
 'n_dim': 3,
 'ones': array([1., 1., 1.]),
 'shape': (3, 3)}

To covert to corrcoef,

  from precision.covariance.util import cov_to_corrcoef
  pprint( cov_to_corrcoef(s['cov']) )

returns:

  array([[1.        , 0.81749783, 0.55345955],
   [0.81749783, 1.        , 0.92689045],
   [0.55345955, 0.92689045, 1.        ]])

See also

If you only need univariate, there is a really minimalise package momentum which avoids use of numpy.

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

precise-0.0.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

precise-0.0.2-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file precise-0.0.2.tar.gz.

File metadata

  • Download URL: precise-0.0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for precise-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4dd4aa018192dea1a1db87b37c9ea2461bd78a37d65ad59083278ec81deb0e4c
MD5 9e687a4eb322b2e35933a300a060d9a5
BLAKE2b-256 faf9500ad0c3e67d3aadc39c071cd04629a951bbc678ed49855f812a71dbf73f

See more details on using hashes here.

File details

Details for the file precise-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: precise-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for precise-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6d5e9f29c9bc94e7cab9364b59f83dbfe0e085c60c5a515c9e0902e4c7dc85dc
MD5 4eb16e2ac619dee8cf4c5524c89c16e5
BLAKE2b-256 cba9a7851ca025287c451d4eacc9f429532a39706b0c52096204cba76b720b12

See more details on using hashes here.

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