def nx_graph_nbrw(G): import networkx as nx A = nx.to_scipy_sparse_matrix(G) P = mkm.graph_nbrw_transition_matrix(A) mc = mkm.MarkovChain(P) mc.set_stationary_distribution(mkm.uniform_distribution(mc.get_n())) return mc
def nx_graph_nbrw(G): """Returns the Markov chain for the NBRW on the graph G. """ import networkx as nx A = nx.to_scipy_sparse_matrix(G) P = mkm.graph_nbrw_transition_matrix(A) mc = mkm.MarkovChain(P) mc.set_stationary(mkm.uniform_distribution(mc.get_n())) return mc
import matplotlib.pyplot as plt # load a 6-regular graph with 50.000 nodes from file G_6_regular = nx.read_sparse6('6_regular.s6') # get the adjacency matrix A = nx.to_scipy_sparse_matrix(G_6_regular) # transition matrix for NBRW on the graph from the adjacency matrix P = mkm.graph_nbrw_transition_matrix(A) # Markov chain with the transition marix mc = mkm.MarkovChain(P) # the stationary distribution is uniform mc.set_stationary(mkm.uniform_distribution(mc.get_n())) # add a random starting position to the Markov chain mc.add_random_delta_distributions(1) # determine the mixing mc.compute_tv_mixing() # plot the mixing (x,tv) = mc.distribution_tv_mixing(0) plt.plot(x, tv, marker='o', linestyle='dashed') plt.title("Mixing of NBRW on a 6-regular graph") plt.xlabel("t") plt.ylabel("Toal variation distance to stationarity") plt.show()