def path_weight(alpha, A, omega, X, path):
    """
    Compute the weight of a path in the state graph corresponding to a word X
    """
    weight = alpha[path[0]]

    for i in range(1, path.shape[0]):
        p, q = path[i-1], path[i]
        weight *= A[p, X[i-1], q]

    weight *= omega[path[path.shape[0] - 1]]

    return weight