def rho_heatmaps(N, F0, lambdaF_list, eta_list, rep, outDeg=20, power=-2.5, M=10, tol=0.0005, window_size=0, t_max=0): """Generates data for the density heatmap.""" blockPrint() g = ig.Graph.Barabasi(N, outDeg, power=power) # generate the BA graph g.simplify() g.delete_vertices(g.vs.select(lambda vertex: vertex.degree() == 0)) N = len(g.vs) E = len(g.es) final_polarised = {} final_rhoF = {} final_FT_edges = {} for lambda_F in lambdaF_list: for eta in eta_list: avg_pol = 0 avg_rhoF = 0 avg_FT = 0 for i in range(rep): v_polarised, rhoF, nFT_edges = newsFlow( g=g, F0=F0, eta=eta, lambda_F=lambda_F, M=M, t_max=t_max, window_size=window_size, tol=tol, sfreq=-1) avg_pol += (v_polarised / N) avg_rhoF += (rhoF / N) avg_FT += (nFT_edges / E) avg_pol /= rep avg_rhoF /= rep avg_FT /= rep final_polarised[(lambda_F, eta)] = avg_pol final_rhoF[(lambda_F, eta)] = avg_rhoF final_FT_edges[(lambda_F, eta)] = avg_FT return final_polarised, final_rhoF, final_FT_edges
def plot_newsFlow(N, F0, eta, lambda_F, outDeg=20, power=-2.5, M=10, tol=0.0005, window_size=0, t_max=0): """Visualises the simulation data.""" g = ig.Graph.Barabasi(N, outDeg, power=power) # generate the BA graph g.simplify() g.delete_vertices(g.vs.select(lambda vertex: vertex.degree() == 0)) N = len(g.vs) E = len(g.es) time_range, list_polarised, list_rhoF, list_FT_edges = newsFlow( g=g, F0=F0, eta=eta, lambda_F=lambda_F, M=M, t_max=t_max, window_size=window_size, tol=tol, sfreq=0) _ = plt.tight_layout() _ = plt.figure(figsize=(8, 8)) _ = plt.suptitle( r'$N =$ %s, $F_0 =$ %s, $M =$ %s, $\eta =$ %s, $\lambda_F =$ %s' % (N, F0, 2 * M, eta, lambda_F), y=1.01) _ = plt.tight_layout() _ = sub_plot(1, time_range, [i / N for i in list_polarised], r'$\rho^P(t)$') _ = plt.ylim((0, 1)) _ = sub_plot(2, time_range, [i / N for i in list_rhoF], r'$\rho^F(t)$') _ = plt.ylim((0, 1)) _ = sub_plot(3, time_range, [i / E for i in list_FT_edges], r'$\rho^{FT}(t)$') _ = plt.ylim((0, 1)) _ = sub_plot(4, time_range, range(len(time_range)), 'Iterations') _ = plt.show()
def time_evolution_lambda_F_eta(N, F0, list_lambdaF, list_eta, outDeg=20, power=-2.5, M=10, tol=0.0005, window_size=0, t_max=0): """Generates data for the time evolution in dependence on lambda_F and eta.""" blockPrint() g = ig.Graph.Barabasi(N, outDeg, power=power) # generate the BA graph g.simplify() g.delete_vertices(g.vs.select(lambda vertex: vertex.degree() == 0)) N = len(g.vs) E = len(g.es) results_times = {} results_polarised = {} results_rhoF = {} results_FT_edges = {} for lambda_F in list_lambdaF: for eta in list_eta: time_range, list_polarised, list_rhoF, list_FT_edges = newsFlow( g=g, F0=F0, eta=eta, lambda_F=lambda_F, M=M, t_max=t_max, window_size=window_size, tol=tol, sfreq=0) results_times[(lambda_F, eta)] = time_range results_polarised[(lambda_F, eta)] = [i / N for i in list_polarised] results_rhoF[(lambda_F, eta)] = [i / N for i in list_rhoF] results_FT_edges[(lambda_F, eta)] = [i / E for i in list_FT_edges] return results_times, results_rhoF, results_FT_edges, results_polarised
def get_media_subscriptions(N, lambda_F, eta, sfreq, rhoF0=0.5, outDeg=20, power=-2.5, M=10, tol=0.0005, window_size=0, t_max=0): """Generates media-reach statistics.""" blockPrint() g = ig.Graph.Barabasi(N, outDeg, power=power) # generate the BA graph g.simplify() g.delete_vertices(g.vs.select(lambda vertex: vertex.degree() == 0)) N = len(g.vs) F0 = int(N * rhoF0) list_rhoF, T_Fmedia, F_Fmedia, T_Tmedia, F_Tmedia, Tmedia_T, Tmedia_F, Fmedia_T, Fmedia_F = newsFlow( g=g, F0=F0, eta=eta, lambda_F=lambda_F, M=M, t_max=t_max, window_size=window_size, tol=tol, sfreq=sfreq) df = pd.DataFrame(columns=['t_step', 'type', '#F_subscribers' ]) # store the results as a dataframe for t_step in Tmedia_T.keys(): TF = Tmedia_F[t_step] TT = Tmedia_T[t_step] temp = pd.DataFrame({ 't_step': [round(t_step) for i in range(len(TF))], 'type': [True for i in range(len(TF))], '#F_subscribers': [TF[i] / (TF[i] + TT[i]) for i in range(len(TF))] }) df = pd.concat([df, temp]) for t_step in Fmedia_F.keys(): FF = Fmedia_F[t_step] FT = Fmedia_T[t_step] temp = pd.DataFrame({ 't_step': [round(t_step) for i in range(len(FF))], 'type': [False for i in range(len(FF))], '#F_subscribers': [FF[i] / (FF[i] + FT[i]) for i in range(len(FF))] }) df = pd.concat([df, temp]) df['#F_subscribers'] = df['#F_subscribers'].astype(float) return df, lambda_F, eta, Tmedia_T, Tmedia_F, Fmedia_T, Fmedia_F, M, N, list_rhoF
def rho_eta(list_N, list_rhoF0, rep, list_eta, lambda_F=1, outDeg=20, power=-2.5, M=10, tol=0.0005, window_size=0, t_max=0): """Generates data for the evolution of the densities in dependence on eta.""" blockPrint() final_rhoF_eta = {} final_rhoFT_eta = {} final_rhoP_eta = {} for N in list_N: g = ig.Graph.Barabasi(N, outDeg, power=power) # generate the BA graph g.simplify() g.delete_vertices(g.vs.select(lambda vertex: vertex.degree() == 0)) N = len(g.vs) E = len(g.es) for rhoF0 in list_rhoF0: F0 = int(N * rhoF0) final_rhoF_eta[(N, rhoF0)] = {} final_rhoFT_eta[(N, rhoF0)] = {} final_rhoP_eta[(N, rhoF0)] = {} for eta in list_eta: avg_rhoF = 0 avg_FT = 0 avg_pol = 0 for i in range(rep): v_polarised, rhoF, nFT_edges = newsFlow( g=g, F0=F0, eta=eta, lambda_F=lambda_F, M=M, t_max=t_max, window_size=window_size, tol=tol, sfreq=-1) avg_rhoF += rhoF / N avg_FT += nFT_edges / E avg_pol += v_polarised / N avg_rhoF /= rep avg_FT /= rep avg_pol /= rep final_rhoF_eta[(N, rhoF0)][eta] = avg_rhoF final_rhoFT_eta[(N, rhoF0)][eta] = avg_FT final_rhoP_eta[(N, rhoF0)][eta] = avg_pol return final_rhoF_eta, final_rhoFT_eta, final_rhoP_eta, lambda_F