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 --upgrade pip
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"

CUDA:

pip install --upgrade pip
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"

macOS (CPU/MPS):

pip install --upgrade pip
pip install torch==2.3.1
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"

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.3a1.tar.gz (23.1 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.3a1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastccm-0.2.3a1.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for fastccm-0.2.3a1.tar.gz
Algorithm Hash digest
SHA256 3e993a359a0337d965bbc3086e40c6579adc06cf825165785d0235d6a2be25c6
MD5 10a6b9fa5b375d2370836e1d839f53af
BLAKE2b-256 79f067800967d5fb5ec9e318394869bef864c318455d7d06e493b139d4b8a7c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastccm-0.2.3a1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for fastccm-0.2.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 8480a6c1aaaa470b7be00b67753933e720f9b4f9a6ec64ad34cf4a234923bfd2
MD5 b7a6db6976b17111e36f8da7bfac2e0b
BLAKE2b-256 83c7de3eb3d33f72c89f137755d6aa614e3dd766a27ab412767b38359e86bd7a

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