Skip to main content

A GPU-accelerated Multivariate Granger Causality implementation using PyTorch.

Project description

PyTorch-MVGC

PyPI version License: MIT

PyTorch-MVGC is a GPU-accelerated Python implementation of Multivariate Granger Causality (MVGC) analysis.

It is designed for high-dimensional time-series data (e.g., EEG, fMRI, MEA) where traditional CPU-based implementations are too slow. By leveraging PyTorch tensors and batched matrix operations, this library achieves significant speedups compared to standard NumPy or Matlab implementations.

Features

  • 🚀 GPU Acceleration: Fully implemented in PyTorch, supporting CUDA acceleration out-of-the-box.
  • ⚡ Batch Processing: Optimized for processing multiple trials or sliding windows simultaneously.
  • 🔧 Numerical Stability: Implements Ridge regularization and Pseudo-inverse solvers to handle ill-conditioned matrices common in high-channel neural recordings (e.g., 128-channel EEG).
  • 🐍 Python Native: A seamless replacement for the Matlab MVGC toolbox for Python pipelines.

Installation

pip install pytorch-mvgc

Quick Start

import numpy as np
import torch
from pytorch_mvgc import compute_mvgc

# 1. Generate sample data (3 channels, 1000 timepoints)
# System: Node 0 drives Node 1
n_time = 1000
X = np.zeros((3, n_time))
noise = 0.5 * np.random.randn(3, n_time)
for t in range(1, n_time):
    X[0, t] = 0.8 * X[0, t-1] + noise[0, t]
    X[1, t] = 0.5 * X[1, t-1] + 0.5 * X[0, t-1] + noise[1, t] # 0->1 Causal
    X[2, t] = 0.7 * X[2, t-1] + noise[2, t]

# 2. Compute MVGC
# Returns matrix F where F[i, j] denotes causality j -> i
F_matrix = compute_mvgc(X, p=1, device='cuda')

print("MVGC Matrix:\n", np.round(F_matrix, 4))
# Expected: F[1, 0] should be significant (> 0)

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

pytorch_mvgc-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

pytorch_mvgc-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytorch_mvgc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f349b3cbfefbc9ffe038b6348b12617e9515c72d45d71d237fdf2e3af7089b23
MD5 2d684eadfc41e31663f353fe9a2dc95e
BLAKE2b-256 583c48f0d948f16ffbb410a3cf426dea1edf52349005f5482eb4b91de42d531c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytorch_mvgc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3da0e9ab4ac7910f9c3ac38197dc1982b83fdda3a75f05ca6a6aadc786e19973
MD5 c017473c6425730784482597ce149881
BLAKE2b-256 68a60203ca3e2963ffad372761fc511ee7a46c15b2425677174e088872419c54

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