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.
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dd4aa018192dea1a1db87b37c9ea2461bd78a37d65ad59083278ec81deb0e4c
|
|
| MD5 |
9e687a4eb322b2e35933a300a060d9a5
|
|
| BLAKE2b-256 |
faf9500ad0c3e67d3aadc39c071cd04629a951bbc678ed49855f812a71dbf73f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d5e9f29c9bc94e7cab9364b59f83dbfe0e085c60c5a515c9e0902e4c7dc85dc
|
|
| MD5 |
4eb16e2ac619dee8cf4c5524c89c16e5
|
|
| BLAKE2b-256 |
cba9a7851ca025287c451d4eacc9f429532a39706b0c52096204cba76b720b12
|