Beispiel #1
0
def ex_1():
    '''Example 1 of the paper.

    A 2-by-20 grid with reflecting boundary condition and an obstacle in the
    middle.
    '''
    N = 20
    G = nx.grid_2d_graph(N,N)

    n_middle = (N/2, N/2)

    # Add reflecting boundary condition
    for i,j in G:
        if i == 0 or i == N-1 or j == 0 or j == N-1:
            G.add_edge((i,j), (i,j))
    
    # Remove edges of the node at the middle
    # (keep one edge, to simplify the bookiping
    for u,v in sorted(G.edges(n_middle))[:-1]:
        G.add_edge(v,v) # Add self loop
        G.remove_edge(u, v)

    T, _ = get_T(G)
    savemat('vf_ex1', {'T':T}, oned_as='column')
    return G
Beispiel #2
0
def circle(N):
    G = nx.cycle_graph(N)
    T, L = get_T(G)

    fn = 'T_circle_%d.mat' % N
    savemat(fn, {'T':T, 'L':L}, oned_as='column')
    print 'T saved as %s' % fn

    # Add self loops to all nodes
    for node in G.nodes():
        G.add_edge(node, node)

    T_loop, L_loop = get_T(G)

    fn = 'T_circle_selfloop_%d.mat' % N
    savemat(fn, {'T':T_loop, 'L':L_loop}, oned_as='column')
    print 'T saved as %s' % fn

    return T, L, T_loop, L_loop
Beispiel #3
0
def circle(N):
    G = nx.cycle_graph(N)
    T, L = get_T(G)

    fn = 'T_circle_%d.mat' % N
    savemat(fn, {'T': T, 'L': L}, oned_as='column')
    print 'T saved as %s' % fn

    # Add self loops to all nodes
    for node in G.nodes():
        G.add_edge(node, node)

    T_loop, L_loop = get_T(G)

    fn = 'T_circle_selfloop_%d.mat' % N
    savemat(fn, {'T': T_loop, 'L': L_loop}, oned_as='column')
    print 'T saved as %s' % fn

    return T, L, T_loop, L_loop
Beispiel #4
0
def make_T(N, add_selfloops=False):
    '''Compute the diffusion operator of an N-by-N grid graph.

    The difussion operator is defined as

    T = D^0.5 * P * D^-0.5, where D is the degree matrix, P=D^-1W is the random
    walk matrix, and W is the adjancency matrix.
    '''
    G = nx.grid_2d_graph(N,N)
    if add_selfloops:
        for n in G:
            G.add_edge(n, n)
            
    T, _ = get_T(G)
    L = nx.laplacian(G, nodelist=sorted(G.nodes()))
    
    return T, L
Beispiel #5
0
def make_T(N, add_selfloops=False):
    '''Compute the diffusion operator of an N-by-N grid graph.

    The difussion operator is defined as

    T = D^0.5 * P * D^-0.5, where D is the degree matrix, P=D^-1W is the random
    walk matrix, and W is the adjancency matrix.
    '''
    G = nx.grid_2d_graph(N, N)
    if add_selfloops:
        for n in G:
            G.add_edge(n, n)

    T, _ = get_T(G)
    L = nx.laplacian(G, nodelist=sorted(G.nodes()))

    return T, L