Skip to main content

A package for optimized Convergent Cross Mapping using PyTorch.

Project description

FastCCM

PyTorch-based implementation of Convergent Cross Mapping (CCM) optimized for calculating pairwise CCM matrices.

Installation

Requirements: Python ≥ 3.9, pip.

CPU-only:

pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
pip install fastccm

CUDA:

pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121
pip install fastccm

macOS (CPU/MPS):

pip install torch==2.3.1
pip install fastccm

Quick start

This example demonstrates how to use the FastCCM package for performing Convergent Cross Mapping (CCM).

  1. Import Required Libraries
from fastccm import PairwiseCCM, utils
from fastccm.data import get_truncated_rossler_lorenz_rand
import numpy as np
  1. Initialize the CCM Object

Specify the device to use (e.g., "cpu" or "cuda"):

ccm = PairwiseCCM(device="cpu")
  1. Generate Data
# Generate a joint Rossler-Lorenz data
X = get_truncated_rossler_lorenz_rand(400, 20000, alpha=6, C=2, seed=0)

Rossler_emb = utils.embed(X[:, 0], E = 7, tau = 4)   # see find_optimal_embedding_params
Lorenz_emb  = utils.embed(X[:, 3], E = 8, tau = 9)

print(f"Rossler embedding shape: {Rossler_emb.shape}")
print(f"Lorenz embedding shape: {Lorenz_emb.shape}")

alt text

Calculate cross-mapping prediction

# Rossler cross-mapping Lorenz
result_rossler_xmap_lorenz = ccm.score_matrix(
    X_emb=Rossler_emb, 
    Y_emb=Lorenz_emb, 
    library_size=None,  # use maximum points
    sample_size=300,    # use 300 random points to estimate the score
    exclusion_window=50, 
    tp=0, 
    method="simplex",
    seed=0
)

# Lorenz cross-mapping Rossler
result_lorenz_xmap_rossler = ccm.score_matrix(
    X_emb=Lorenz_emb, 
    Y_emb=Rossler_emb, 
    library_size=None, 
    sample_size=300, 
    exclusion_window=50, 
    tp=0, 
    method="simplex",
    seed=0
)

print(f"Rossler xmap Lorenz. Shape: {result_rossler_xmap_lorenz.shape}, score: {result_rossler_xmap_lorenz[-1,0,0]:.3f}")
print(f"Lorenz xmap Rossler. Shape: {result_lorenz_xmap_rossler.shape}, score: {result_lorenz_xmap_rossler[-1,0,0]:.3f}")

Test convergence

from fastccm import ccm_utils

conv_test_res = ccm_utils.Functions("cpu").convergence_test(
    X_emb=Rossler_emb, 
    Y_emb=Lorenz_emb,
    library_sizes=[160, 320, 640, 1250, 2500, 5000, 10000, 20000],
    sample_size=1000, 
    exclusion_window=50, 
    tp=0, 
    method="simplex", 
    trials=20,
    seed=0
)

Plot the convergence test results:

ccm_utils.Visualizer().plot_convergence_test(conv_test_res)

alt text

Find optimal time-delay embedding parameters

optimal_E_tau_res = ccm_utils.Functions("cpu").find_optimal_embedding_params(
    X[:,3], 
    library_size=4000, 
    sample_size=300, 
    exclusion_window=50,
    E_range=np.arange(2,30),
    tau_range=np.arange(1,30),
    tp_max=50,
    method="simplex",
    seed=0
)

print(f"Optimal E: {optimal_E_tau_res['optimal_E']}, optimal_tau: {optimal_E_tau_res['optimal_tau']}")

Plot the results

ccm_utils.Visualizer().visualize_optimal_e_tau(optimal_E_tau_res)

alt text

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

fastccm-0.2.4a1.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

fastccm-0.2.4a1-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file fastccm-0.2.4a1.tar.gz.

File metadata

  • Download URL: fastccm-0.2.4a1.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastccm-0.2.4a1.tar.gz
Algorithm Hash digest
SHA256 474743331d1447ba6bb65927adfaf26b9f78ac076692a4031c21680eb9732eec
MD5 63a3862286f4a81038b0333c49a9aa98
BLAKE2b-256 0b292d9ba4ea1c33ea875d7568c0051a1c0cc7bebf0eb8d055d58574ee5e6f3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastccm-0.2.4a1.tar.gz:

Publisher: python-publish.yml on z7743/FastCCM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastccm-0.2.4a1-py3-none-any.whl.

File metadata

  • Download URL: fastccm-0.2.4a1-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastccm-0.2.4a1-py3-none-any.whl
Algorithm Hash digest
SHA256 71bd69e251ad89f7464767957233b2a015b01357a3e76075b7762e5a6cde13ec
MD5 2d2f6f441e2f343bac2f9b509ae393eb
BLAKE2b-256 fd8de8e7cf98dff794367206de08ae5ec52a5796ddd967443721cdd5d589946e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastccm-0.2.4a1-py3-none-any.whl:

Publisher: python-publish.yml on z7743/FastCCM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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