Skip to content

pyspi 3.0.0

Latest

Choose a tag to compare

@benfulcher benfulcher released this 29 Nov 23:03
· 6 commits to main since this release
1b64bcf
pip install --upgrade pyspi

pyspi 3.0.0 represents a major overhaul from the previous release. The Java/JIDT dependency is gone, the Calculator API is simpler, computation runs in parallel and can resume, every missing result is labeled with a quality tag (that labels why it is missing a valid value), and many long-standing correctness bugs are fixed. It contains substantial breaking changes; many SPI values differ from 2.0.2: see Upgrading from 2.x.
Note the vision for this package, and others like it, is to have a consistent set of design principles (shared with pyhctsa). Note also that the broad scope of optimizations, implementation, and verification of SPI behavior has been possible with use of AI coding agents (see Contributors for details).

The full list of changes is in the CHANGELOG.

Some highlights

  • Correctness fixes. Among many others: the directed spectral SPIs and ccm_* were transposed, DirectedInfo did not compute directed information, Kraskov estimators mishandled ties, six measures were named kraskov but actually ran a Gaussian estimator, and the constrained soft-DTW and LCSS variants incorrectly ignored their constraint. Every directed SPI now follows a consistent orientation: row = source, column = target.

  • Re-curated SPI sets. full goes from 285 SPIs down to 231: 74 new SPIs have been added (including wavelet coherence, conditional spectral measures, partial correlations, Liang information flow and event synchronisation), 128 SPIs have been removed (duplicates, degenerate estimates and SPIs with behavior tracked ~exactly by another SPI in full) and 22 SPIs have been renamed. New benchmarked_p99, p95, p90 and p80 sets approximately hold the cheapest 99%, 95%, 90% and 80% of the SPIs in full, ranked by measured cost, providing a mechanism to run the vast majority of the SPI library at a fraction of the computational cost (e.g., benchmarked_p90 computes 207 of the 231 SPIs for just ~5% of the cost of full).

  • No Java. Every information-theoretic estimator (KSG, kernel, Gaussian, symbolic) is pure NumPy, so installing pyspi no longer requires a Java runtime, jpype, cdt or torch. The new estimators have been checked against hard-coded outputs of JIDT 1.6.1 in the test suite.

  • A simpler Calculator. Calculator(config="fast") takes a bundled set name or a path to your own YAML file, zscore= replaces normalise=, and every argument after dataset is keyword-only. A new command line, pyspi compute (or python -m pyspi compute), allows a dataset to be computed directly from the shell.

  • Parallel computation and checkpoints. calc.compute(n_jobs=-1) uses all cores, and compute(checkpoint_dir=...) writes each SPI as it finishes and resumes an interrupted run. A resumed run performs verifications for validity, and refuses a changed dataset, config or computation version (& serial, parallel and resumed runs give identical results).

  • Quality labels. Each cell of calc.table has a quality code in calc.quality (a consistent set of codes as implemented in pyhctsa). When the properties of a dataset make it inappropriate for computing a given SPI on it (e.g., a series is too short, has many tied values, many linearly dependent series) gives NaN marked not appropriate, with the reason recorded in calc.not_appropriate, while calc.errors stores unexpected failures. calc.summary() gives the counts of all such cases.

  • Results now retain important context. calc.save() writes a .npz file with the results, quality codes, each SPI's symmetry, and a record of the run (pyspi, computation and dependency versions, and a digest of the config and data), and pyspi.load_table() reads it in. Every SPI is now annotated with labels for what its value means: one of strength (SPI output is a strength of dependence), timing (SPI output encodes a lag or similar) or profile (SPI output encodes some other property of the interaction), and additional labels specify whether the scale of an SPI is signed (0 codes for no dependence, with deviations in both directions) or inverted (lower numbers encode stronger dependence). feature_vector() turns a results table into features for classification or regression: one value per (independent) pair.

Bundled benchmarked SPI sets

Set SPIs Cost vs full Use
full 231 100% everything bundled (the default)
benchmarked_p99 229 ~45% everything except bary_softdtw_corr and gpfit_RBF, which cost more than the other 229 together
benchmarked_p95 213 ~8% p90 plus costlier settings of its methods
benchmarked_p90 207 ~5% large batches
benchmarked_p80 185 ~2% cost-constrained sweeps

Each benchmarked_p* set is ranked over all 231 SPIs of full by amortized cost on one core at M = 16, T = 1000, with a few SPIs placed by hand (details are in the README and in each config's header).

Cost vs full is a rough guide: the summed single-core time of each set's SPIs at M = 16, T = 1000, relative to full. For longer series the cheaper sets save more (at T = 4000, benchmarked_p90 costs about 1% of full).

Note that although full has changed, every SPI that was removed from full in this version (that still has a class) can still be computed from a custom config. The list of which SPIs were added, removed, and renamed is in docs/spi_changes_2.0.2_to_3.0.0.md.

Upgrading from 2.x

  • Requirements: Python ≥ 3.11 (2.0.2: ≥ 3.8), numpy ≥ 2, scikit-learn ≥ 1.8, pyEDM ≥ 2.5, mne ≥ 1.6 and spectral-connectivity ≥ 2.0.
  • Deprecated but still working until 4.0, with a warning: subset= (use config=; subset="all" becomes config="full"), configfile= (use config=), normalise= (use zscore=) and the class name GromovWasserstainTau (now GromovWassersteinTau).
  • Breaking:
    • A positional call such as Calculator(X, "name", None, "fast") raises TypeError: pass every argument after dataset by keyword.
    • Results tables saved by 2.x (pickle) do not load; recompute and save as .npz.
    • The directed spectral SPIs (sgc, dcoh, pdcoh, gpdcoh, dtf, ddtf) are transposed relative to 2.x.
    • SPI classes refuse parameters their estimator ignores, so some 2.x YAML files fail with a clear error.
    • CorrelationFrame's p-value methods raise NotImplementedError, because the p-values were invalid.
  • Saved 2.x results cannot be joined to 3.0 results by SPI name without the rename table, and many values change even where the name does not.

The migration table in the CHANGELOG lists every change alongside its 3.0 equivalent.

If you tested a release candidate

Since 3.0.0rc3, the only change is that Data.add_process() refuses NaN and inf, as Data(...) already did, so a raw-array call such as bivariate(x, y) with a non-finite value in y now raises ValueError. Values are unchanged from rc3. Results from rc1 or rc2 should not be pooled with 3.0.0 for the 12 bundled dcoh_multitaper_* and sgc_nonparametric_* SPIs, or for anm with zscore=False.

Citing pyspi

If you use pyspi, please cite the following article:

O. M. Cliff, A. G. Bryant, J. T. Lizier, N. Tsuchiya and B. D. Fulcher, "Unifying pairwise interactions in complex dynamics", Nature Computational Science 3, 883–893 (2023), doi:10.1038/s43588-023-00519-x.

The software itself can be cited from CITATION.cff.

Contributors

3.0.0 was developed by Ben Fulcher, Will Edibam and Joshua Moore, building on pyspi by Oliver Cliff and the authors of the 2023 article.

Note that much of the SPI implementation and computing infrastructure in this version was developed with the use of Claude Code, Anthropic's AI coding assistant. This allowed us to catch bugs and optimize implementations of SPIs in implementing our vision for pyspi. The SPIs are checked against reference implementations and hard-coded outputs in the test suite.

pyspi is released under the GPL-3.0-or-later licence; code adapted from JIDT, cdt and ids keeps its own notices.