|
1 | 1 | # ts2g<sup>2</sup> |
2 | 2 |
|
3 | | -TS2G<sup>2</sup> stands for "timeseries to graphs and back". The library implements a variety of strategies to convert timeseries into graphs, and convert graphs into sequences. |
| 3 | +TS2G<sup>2</sup> 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: |
| 4 | + |
| 5 | + # load time series from a file |
| 6 | + timegraph = model.Timeseries(CsvStock(some_file_path, "ColumnOfInterest").from_csv())\ |
4 | 7 |
|
5 | | - stream = TimeseriesArrayStream([2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) |
6 | | - timeseries = Timeseries(stream) |
7 | | - g = timeseries.to_graph(NaturalVisibilityGraphStrategy()) |
8 | | - sequence = g.to_sequence(RandomWalkSequenceGenerationStrategy(), sequence_length=500) |
| 8 | + # and preprocess the timeseries with multiple preprocessing strategies |
| 9 | + .with_preprocessing(model.TimeseriesPreprocessingComposite()\ |
| 10 | + .add_strategy(model.TimeseriesPreprocessingSegmentation(60, 120))\ |
| 11 | + .add_strategy(model.TimeseriesPreprocessingSlidingWindow(5)))\ |
9 | 12 |
|
10 | | -For a more detailed example, look at the [Amazon stocks demo](https://github.com/graph-massivizer/ts2g2/blob/main/tutorials/demo-amazon-stocks.ipynb). |
| 13 | + # then create a graph from the timeseries, following a particular strategy |
| 14 | + .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
| 15 | + |
| 16 | + # link graphs that result from the same timeseries, but at different sliding window frames |
| 17 | + .link(mgl.LinkGraphs().sliding_window())\ |
| 18 | + |
| 19 | + # and combine identical graphs that result from the abovementioned time windows into single nodes |
| 20 | + .combine_identical_nodes_slid_win()\ |
| 21 | + |
| 22 | + # finally, draw the graph |
| 23 | + .draw("red") |
| 24 | + |
| 25 | +For a more detailed example, look at the [Amazon stocks demo](https://github.com/graph-massivizer/ts2g2/blob/main/tutorials/demo-ts2g2.ipynb). |
11 | 26 |
|
12 | 27 | 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. |
13 | 28 |
|
@@ -41,72 +56,52 @@ The package is a joint effort between the [Jožef Stefan Institute](https://www. |
41 | 56 | <tr> |
42 | 57 | <td class="tg-7btt">1</td> |
43 | 58 | <td class="tg-0pky">Natural Visibility Graph</td> |
44 | | - <td class="tg-0pky"> |
45 | | - X |
46 | | - </td> |
47 | | - <td class="tg-0pky"> |
48 | | - <!-- directed --> |
49 | | - X |
50 | | - </td> |
51 | | - <td class="tg-0pky"> |
52 | | - <!-- weighted --> |
53 | | - X |
54 | | - </td> |
55 | | - <td class="tg-0pky"> |
56 | | - <!-- constraints:references: penetration --> |
57 | | - X |
58 | | - </td> |
59 | | - <td class="tg-0pky"> |
60 | | - <!-- constraints:references: angle --> |
61 | | - X |
62 | | - </td> |
| 59 | + <td class="tg-0pky">X</td> |
| 60 | + <td class="tg-0pky">X</td> |
| 61 | + <td class="tg-0pky">X</td> |
| 62 | + <td class="tg-0pky">X</td> |
| 63 | + <td class="tg-0pky">X</td> |
63 | 64 | </tr> |
64 | 65 | <tr> |
65 | 66 | <td class="tg-7btt">2</td> |
66 | 67 | <td class="tg-0pky">Horizontal Visibility Graph</td> |
67 | | - <td class="tg-0pky"> |
68 | | - X |
69 | | - </td> |
70 | | - <td class="tg-0pky"> |
71 | | - <!-- directed --> |
72 | | - X |
73 | | - </td> |
74 | | - <td class="tg-0pky"> |
75 | | - <!-- weighted --> |
76 | | - X |
77 | | - </td> |
78 | | - <td class="tg-0pky"> |
79 | | - <!-- constraints:references: penetration --> |
80 | | - X |
81 | | - </td> |
82 | | - <td class="tg-0pky"> |
83 | | - <!-- constraints:references: angle --> |
84 | | - X |
85 | | - </td> |
| 68 | + <td class="tg-0pky">X</td> |
| 69 | + <td class="tg-0pky">X</td> |
| 70 | + <td class="tg-0pky">X</td> |
| 71 | + <td class="tg-0pky">X</td> |
| 72 | + <td class="tg-0pky">X</td> |
86 | 73 | </tr> |
87 | 74 | <tr> |
88 | 75 | <td class="tg-7btt">3</td> |
89 | 76 | <td class="tg-0pky">Difference Visibility Graph</td> |
90 | | - <td class="tg-0pky"> |
91 | | - <!-- undirected --> |
92 | | - </td> |
93 | | - <td class="tg-0pky"> |
94 | | - <!-- directed --> |
95 | | - </td> |
96 | | - <td class="tg-0pky"> |
97 | | - <!-- weighted --> |
98 | | - </td> |
99 | | - <td class="tg-0pky"> |
100 | | - <!-- constraints:references: penetration --> |
101 | | - </td> |
102 | | - <td class="tg-0pky"> |
103 | | - <!-- constraints:references: angle --> |
104 | | - </td> |
| 77 | + <td class="tg-0pky"></td> |
| 78 | + <td class="tg-0pky"></td> |
| 79 | + <td class="tg-0pky"></td> |
| 80 | + <td class="tg-0pky"></td> |
| 81 | + <td class="tg-0pky"></td> |
| 82 | + </tr> |
| 83 | + <tr> |
| 84 | + <td class="tg-7btt">4</td> |
| 85 | + <td class="tg-0pky">Quantile Graph</td> |
| 86 | + <td class="tg-0pky"></td> |
| 87 | + <td class="tg-0pky">X</td> |
| 88 | + <td class="tg-0pky">X</td> |
| 89 | + <td class="tg-0pky"></td> |
| 90 | + <td class="tg-0pky"></td> |
| 91 | + </tr> |
| 92 | + |
| 93 | + <tr> |
| 94 | + <td class="tg-7btt">5</td> |
| 95 | + <td class="tg-0pky">Ordinal Partition Graph</td> |
| 96 | + <td class="tg-0pky"></td> |
| 97 | + <td class="tg-0pky">X</td> |
| 98 | + <td class="tg-0pky">X</td> |
| 99 | + <td class="tg-0pky"></td> |
| 100 | + <td class="tg-0pky"></td> |
105 | 101 | </tr> |
106 | 102 | </tbody> |
107 | 103 | </table> |
108 | 104 |
|
109 | | - |
110 | 105 | #### References table |
111 | 106 |
|
112 | 107 | <table class="tg"> |
@@ -193,22 +188,65 @@ The package is a joint effort between the [Jožef Stefan Institute](https://www. |
193 | 188 | <!-- constraints:references: angle --> |
194 | 189 | </td> |
195 | 190 | </tr> |
| 191 | +<tr> |
| 192 | + <td class="tg-7btt">4</td> |
| 193 | + <td class="tg-0pky">Quantile Graph</td> |
| 194 | + <td class="tg-0pky"> |
| 195 | + </a> |
| 196 | + </td> |
| 197 | + <td class="tg-0pky"> |
| 198 | + <!-- directed --> |
| 199 | + <a href="https://www.researchgate.net/figure/Illustrative-example-of-the-quantile-graph-algorithm-for-Q-4-On-the-left-panel-we_fig8_349721222">ref</a> |
| 200 | + </td> |
| 201 | + <td class="tg-0pky"> |
| 202 | + <!-- weighted --> |
| 203 | + </td> |
| 204 | + <td class="tg-0pky"> |
| 205 | + <!-- constraints:references: penetration --> |
| 206 | + </a> |
| 207 | + </td> |
| 208 | + <td class="tg-0pky"> |
| 209 | + <!-- constraints:references: angle --> |
| 210 | + </a> |
| 211 | + </td> |
| 212 | + </tr><tr> |
| 213 | + <td class="tg-7btt">5</td> |
| 214 | + <td class="tg-0pky">Ordinal Partition Graph</td> |
| 215 | + <td class="tg-0pky"> |
| 216 | + </a> |
| 217 | + </td> |
| 218 | + <td class="tg-0pky"> |
| 219 | + <!-- directed --> |
| 220 | + </a> |
| 221 | + </td> |
| 222 | + <td class="tg-0pky"> |
| 223 | + <!-- weighted --> |
| 224 | + </td> |
| 225 | + <td class="tg-0pky"> |
| 226 | + <!-- constraints:references: penetration --> |
| 227 | + </a> |
| 228 | + </td> |
| 229 | + <td class="tg-0pky"> |
| 230 | + <!-- constraints:references: angle --> |
| 231 | + </a> |
| 232 | + </td> |
| 233 | + </tr> |
196 | 234 | </tbody> |
197 | 235 | </table> |
198 | 236 |
|
199 | 237 |
|
200 | 238 |
|
201 | 239 | ### Graphs to timeseries conversion |
202 | 240 |
|
203 | | -Graphs are converted back to timeseries by sampling node values from the graph following different strategies. The following strategies have been implemented so far: |
| 241 | +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. |
204 | 242 |
|
205 | | - - random node |
206 | | - - random node neighbour |
207 | | - - random node degree |
208 | | - - random walk |
209 | | - - random walk with restart |
210 | | - - random walk with jump |
| 243 | + timegraph.to_sequence(model.ToSequenceVisitorSlidingWindow()\ |
| 244 | + .next_node_strategy(tts.StrategySelectNextNodeRandomlyFromFirstGraph())\ |
| 245 | + .next_value_strategy(tts.StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\ |
| 246 | + .ts_length(50))\ |
| 247 | + .draw_sequence() |
211 | 248 |
|
| 249 | +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. |
212 | 250 |
|
213 | 251 | ## Publications |
214 | 252 |
|
|
0 commit comments