Skip to main content

ts2net

PyPI version Documentation Status Tests License: MIT

Time series to networks. Clean API for visibility graphs, recurrence networks, and transition networks.

Install

Basic Installation

Installs core network builders and sklearn integration:

# Using uv (recommended)
uv pip install ts2net

# Or using pip
pip install ts2net

Optional Feature Tiers

# YAML pipeline CLI + Parquet I/O
uv pip install "ts2net[pipeline]"

# Structural decomposition (BSTS)
uv pip install "ts2net[bsts]"

# Performance acceleration (Numba)
uv pip install "ts2net[speed]"

# All optional features
uv pip install "ts2net[all]"
Extra Includes Use when
(core) numpy, scipy, networkx, sklearn, matplotlib Building networks, sklearn features
[pipeline] click, pyyaml, polars, pyarrow ts2net run, Parquet ingestion
[bsts] statsmodels Structural decomposition
[polars] polars, pyarrow Polars-only ingestion (subset of pipeline)
[speed] numba 100–180× visibility graph speedup
[all] everything above + dtw, cnn, examples, viz Full development setup

Development Installation

For development, use uv:

# Clone the repository
git clone https://github.com/kylejones200/ts2net.git
cd ts2net

# Install with uv (creates virtual environment and installs dependencies)
uv sync --group dev

# Build Rust extension
uv run maturin develop --release

Optional Dependencies

# Using uv
uv pip install "ts2net[pipeline]"   # CLI + Parquet pipeline
uv pip install "ts2net[bsts]"       # BSTS decomposition
uv pip install "ts2net[speed]"      # Performance acceleration (Numba)
uv pip install "ts2net[dtw]"        # DTW distance (tslearn)
uv pip install "ts2net[cnn]"        # Temporal CNN embeddings (PyTorch)
uv pip install "ts2net[examples]"   # Example dependencies
uv pip install "ts2net[all]"        # All optional features

# Or using pip
pip install "ts2net[pipeline]"
pip install "ts2net[bsts]"
pip install "ts2net[speed]"

Verify Installation

import ts2net
print(ts2net.__version__)

from ts2net import HVG
import numpy as np
x = np.random.randn(100)
hvg = HVG()
hvg.build(x)
print(f"Installation successful: {hvg.n_nodes} nodes, {hvg.n_edges} edges")

Quick Start

import numpy as np
from ts2net import HVG

x = np.random.randn(1000)

hvg = HVG()
hvg.build(x)

print(hvg.n_nodes, hvg.n_edges)
print(hvg.degree_sequence())

Adjacency Matrix

A = hvg.adjacency_matrix()
print(A.shape)  # (1000, 1000)

NetworkX (Optional)

NetworkX is optional. Convert only if needed:

G = hvg.as_networkx()
import networkx as nx
print(nx.average_clustering(G))

Structural Decomposition and Residual Topology

For time series with predictable structure (seasonality, trends), decompose first, then analyze the residual:

from ts2net.bsts import features, BSTSSpec

# Decompose and analyze residual in one pass
spec = BSTSSpec(
    level=True,
    trend=False,
    seasonal_periods=[24, 168]  # Daily and weekly for hourly data
)

result = features(x, methods=['hvg', 'transition'], bsts=spec)

# Access three feature blocks
raw_stats = result.raw_stats              # Basic series statistics
structural_stats = result.structural_stats # Component variances, seasonal strength
residual_network_stats = result.residual_network_stats  # Network features from residual

Use cases:

  • Compare meters/wells without seasonal confounds
  • Flag series where structural model fails (high residual complexity)
  • Separate predictable structure from irregular dynamics

Installation: BSTS requires the [bsts] extra (statsmodels is not in the core install):

uv pip install "ts2net[bsts]"
# Or: pip install "ts2net[bsts]"

See examples/bsts_features.py for complete examples.

Large Series

For large series, use output modes to control memory usage:

# Degrees only (most memory efficient)
hvg = HVG(output="degrees")
hvg.build(x)
degrees = hvg.degree_sequence()  # Fast, no edge storage

# Stats only (summary statistics without edges)
hvg = HVG(output="stats")
hvg.build(x)
stats = hvg.stats()  # n_nodes, n_edges, avg_degree, etc.

# Full edges (default, use for small-medium series)
hvg = HVG(output="edges")
hvg.build(x)
edges = hvg.edges  # Full edge list

