def final_results(): for day in days: path = 'Data/Preprocessed/preprocessed_' + day graph = dn.read_snapshots(path, nodetype=int, timestamptype=int) d = Day(graph) i_total = np.empty((alpha.shape[0], n)) # alpha x simulations i_total = d.simulate(alpha, n, final_plot=False) with open('Data/Simulations/final_' + day + '.pkl', 'wb') as output: pickle.dump(i_total, output, pickle.HIGHEST_PROTOCOL) print('finished', n, 'simulations for day', day)
def preprocess(windows): data = {} for filename in os.listdir('Data/Preprocessed'): if 'preprocessed_0' in filename: g = dn.read_snapshots(str('Data/Preprocessed/' + filename), nodetype=int, timestamptype=int) day = filename[13:18] print(day) data[day] = burstiness_window(g, windows) with open('Data/Preprocessed_bursts.txt', 'w') as outfile: json.dump(data, outfile)
def test_snapshot_graph_flag(self): g = dn.DynGraph() g.add_interaction(1, 2, 2) g.add_interaction(1, 2, 2, e=6) g.add_interaction(1, 2, 7, e=11) g.add_interaction(1, 2, 8, e=15) g.add_interaction(1, 2, 18) g.add_interaction(1, 2, 19) dn.write_snapshots(g, "test4.txt", delimiter=" ") h = dn.read_snapshots("test4.txt", nodetype=int, timestamptype=int, keys=True) # self.assertEqual(list(g.stream_interactions()), list(h.stream_interactions())) self.assertEqual(g.number_of_interactions(), h.number_of_interactions()) os.remove("test4.txt")
def load_graphs(dir='Data/Preprocessed/'): """ Construct dictionary containing results of may indexed by the day month (e.g. 05-09) """ all_days = {} for filename in os.listdir(dir): if 'preprocessed_' in filename: path = dir + filename all_days[filename[13:]] = dn.read_snapshots(path, nodetype=int, timestamptype=int) print("Loaded", len(all_days), "days.") return all_days
def read_graph(day): path = "Data/Preprocessed/preprocessed_" + day graph = dn.read_snapshots(path, nodetype=int, timestamptype=int) return graph
'node_size': 1, 'line_color': 'red', 'linewidths': 0, 'width': 0.1, } nx.draw_circular(G, **options) plt.show() G=nx.read_edgelist("/Users/jennie/Documents/analytics/xanax/xanshort.csv", delimiter=",") import networkx as nx import dynetx as dn import matplotlib.pyplot as plt g = dn.DynGraph(edge_removal=False) g = dn.read_snapshots("/Users/jennie/Documents/analytics/xanax/lyrics_ngrams.txt", timestamptype=int) pos=nx.spring_layout(g,scale=20) # double distance between all nodes plt.figure(3,figsize=(10,10)) nx.draw(g,pos,node_size=10, font_size=8, with_labels=True) list(g.stream_interactions()) import networkx as nx import ndlib.models.ModelConfig as mc import ndlib.models.opinions.AlgorithmicBiasModel as ab # Network topology g=nx.read_edgelist("/Users/jennie/Documents/analytics/xanax/lyrics_ngram.csv", delimiter=",")