Tuto test¶
>>> import networkx as nx
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import pandas as pd
>>>
>>> from phasik.classes import TemporalNetwork
Title¶
Test text
>>> # generate static network
>>> N = 4
>>> p = 0.7
>>> static_network = nx.erdos_renyi_graph(N, p)
>>>
>>> N_edges = static_network.number_of_edges()
>>>
>>> # relabel nodes with strings
>>> node_labels = ['a', 'b', 'c', 'd']
>>> mapping = {i : x for i,x in enumerate(node_labels)}
>>> static_network = nx.relabel_nodes(static_network, mapping)
>>>
>>> nx.draw_networkx(static_network)
>>> plt.show()
>>> # def str_name(name) :
>>> # return '-'.join(name)
>>>
>>> # edges_labels = [str_name(edge) for edge in static_network.edges()]
>>> T = 10
>>> node_series = np.random.random((T, N))
>>> node_table = pd.DataFrame(node_series, columns=node_labels)
>>> node_table
a | b | c | d | |
---|---|---|---|---|
0 | 0.541966 | 0.823289 | 0.234176 | 0.146126 |
1 | 0.127284 | 0.304599 | 0.541704 | 0.603139 |
2 | 0.793611 | 0.923618 | 0.211838 | 0.523801 |
3 | 0.817821 | 0.346724 | 0.574949 | 0.921824 |
4 | 0.917800 | 0.182292 | 0.633973 | 0.991735 |
5 | 0.593825 | 0.246298 | 0.425232 | 0.668774 |
6 | 0.238783 | 0.191160 | 0.221105 | 0.287929 |
7 | 0.900313 | 0.945168 | 0.070468 | 0.284179 |
8 | 0.161511 | 0.577583 | 0.410588 | 0.288009 |
9 | 0.672275 | 0.104990 | 0.357841 | 0.538351 |
>>> node_table.plot()
>>> plt.xlabel("Time")
>>> plt.ylabel("Edge time series")
>>>
>>> plt.show()
>>> temporal_network = TemporalNetwork.from_static_network_and_node_table_dataframe(
... static_network=static_network,
... node_table=node_table,
... combine_node_weights=lambda x, y: x*y)
The following edges were not found in the static network (20 edges):
[('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd'), ('a', 'b'), ('c', 'd')]
>>> temporal_network.info()
'4 nodes, 4 edges (of which 4 temporal), over 10 time points.'
>>> # %matplotlib
>>> anim = temporal_network.animate_highlight_temporal(filepath="video.mp4", fps=1)
Using matplotlib backend: Qt5Agg