import torch


def getGraphTransition(adjacency, self_loop=True):
    """Compute random walker transition in the given graph"""
    N = len(adjacency)
    if self_loop:
        adjacency = adjacency + torch.eye(N)
    degree = 1 / adjacency.sum(1).reshape(-1, 1) # for normalization
    transition = (adjacency * degree).T # (N, N)
    return transition