Skip to main content

PyCorrelation is a Python package designed to handle symmetric and correlation matrices efficiently.

Project description

PyCorrelation

PyCorrelation is a Python package designed to handle symmetric and correlation matrices efficiently. It builds upon the concept of symmetric matrices to provide a class dedicated to correlation operations, ensuring values fall within the valid range $(-1,1)$, and automatically maintaining correlations of 1 on the diagonal.

Features

  • A class ensuring symmetry in a matrix: $x_{i,j} = x_{j,i}$
  • A class for managing correlation matrices with strict validation of correlation values.
  • Methods to set, retrieve, and validate correlation pairs using user-friendly indexers.

Installation

To install PyCorrelation, you can clone the repository and use pip:

git clone https://github.com/SRKX/PyCorrelation.git
cd PyCorrelation
pip install .

Usage

Below is an example of how to use the package:

from PyCorrelation import CorrelationMatrix

# Initialize a CorrelationMatrix
correl_matrix = CorrelationMatrix(keys=['A', 'B', 'C'], frozen_keys=True)

# Set correlations
correl_matrix[('A', 'B')] = 0.5
correl_matrix[('B', 'C')] = -0.2

# Access correlation values
print(correl_matrix[('B', 'A')])  # Outputs: 0.5

# Check if a key pair is in the matrix
print(('A', 'B') in correl_matrix)  # Outputs: True

Classes and Methods

SymmetricMatrix

This is the base class for symmetric matrices. It allows you to define and manipulate a matrix where elements are mirrored across the diagonal.

Public Methods

  • keys(): Returns the keys of the matrix.
  • to_2d_dict(selected_keys=None): Converts the matrix into a 2D dictionary, extracting only the selected keys (or all if not specified).
  • to_2d_array(ordered_keys): Converts the matrix into a 2D array representation, returning a list of lists where the indices follow the ordered of the input parameter.

CorrelationMatrix

This class extends SymmetricMatrix and is specialized for correlation matrices. It includes additional validation to ensure values are always in $(-1,1)$, and that identical keys always have a correlation of 1.

License

This project is licensed under the MIT License.

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

pycorrelation-0.0.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

pycorrelation-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycorrelation-0.0.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for pycorrelation-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1a0dc6f00c950eca557ae91d2d11ae07c4e7a5b4975d6c04faac5e2fd66bd749
MD5 2f5742569ee8b5edd91f59ca675ab8ce
BLAKE2b-256 b56e6145f3c78aab0e5d6d746b62bda78556f757384448c48b331de1e532b059

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycorrelation-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for pycorrelation-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 911ef46b536c05216a19e2e7e02e8d943e060e24e73575a32f92263c7d315135
MD5 15fbfd8b11891fe97fdff9eeb504e957
BLAKE2b-256 c144ba8bcce8f6aa6daf26b7ac6d06358e88dacc18d035eccaf605644b305c56

See more details on using hashes here.

Supported by

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