def calc_Br(Y, A_r, beta, in_edges_r, neg_edges_r):
    """ Calculates a new bias vector for a single edge type according to Eq 4.

    Parameters
    ----------
    Y           : np.array, entity embeddings
    A_r         : np.array, linear mapping for this edge type
    beta        : func from in_edges.keys() to float
    in_edges_r  : dict of incoming edges for this edge type
    neg_edges_r : dict of incoming non-edges for this edge type

    Returns
    -------
    np.array
    """
    num = 0.
    denom = 0.
    for i, neighbors in in_edges_r.items():
        for j in neighbors:
            num += beta(i, j)*(A_r.dot(Y[j]) - Y[i])
            denom += beta(i, j)

    for i, neighbors in neg_edges_r.items():
        for j in neighbors:
            num -= beta(i, j)*(A_r.dot(Y[j]) - Y[i])
            denom -= beta(i, j)

    return num / denom