|
3 | 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 | 4 |
|
5 | 5 | # load time series from a file |
6 | | - timegraph = model.Timeseries(CsvStock(some_file_path, "ColumnOfInterest").from_csv())\ |
| 6 | + timegraph = Timeseries(CsvFile(amazon_path, "Close").from_csv())\ |
7 | 7 |
|
8 | 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 | + .with_preprocessing(TimeseriesPreprocessingComposite()\ |
| 10 | + .add(TimeseriesPreprocessingSegmentation(60, 120))\ |
| 11 | + .add(TimeseriesPreprocessingSlidingWindow(5)))\ |
12 | 12 |
|
13 | 13 | # then create a graph from the timeseries, following a particular strategy |
14 | | - .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
| 14 | + .to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
15 | 15 |
|
16 | 16 | # link graphs that result from the same timeseries, but at different sliding window frames |
17 | | - .link(mgl.LinkGraphs().sliding_window())\ |
| 17 | + .link(LinkGraphs().sliding_window())\ |
18 | 18 |
|
19 | 19 | # and combine identical graphs that result from the abovementioned time windows into single nodes |
20 | | - .combine_identical_nodes_slid_win()\ |
| 20 | + .combine_identical_subgraphs()\ |
21 | 21 |
|
22 | 22 | # finally, draw the graph |
23 | | - .draw("red") |
| 23 | + .draw("blue") |
24 | 24 |
|
25 | 25 | For a more detailed example, look at the [Amazon stocks demo](https://github.com/graph-massivizer/ts2g2/blob/main/tutorials/demo-ts2g2.ipynb). |
26 | 26 |
|
@@ -240,9 +240,9 @@ The package is a joint effort between the [Jožef Stefan Institute](https://www. |
240 | 240 |
|
241 | 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. |
242 | 242 |
|
243 | | - timegraph.to_sequence(model.ToSequenceVisitorSlidingWindow()\ |
244 | | - .next_node_strategy(tts.StrategySelectNextNodeRandomlyFromFirstGraph())\ |
245 | | - .next_value_strategy(tts.StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\ |
| 243 | + timegraph.to_sequence(ToSequenceVisitorSlidingWindow()\ |
| 244 | + .next_node_strategy(StrategySelectNextNodeRandomlyFromFirstGraph())\ |
| 245 | + .next_value_strategy(StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\ |
246 | 246 | .ts_length(50))\ |
247 | 247 | .draw_sequence() |
248 | 248 |
|
|
0 commit comments