Tuto testΒΆ
>>> import matplotlib.pyplot as plt
>>> import networkx as nx
>>> import numpy as np
>>> import pandas as pd
>>>
>>> import phasik as pk
>>> # generate static network
>>> edges = [('a', 'b'), ('a', 'c'), ('b', 'c'), ('a', 'd')]
>>>
>>> static_network = nx.Graph(edges)
>>>
>>> nodes = list(static_network.nodes)
>>> N = static_network.number_of_nodes()
>>>
>>> nx.draw_networkx(static_network)
>>> plt.show()
>>> # generate node time series
>>> T = 10 # number of timepoints
>>> node_series_arr = np.random.random((N, T))
>>>
>>> node_series = pd.DataFrame(node_series_arr, index=nodes) #
>>> node_series
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
|---|---|---|---|---|---|---|---|---|---|---|
| a | 0.401917 | 0.881092 | 0.127991 | 0.912639 | 0.661475 | 0.555443 | 0.256126 | 0.727078 | 0.248045 | 0.015757 |
| b | 0.852820 | 0.936582 | 0.988778 | 0.107239 | 0.126230 | 0.250864 | 0.463638 | 0.491446 | 0.369278 | 0.982625 |
| c | 0.012937 | 0.909779 | 0.865591 | 0.049600 | 0.566255 | 0.119082 | 0.581458 | 0.970764 | 0.809731 | 0.236107 |
| d | 0.655355 | 0.173176 | 0.325639 | 0.097256 | 0.452466 | 0.646218 | 0.821179 | 0.192487 | 0.783225 | 0.798528 |
>>> node_series.T.plot()
>>> plt.xlabel("Time")
>>> plt.ylabel("Edge time series")
>>>
>>> plt.show()
>>> # create the temporal network by combining
>>> # the static network with the node timeseries
>>> temporal_network = pk.TemporalNetwork.from_static_network_and_node_timeseries(
... static_network,
... node_series,
... static_edge_default_weight=1,
... normalise='minmax', # method to normalise the edge weights
... )
>>> print(temporal_network)
<class 'phasik.classes.TemporalNetwork.TemporalNetwork'> with 4 nodes and 10 times