Scale Guidelines

Series Length Method Recommended Settings Memory Risk
n < 10k All methods output="edges" Safe
10k < n < 100k HVG output="edges" or output="degrees" Safe with sparse
10k < n < 100k NVG limit=2000-5000, output="degrees" Use horizon limit
10k < n < 100k Recurrence rule='knn', k=10-30 Avoid exact all-pairs
n > 100k HVG output="degrees" or output="stats" Safe
n > 100k NVG limit=2000-5000, max_edges=1e6, output="degrees" Required limits
n > 100k Recurrence rule='knn', k=10-30, output="degrees" kNN only

Critical Warnings:

  • Dense adjacency matrices are disabled by default for n > 50k (prevents 63GB+ memory blowup)
  • NVG without limit can create millions of edges for smooth series
  • Recurrence exact all-pairs is O(n²) memory - use kNN for large n
  • NetworkX conversion refused for n > 200k (use force=True to override)

Memory Estimates:

  • Dense adjacency: ~8 * n² bytes (e.g., 90k nodes = 63 GB)
  • Sparse adjacency: ~16 * m bytes where m = edges (e.g., 100k edges = 1.6 MB)
  • Edge list: ~16 * m bytes (similar to sparse)
  • Degrees only: ~8 * n bytes (e.g., 90k nodes = 720 KB)

Methods

Visibility Graphs

HVG - Horizontal Visibility Graph

from ts2net import HVG

hvg = HVG(weighted=False, limit=None)
hvg.build(x)

NVG - Natural Visibility Graph

from ts2net import NVG

# For large series, use horizon limit and bounded work
nvg = NVG(weighted=False, limit=5000, max_edges=1_000_000, output="degrees")
nvg.build(x)

# Or with memory limit
nvg = NVG(limit=2000, max_memory_mb=100)  # Caps at ~100MB
nvg.build(x)

Recurrence Networks

Phase space recurrence:

from ts2net import RecurrenceNetwork

rn = RecurrenceNetwork(m=3, tau=1, rule='knn', k=5)
rn.build(x)

Parameters:

  • m: embedding dimension (None = auto via FNN)
  • tau: time delay
  • rule: 'knn', 'epsilon', 'radius'
  • k: neighbors for k-NN
  • epsilon: threshold for epsilon-recurrence

Transition Networks

Symbolic dynamics:

from ts2net import TransitionNetwork

tn = TransitionNetwork(symbolizer='ordinal', order=3)
tn.build(x)

Symbolizers:

  • 'ordinal': ordinal patterns
  • 'equal_width': equal-width bins
  • 'equal_freq': equal-frequency bins (quantiles)
  • 'kmeans': k-means clustering

Compare Methods

from ts2net import build_network

x = np.random.randn(1000)

for method in ['hvg', 'nvg', 'recurrence', 'transition']:
    if method == 'recurrence':
        g = build_network(x, method, m=3, rule='knn', k=5)
    elif method == 'transition':
        g = build_network(x, method, symbolizer='ordinal', order=3)
    else:
        g = build_network(x, method)
    
    print(f"{method}: {g.n_edges} edges")

Output:

hvg: 1979 edges
nvg: 2931 edges
recurrence: 3159 edges
transition: 18 edges

Multivariate

Multiple time series → network where nodes = time series:

from ts2net.multivariate import ts_dist, net_knn

X = np.random.randn(30, 1000)  # 30 series, 1000 points each

D = ts_dist(X, method='dtw', n_jobs=-1)
G = net_knn(D, k=5)

print(G.n_nodes, G.n_edges)

Distance methods: 'correlation', 'dtw', 'nmi', 'voi', 'es', 'vr'

Network builders: net_knn, net_enn, net_weighted

Performance

With Numba (recommended):

pip install numba

Speedups:

  • HVG: 100x faster
  • NVG: 180x faster
  • Recurrence: 10x faster

API

All methods follow the same pattern:

builder = Method(**params)
builder.build(x)

# Access results
builder.n_nodes
builder.n_edges
builder.edges                # list of tuples
builder.degree_sequence()    # numpy array
builder.adjacency_matrix()   # numpy array
builder.as_networkx()        # optional conversion

Troubleshooting

Common Issues

Memory errors with large time series:

  • Use output="degrees" or output="stats" instead of output="edges"
  • For NVG, always set limit parameter (e.g., limit=5000)
  • For recurrence networks, use rule='knn' with small k (10-30) instead of exact all-pairs

Slow performance:

  • Install Numba: uv pip install numba or pip install numba (100-180x speedup for visibility graphs)
  • Use output="degrees" if you don't need full edge lists
  • For multivariate, use n_jobs=-1 for parallel distance computation

Import errors:

  • Ensure you're using Python 3.12+
  • If Rust extension fails to build, install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • For development, run maturin develop --release after installing Rust

NetworkX conversion refused:

  • For very large graphs (n > 200k), NetworkX conversion is disabled by default
  • Use force=True to override: hvg.as_networkx(force=True)
  • Consider using output="degrees" or output="stats" instead

Getting Help

Citation

Multivariate methods based on:

Ferreira, L.N. (2024). From time series to networks in R with the ts2net package. Applied Network Science, 9(1), 32. https://doi.org/10.1007/s41109-024-00642-2

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Case Study

Try the Spain smart meter case study in Binder (no dataset download required):

Binder

License

MIT

Metadata

Release files for ts2net 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ts2net 0.9.0
File Size Uploaded Provenance Actions
ts2net-0.9.0.tar.gz 21.7 kB With provenance Details for ts2net-0.9.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ts2net 0.9.0
File Actions
ts2net-0.9.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for ts2net-0.9.0-cp313-cp313-win_amd64.whl
ts2net-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for ts2net-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
ts2net-0.9.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for ts2net-0.9.0-cp313-cp313-macosx_11_0_arm64.whl
ts2net-0.9.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for ts2net-0.9.0-cp312-cp312-win_amd64.whl
ts2net-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for ts2net-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
ts2net-0.9.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for ts2net-0.9.0-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 3.4 MB

Release files / ts2net-0.9.0.tar.gz

Download URL ts2net-0.9.0.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ef84f745e628fe53328bac8f2faf8956810c5c561483429a417285db92a96097
BLAKE2b-256 checksum
How to use checksums
48fd7ba99849e54b91304505f2e686a8f6dc010b4ae68220ddaefe17e7ae467f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp313-cp313-win_amd64.whl

Download URL ts2net-0.9.0-cp313-cp313-win_amd64.whl
Size 551.7 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
7414a08346aff5cdc3b1b69056f4da4b98e46d1dc6bd71a6d7cab1e3ca00155e
BLAKE2b-256 checksum
How to use checksums
4fdbcb84f25c7f80121ea8e6788d99e7989380e41bdd534c563fafa1dc930760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ts2net-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 658.2 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b5992a98e96c139e7689cc627ab2d232b6e8e1b331dea9dbf18b124aa6406c96
BLAKE2b-256 checksum
How to use checksums
e32fd9ab96150f87804386216defa07b172aeb97ea0f098a94eb244e9161fea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL ts2net-0.9.0-cp313-cp313-macosx_11_0_arm64.whl
Size 457.8 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fd616b15e63ae9c88653f3c49c9501ce6ef640c0e1a71ecbadab20abeadb6a36
BLAKE2b-256 checksum
How to use checksums
22766b3b14f9c4b999d2c69dfa60d171099b6014343cd1cec3eb27cfe101d805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp312-cp312-win_amd64.whl

Download URL ts2net-0.9.0-cp312-cp312-win_amd64.whl
Size 551.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
e1b6910660829e84ec9a7158ee24ca296472d6611a122c994908295f4df684cb
BLAKE2b-256 checksum
How to use checksums
9b8be973a42801e25ad0ba632d8c89941caf672521298bceda0de54ca3fe52c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ts2net-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 658.1 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f5967e5b653f93cae002593ff479903e4e45e2253a3702cffcdb522816d5952a
BLAKE2b-256 checksum
How to use checksums
33258960273383a1b8c5704af7fb66c7027cdddb991eab87de48937ab94cd805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / ts2net-0.9.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL ts2net-0.9.0-cp312-cp312-macosx_11_0_arm64.whl
Size 457.7 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d3267f4e114843dd4b082c42cb514e2ab6ffcdc4b0be648e84dffc408fa67aa8
BLAKE2b-256 checksum
How to use checksums
c2977653bc85e7798cc9c310306dfb0f7710a3c65bccccba45220b43722fe9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Security for ts2net 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for ts2net-0.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page