|
4 | 4 | if nb_dir not in sys.path: |
5 | 5 | sys.path.append(nb_dir) |
6 | 6 |
|
7 | | -from core import model |
| 7 | +from core.model import Timeseries, TimeseriesPreprocessing, TimeseriesPreprocessingSegmentation, TimeseriesPreprocessingSlidingWindow, TimeseriesPreprocessingComposite, TimeseriesView, TimeGraph, ToSequenceVisitorSlidingWindow, ToSequenceVisitor |
8 | 8 |
|
9 | | -from input_output import input as inp |
10 | | -import from_graph.strategy_to_time_sequence as tts |
11 | | -import to_graph.strategy_linking_graph as gls |
12 | | -import to_graph.strategy_linking_multi_graphs as mgl |
13 | | -import to_graph.strategy_to_graph as tgs |
| 9 | +from tsg_io.input import CsvFile |
| 10 | +from from_graph.strategy_to_time_sequence import StrategyNextValueInNodeRandom, StrategyNextValueInNodeRandomForSlidingWindow, StrategyNextValueInNodeRoundRobin, StrategyNextValueInNodeRoundRobinForSlidingWindow, StrategySelectNextNodeRandomlyFromNeighboursAcrossGraphs, StrategySelectNextNodeRandomlyFromNeighboursFromFirstGraph, StrategySelectNextNodeRandomly, StrategySelectNextNodeRandomDegree, StrategySelectNextNodeRandomWithRestart |
| 11 | +from to_graph.strategy_linking_graph import StrategyLinkingGraphByValueWithinRange, LinkNodesWithinGraph |
| 12 | +from to_graph.strategy_linking_multi_graphs import LinkGraphs |
| 13 | +from to_graph.strategy_to_graph import BuildTimeseriesToGraphNaturalVisibilityStrategy, BuildTimeseriesToGraphHorizontalVisibilityStrategy |
14 | 14 |
|
15 | 15 | amazon_path = os.path.join(os.getcwd(), "amazon", "AMZN.csv") |
16 | 16 | apple_path = os.path.join(os.getcwd(), "apple", "APPLE.csv") |
17 | 17 |
|
18 | 18 |
|
19 | | -test = model.Timeseries(inp.CsvStock(amazon_path, "Close").from_csv())\ |
20 | | - .with_preprocessing(model.TimeseriesPreprocessingSegmentation(60, 90))\ |
21 | | - .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().with_limit(1).get_strategy())\ |
| 19 | + |
| 20 | +timegraph_1 = Timeseries(CsvFile(amazon_path, "Close").from_csv())\ |
| 21 | + .with_preprocessing(TimeseriesPreprocessingSegmentation(60, 90))\ |
| 22 | + .to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().with_limit(1).get_strategy())\ |
22 | 23 | .add_edge(0,2)\ |
23 | 24 | .add_edge(13, 21, weight = 17)\ |
24 | | - .link(gls.LinkNodesWithinGraph().by_value(gls.StrategyLinkingGraphByValueWithinRange(2)).seasonalities(15))\ |
| 25 | + .link(LinkNodesWithinGraph().by_value(StrategyLinkingGraphByValueWithinRange(2)).seasonalities(15))\ |
25 | 26 | .draw("blue") |
26 | 27 |
|
27 | | - |
28 | | -x = model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
29 | | - .with_preprocessing(model.TimeseriesPreprocessingComposite()\ |
30 | | - .add_strategy(model.TimeseriesPreprocessingSegmentation(60, 120))\ |
31 | | - .add_strategy(model.TimeseriesPreprocessingSlidingWindow(5)))\ |
32 | | - .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
33 | | - .link(mgl.LinkGraphs().sliding_window())\ |
34 | | - .combine_identical_nodes_slid_win()\ |
| 28 | +timegraph_2 = Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 29 | + .with_preprocessing(TimeseriesPreprocessingComposite()\ |
| 30 | + .add(TimeseriesPreprocessingSegmentation(60, 120))\ |
| 31 | + .add(TimeseriesPreprocessingSlidingWindow(5)))\ |
| 32 | + .to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
| 33 | + .link(LinkGraphs().sliding_window())\ |
| 34 | + .combine_identical_subgraphs()\ |
35 | 35 | .draw("red") |
36 | 36 |
|
37 | | -i = model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
38 | | - .with_preprocessing(model.TimeseriesPreprocessingSegmentation(60, 90))\ |
39 | | - .add(model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
40 | | - .with_preprocessing(model.TimeseriesPreprocessingSegmentation(90, 120)))\ |
41 | | - .add(model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
42 | | - .with_preprocessing(model.TimeseriesPreprocessingSegmentation(150, 180)))\ |
43 | | - .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().with_limit(1).get_strategy())\ |
44 | | - .link(mgl.LinkGraphs().time_cooccurrence())\ |
45 | | - .link(gls.LinkNodesWithinGraph().by_value(gls.StrategyLinkingGraphByValueWithinRange(0.5)))\ |
| 37 | +timegraph_3 = Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 38 | + .with_preprocessing(TimeseriesPreprocessingSegmentation(60, 90))\ |
| 39 | + .add(Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 40 | + .with_preprocessing(TimeseriesPreprocessingSegmentation(90, 120)))\ |
| 41 | + .add(Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 42 | + .with_preprocessing(TimeseriesPreprocessingSegmentation(150, 180)))\ |
| 43 | + .to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().with_limit(1).get_strategy())\ |
| 44 | + .link(LinkGraphs().time_cooccurrence())\ |
| 45 | + .link(LinkNodesWithinGraph().by_value(StrategyLinkingGraphByValueWithinRange(0.5)))\ |
46 | 46 | .combine_identical_nodes()\ |
47 | 47 | .draw("brown") |
48 | 48 |
|
49 | | -j = model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
50 | | - .with_preprocessing(model.TimeseriesPreprocessingComposite()\ |
51 | | - .add_strategy(model.TimeseriesPreprocessingSegmentation(60, 110))\ |
52 | | - .add_strategy(model.TimeseriesPreprocessingSlidingWindow(5)))\ |
53 | | - .add(model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
54 | | - .with_preprocessing(model.TimeseriesPreprocessingComposite()\ |
55 | | - .add_strategy(model.TimeseriesPreprocessingSegmentation(120, 170))\ |
56 | | - .add_strategy(model.TimeseriesPreprocessingSlidingWindow(5)))\ |
57 | | - .add(model.Timeseries(inp.CsvStock(apple_path, "Close").from_csv())\ |
58 | | - .with_preprocessing(model.TimeseriesPreprocessingComposite()\ |
59 | | - .add_strategy(model.TimeseriesPreprocessingSegmentation(190, 240))\ |
60 | | - .add_strategy(model.TimeseriesPreprocessingSlidingWindow(5)))))\ |
61 | | - .to_graph(tgs.BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
62 | | - .link(mgl.LinkGraphs().sliding_window().time_cooccurrence())\ |
63 | | - .combine_identical_nodes_slid_win()\ |
64 | | - .link(gls.LinkNodesWithinGraph().seasonalities(15))\ |
| 49 | +timegraph_4 = Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 50 | + .with_preprocessing(TimeseriesPreprocessingComposite()\ |
| 51 | + .add(TimeseriesPreprocessingSegmentation(60, 110))\ |
| 52 | + .add(TimeseriesPreprocessingSlidingWindow(5)))\ |
| 53 | + .add(Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 54 | + .with_preprocessing(TimeseriesPreprocessingComposite()\ |
| 55 | + .add(TimeseriesPreprocessingSegmentation(120, 170))\ |
| 56 | + .add(TimeseriesPreprocessingSlidingWindow(5)))\ |
| 57 | + .add(Timeseries(CsvFile(apple_path, "Close").from_csv())\ |
| 58 | + .with_preprocessing(TimeseriesPreprocessingComposite()\ |
| 59 | + .add(TimeseriesPreprocessingSegmentation(190, 240))\ |
| 60 | + .add(TimeseriesPreprocessingSlidingWindow(5)))))\ |
| 61 | + .to_graph(BuildTimeseriesToGraphNaturalVisibilityStrategy().get_strategy())\ |
| 62 | + .link(LinkGraphs().sliding_window().time_cooccurrence())\ |
| 63 | + .combine_identical_subgraphs()\ |
| 64 | + .link(LinkNodesWithinGraph().seasonalities(15))\ |
65 | 65 | .draw("green") |
66 | 66 |
|
67 | 67 |
|
68 | | -test.to_sequence(model.ToSequenceVisitor()\ |
69 | | - .next_node_strategy(tts.StrategySelectNextNodeRandomlyAcrossGraphs())\ |
70 | | - .next_value_strategy(tts.StrategyNextValueInNodeRoundRobin().skip_every_x_steps(1))\ |
| 68 | +timegraph_1.to_sequence(ToSequenceVisitor()\ |
| 69 | + .next_node_strategy(StrategySelectNextNodeRandomWithRestart())\ |
| 70 | + .next_value_strategy(StrategyNextValueInNodeRoundRobin().skip_every_x_steps(1))\ |
71 | 71 | .ts_length(100))\ |
72 | 72 | .draw_sequence() |
73 | 73 |
|
74 | 74 |
|
75 | | -x.to_sequence(model.ToSequenceVisitorSlidingWindow()\ |
76 | | - .next_node_strategy(tts.StrategySelectNextNodeRandomlyFromFirstGraph())\ |
77 | | - .next_value_strategy(tts.StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\ |
| 75 | +timegraph_2.to_sequence(ToSequenceVisitorSlidingWindow()\ |
| 76 | + .next_node_strategy(StrategySelectNextNodeRandomly())\ |
| 77 | + .next_value_strategy(StrategyNextValueInNodeRandomForSlidingWindow().skip_every_x_steps(1))\ |
78 | 78 | .ts_length(50))\ |
79 | 79 | .draw_sequence() |
80 | 80 |
|
81 | 81 |
|
82 | | -i.to_sequence(model.ToSequenceVisitor()\ |
83 | | - .next_node_strategy(tts.StrategySelectNextNodeRandomlyAcrossGraphs().change_graphs_every_x_steps(2))\ |
84 | | - .next_value_strategy(tts.StrategyNextValueInNodeRoundRobin().skip_every_x_steps(1))\ |
| 82 | +timegraph_3.to_sequence(ToSequenceVisitor()\ |
| 83 | + .next_node_strategy(StrategySelectNextNodeRandomlyFromNeighboursAcrossGraphs().change_graphs_every_x_steps(2))\ |
| 84 | + .next_value_strategy(StrategyNextValueInNodeRoundRobin().skip_every_x_steps(1))\ |
85 | 85 | .ts_length(50))\ |
86 | 86 | .draw_sequence() |
87 | 87 |
|
88 | 88 |
|
89 | | -j.to_sequence(model.ToSequenceVisitorSlidingWindow()\ |
90 | | - .next_node_strategy(tts.StrategySelectNextNodeRandomlyFromFirstGraph())\ |
91 | | - .next_value_strategy(tts.StrategyNextValueInNodeRoundRobinForSlidingWindow())\ |
| 89 | +timegraph_4.to_sequence(ToSequenceVisitorSlidingWindow()\ |
| 90 | + .next_node_strategy(StrategySelectNextNodeRandomlyFromNeighboursAcrossGraphs())\ |
| 91 | + .next_value_strategy(StrategyNextValueInNodeRoundRobinForSlidingWindow())\ |
92 | 92 | .ts_length(100))\ |
93 | 93 | .draw_sequence() |
0 commit comments