Time series to network conversion and analysis
Project description
ts2net
Time series to networks. Clean API for visibility graphs, recurrence networks, and transition networks.
Install
Basic Installation
pip install ts2net
Optional Dependencies
Install with optional features:
# Performance acceleration (Numba)
pip install ts2net[speed]
# BSTS decomposition (statsmodels)
pip install ts2net[bsts]
# Temporal CNN embeddings (PyTorch)
pip install ts2net[cnn]
# All optional features
pip install ts2net[all]
# Development dependencies
pip install ts2net[dev]
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:
pip install ts2net[bsts] # Installs statsmodels
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
limitcan 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=Trueto 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 delayrule: 'knn', 'epsilon', 'radius'k: neighbors for k-NNepsilon: 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"oroutput="stats"instead ofoutput="edges" - For NVG, always set
limitparameter (e.g.,limit=5000) - For recurrence networks, use
rule='knn'with smallk(10-30) instead of exact all-pairs
Slow performance:
- Install Numba:
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=-1for 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 --releaseafter installing Rust
NetworkX conversion refused:
- For very large graphs (n > 200k), NetworkX conversion is disabled by default
- Use
force=Trueto override:hvg.as_networkx(force=True) - Consider using
output="degrees"oroutput="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.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ts2net-0.7.1.tar.gz.
File metadata
- Download URL: ts2net-0.7.1.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00fa0fa5a3750c18a2db2a64228b4c9919e7d0a78ff805839536d34a90838dc6
|
|
| MD5 |
1fafeda9654104f41c78d0d324bf2edd
|
|
| BLAKE2b-256 |
940d61abb66c11f7bd03f420f7c4b1a1bab66e65ad476f3314804fcbc1d2a9b7
|
Provenance
The following attestation bundles were made for ts2net-0.7.1.tar.gz:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1.tar.gz -
Subject digest:
00fa0fa5a3750c18a2db2a64228b4c9919e7d0a78ff805839536d34a90838dc6 - Sigstore transparency entry: 805103106
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 549.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4090561d407bce665ff96ba54562fd6b075c2618596c8635da566b365b82a5e7
|
|
| MD5 |
4c27cf1efe36735a82ad11071d162354
|
|
| BLAKE2b-256 |
aa546fd72c7ada013e2c1ce268af09516f32f57490a49a3f3b005be62b3d5fd8
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp313-cp313-win_amd64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp313-cp313-win_amd64.whl -
Subject digest:
4090561d407bce665ff96ba54562fd6b075c2618596c8635da566b365b82a5e7 - Sigstore transparency entry: 805103131
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp313-cp313-manylinux_2_24_x86_64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp313-cp313-manylinux_2_24_x86_64.whl
- Upload date:
- Size: 655.2 kB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f7e0bf9912e491ab4dccdd14ece0cfe9bedf95340f5308136d5eabd773a32f
|
|
| MD5 |
e98325639f3140bf1fd3a50db0245cee
|
|
| BLAKE2b-256 |
bfc813beca069aeaa62a7c14979f7239dfb67ed563ee6568aa7d10c63051ed35
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp313-cp313-manylinux_2_24_x86_64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp313-cp313-manylinux_2_24_x86_64.whl -
Subject digest:
f8f7e0bf9912e491ab4dccdd14ece0cfe9bedf95340f5308136d5eabd773a32f - Sigstore transparency entry: 805103126
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 450.0 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66d791977d7a51e6e5a263be4a3573796016fc8137ee32a660bc24d563132d10
|
|
| MD5 |
a3b58969363cece973beb6fefeb4a322
|
|
| BLAKE2b-256 |
db958253ef96fe0cf1a279bdebc7143be5e3a88321a50e084df126738981c863
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
66d791977d7a51e6e5a263be4a3573796016fc8137ee32a660bc24d563132d10 - Sigstore transparency entry: 805103110
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 549.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9fb6cbb7bb3309ba3830b64304621f37d97ed01378b729e7ab88b46880efff1
|
|
| MD5 |
a6e508d400c2c9c3b079cf6fd234f577
|
|
| BLAKE2b-256 |
44df8353624a7f09174806a5b4d7bb0f39320fe8d41214a5379df110d42b8932
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp312-cp312-win_amd64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp312-cp312-win_amd64.whl -
Subject digest:
e9fb6cbb7bb3309ba3830b64304621f37d97ed01378b729e7ab88b46880efff1 - Sigstore transparency entry: 805103116
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp312-cp312-manylinux_2_24_x86_64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp312-cp312-manylinux_2_24_x86_64.whl
- Upload date:
- Size: 655.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ed47d7fa5b5a2a824f903a6faff072ab790f99d5e33e7399f8cfbb927bb24d3
|
|
| MD5 |
396dc07808fec90e8f78c7e7a3966c7b
|
|
| BLAKE2b-256 |
e3a482805ff080f5d162f7e2b12aafe2ea4188f29dff3d67217e800ea33670fd
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp312-cp312-manylinux_2_24_x86_64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp312-cp312-manylinux_2_24_x86_64.whl -
Subject digest:
3ed47d7fa5b5a2a824f903a6faff072ab790f99d5e33e7399f8cfbb927bb24d3 - Sigstore transparency entry: 805103114
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ts2net-0.7.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: ts2net-0.7.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 450.0 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e0ed27aa954b87127aa9d02696a8a70bfa8ba469b53eadbc035544bc6d2a96
|
|
| MD5 |
fb853c5ecdf36379ffff6f61b4d9f793
|
|
| BLAKE2b-256 |
b433fff50bb9bb37f89582b41c01c4f4d8c865a39f2ebef5e78e175525277aee
|
Provenance
The following attestation bundles were made for ts2net-0.7.1-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on kylejones200/ts2net
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ts2net-0.7.1-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
a1e0ed27aa954b87127aa9d02696a8a70bfa8ba469b53eadbc035544bc6d2a96 - Sigstore transparency entry: 805103119
- Sigstore integration time:
-
Permalink:
kylejones200/ts2net@039ab82bc74d6297c99a310599d5a1c051100f43 -
Branch / Tag:
refs/tags/v0.7.1-test - Owner: https://github.com/kylejones200
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@039ab82bc74d6297c99a310599d5a1c051100f43 -
Trigger Event:
push
-
Statement type: