Skip to main content

ts2g2

TS2G2 stands for "timeseries to graphs and back". The library implements a variety of strategies to convert timeseries into graphs, and convert graphs into sequences. Below, we provide a code snippet to generate a graph from timeseries:

# load time series from a file
timegraph = Timeseries(CsvStock(some_file_path, "ColumnOfInterest").from_csv())\

# and preprocess the timeseries with multiple preprocessing strategies
.with_preprocessing(TimeseriesPreprocessingComposite()\
    .add_strategy(TimeseriesPreprocessingSegmentation(60, 120))\
    .add_strategy(TimeseriesPreprocessingSlidingWindow(5)))\

# then create a graph from the timeseries, following a particular strategy
.to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\

# link graphs that result from the same timeseries, but at different sliding window frames
.link(LinkGraphs().sliding_window())\

# and combine identical graphs that result from the abovementioned time windows into single nodes
.combine_identical_nodes_slid_win()\

# finally, draw the graph
.draw("red")

For a more detailed example, look at the Amazon stocks demo.

Many of the methods implemented in this library are described in Silva, Vanessa Freitas, et al. "Time series analysis via network science: Concepts and algorithms." Wiley Interdisciplinary Reviews: Data Mining and Knowledge Discovery 11.3 (2021): e1404. Nevertheless, the library also includes additional techniques found in other works from the scientific literature.

This package is being developed as part of the Graph-Massivizer project. The package is a joint effort between the Jožef Stefan Institute, the University of Twente, the Vrije Universiteit Amsterdam, the University of Klagenfurt, the University of Bologna, and Peracton.

Timeseries to graph conversion

Implemented features

# Visibility Graph Graph type Constraints
Undirected Directed Weighted
Penetration Angle
1 Natural Visibility Graph X X X X X
2 Horizontal Visibility Graph X X X X X
3 Difference Visibility Graph
4 Quantile Graph X X
5 Ordinal Partition Graph X X

References table

# Visibility Graph Graph type Constraints
Undirected Directed Weighted
Penetration Angle
1 Natural Visibility Graph ref ref ref ref, ref
2 Horizontal Visibility Graph ref ref ref ref, ref
3 Difference Visibility Graph
4 Quantile Graph ref
5 Ordinal Partition Graph

Graphs to timeseries conversion

Graphs are converted back to timeseries by sampling node values from the graph following different strategies. Below, we provide a short snippet of code, to illustrate how this can be done.

timegraph.to_sequence(ToSequenceVisitorSlidingWindow()\
.next_node_strategy(StrategySelectNextNodeRandomlyFromFirstGraph())\
.next_value_strategy(StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\
.ts_length(50))\
.draw_sequence()

When choosing the next node, the following strategies have been implemented so far: random node, random node neighbour, random node degree, random walk, random walk with restart, random walk with jump.

Publications

When using this work for research purposes, we would appreciate it if the following references could be included:

Below we provide a curated list of papers related to our research in this area:

Metadata

Release files for ts2g2 0.1.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 ts2g2 0.1.0
File Size Uploaded Provenance Actions
ts2g2-0.1.0.tar.gz 18.5 kB Without provenance Details for ts2g2-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ts2g2 0.1.0
File Interpreter ABI Platform Actions
ts2g2-0.1.0-py3-none-any.whl Python 3 none any Details for ts2g2-0.1.0-py3-none-any.whl

Total release size: 25.9 kB

Release files / ts2g2-0.1.0.tar.gz

Download URL ts2g2-0.1.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1820c425d494e4d50b6f0a2cbbcdb0806e0d43d312bb65c4dc4acceebe544f2a
BLAKE2b-256 checksum
How to use checksums
adf03e2dccb55dc0ad33ceca3426cf271760cd6681cb4f790cec558a79f509dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / ts2g2-0.1.0-py3-none-any.whl

Download URL ts2g2-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a0c8d7b3a645d678ae7313b49d169b0e3dbc8f26e7a28bd43311b17b0035520
BLAKE2b-256 checksum
How to use checksums
55e89d4c3801bd28645eb6ce6c67266ea5818d165a893bc5737c20d15c93fb48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for ts2g2 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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