Skip to main content

A python impementation of covariance matrices.

Project description

covmats

License Stars Python PyPI Downoads Build Status Documentation Status Coverage codacy Precommit: enabled Ruff Checked with ty DOI

🐍 Covariance matrices representation.

The complete and up to date documentation can be found here: https://covmats.readthedocs.io.

🎯 Motivations

Calculations involving covariance matrices (e.g. linear algebra, data whitening, multivariate normal function evaluation) are often performed more efficiently using a decomposition of the covariance matrix instead of the covariance matrix itself. For large scale application, a dense covariance matrix would not even fit in memory and one must rely on low-rank approxiations. This package allows the user to construct an object representing a covariance matrix using any of several decompositions/approximations and perform calculations using a common interface.

The common interface CovarianceMatrix can be seen as a extension of the class scipy.stats.Covariance as it inherits from it (thus making it compatible with all scipy.stats functions and classes) and dope it with LinearOperator capabilities.

The package is used in large-scale inversion packages such as pypcga, pyesmda and pyrtid.

🚀 Quick start

To install covmats, the easiest way is through pip:

pip install covmats

Or alternatively using conda

conda install covmats

You might also clone the repository and install from source

pip install -e .

Once the installation is done, covmats is straighforward to use and proposes the following full-rank covariance representations:

It also provides low-rank approximations suitable for large scale problems:

Let’s start by importing numpy, scipy and covmats for the tests and define a random number generator seed for reproducibility:

import numpy as np
import scipy as sp
import covmats

rng_seed = 2026

First example with a diagonal covariance matrix

In the following, we define a (3 x 3) covariance matrix defining only its diagonal (i.e., all elements of the random vectors are independent). Using scipy, it is possible to compute the pdf.

d = [1, 2, 3]
A33 = np.diag(d)  # a diagonal covariance matrix
x = [4, -2, 5]  # a point of interest
dist = sp.stats.multivariate_normal(mean=[0, 0, 0], cov=A33)
dist.pdf(x)
np.float64(4.9595685102808205e-08)

It is possible to obtain a dense representation in a straighforward manner:

cov_diag33 = covmats.CovViaDiagonal(d)
dist = sp.stats.multivariate_normal(mean=[0, 0, 0], cov=cov_diag33)
dist.pdf(x)
np.float64(4.9595685102808205e-08)

It is compatible with the stats API from scipy since the base class inherit from Covariance.

🏗️ Complete example with supporting paper coming Q1 2026.

🔑 License

This project is released under the BSD 3-Clause License.

Copyright (c) 2026, Antoine COLLET. All rights reserved.

For more details, see the LICENSE file included in this repository.

⚠️ Disclaimer

This software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, or non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.

By using this software, you agree to accept full responsibility for any consequences, and you waive any claims against the authors or contributors.

📧 Contact

For questions, suggestions, or contributions, you can reach out via:

We welcome contributions!

📚 References

TODO

  • Free software: SPDX-License-Identifier: BSD-3-Clause

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

covmats-0.1.0.tar.gz (68.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

covmats-0.1.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file covmats-0.1.0.tar.gz.

File metadata

  • Download URL: covmats-0.1.0.tar.gz
  • Upload date:
  • Size: 68.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for covmats-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a439cfcda90fe201a7c256ebdf83403a46ab7aff5a1feddcbb6b6868a2b043b
MD5 90af030c1f67577039c04811ec7d6a2f
BLAKE2b-256 73b4511811640d18ce845e147334a18bcfa7a292e6252c55b3d50f4de6bcde9b

See more details on using hashes here.

File details

Details for the file covmats-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: covmats-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for covmats-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7fd318ccbc154e4e660db24deafe36b5d4cb73986f7ea18970303f3e1b443056
MD5 d26907b577f31f95a8204e8d632bc469
BLAKE2b-256 188b6e1b60ec2a8e7622410a0aab6af0feb3bc6d7d0bd6e8ea0afb36257b54b2

See more details on using hashes here.

Supported by

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