def hist_from_cascade( transition_probs, start_nodes, stop_nodes=[], allow_loops=False, n_init=100, simultaneous=True, max_hops=10, ): dispatcher = TraverseDispatcher( Cascade, transition_probs, allow_loops=allow_loops, n_init=n_init, max_hops=max_hops, stop_nodes=stop_nodes, ) if simultaneous: hop_hist = dispatcher.start(start_nodes) else: n_verts = len(transition_probs) hop_hist = np.zeros((n_verts, max_hops)) for s in start_nodes: hop_hist += dispatcher.start(s) return hop_hist
matrixplot(A, row_sort_class=labels, col_sort_class=labels, cbar=False) stashfig("sbm") # %% [markdown] # ## p = 0.05 max_hops = 10 n_init = 100 simultaneous = True transition_probs = to_transmission_matrix(A, p) start_nodes = np.arange(n_feedforward) cdispatch = TraverseDispatcher( Cascade, transition_probs, allow_loops=False, n_init=n_init, simultaneous=simultaneous, ) hit_hist = cdispatch.multistart(start_nodes) fig, axs = plt.subplots(3, 1, figsize=(10, 10), gridspec_kw=dict(height_ratios=[0.45, 0.45, 0.1])) ax = axs[0] matrixplot(hit_hist.T, ax=ax, col_sort_class=labels, cbar=True) ax.set_xlabel("Block") ax.set_yticks(np.arange(1, max_hops + 1) - 0.5) ax.set_yticklabels(np.arange(1, max_hops + 1)) ax.set_ylabel("Hops")
np.random.seed(888) max_hops = 10 n_init = 100 p = 0.05 traverse = Cascade simultaneous = True transition_probs = to_transmission_matrix(adj, p) source_inds = meta[meta[class_key].isin(sg)]["inds"].values out_inds = meta[meta[class_key].isin(og)]["inds"].values td = TraverseDispatcher( traverse, transition_probs, n_init=n_init, simultaneous=simultaneous, stop_nodes=out_inds, max_hops=max_hops, allow_loops=False, ) fwd_hop_hist = td.multistart(source_inds) fwd_hop_hist = fwd_hop_hist.T # backward cascade td = TraverseDispatcher( traverse, transition_probs.T, n_init=n_init, simultaneous=simultaneous, stop_nodes=source_inds, max_hops=max_hops,
matrixplot(post, ax=ax, col_sort_class=labels) # %% [markdown] # ## max_hops = 10 n_init = 100 # random walk transition_probs = to_markov_matrix(adj) # row normalize! traverse = RandomWalk simultaneous = False td = TraverseDispatcher( traverse, transition_probs, n_init=n_init, simultaneous=simultaneous, stop_nodes=np.arange(n_feedforward * (n_blocks - 1), n_feedforward * (n_blocks)), max_hops=max_hops, allow_loops=False, ) rw_hop_hist = td.multistart(np.arange(n_feedforward)) rw_hop_hist = rw_hop_hist.T fig, ax = plt.subplots(1, 1, figsize=(10, 5)) matrixplot(rw_hop_hist, ax=ax, col_sort_class=labels) # forward cascade traverse = Cascade simultaneous = True td = TraverseDispatcher( traverse, transition_probs,