def _get_normalizing_constant(xi, max_children=10000):
    """
    Calculates the sum of xi[0,1,...,max_children]. This can be used to convert weights into probability.
    :param xi: List or lambda function such that xi[i] / sum(xi[0,...,max_children]) is the probability of a node
    getting i children.
    :param max_children: Maximum number of children a node can have. This parameter is ignored if xi is not callable.
    :return: Sum of xi[0,1,...,len(xi)-1] or sum of xi(0,1,...,max_children) if xi is callable.
    """
    if callable(xi):
        if xi(0) <= 0:
            raise ValueError('The probability of getting 0 children must be positive.')
        return sum([xi(i) for i in range(max_children+1)])

    if xi[0] <= 0:
        raise ValueError('The probability of getting 0 children must be positive.')
    return sum(xi)