def inter_cluster_mean_score(cluster, graph, mean=None):
    """
    The method is based on the calculation of distances for each sample in a given cluster to
    the specific centroid of cluster. If the centroid is not given by specifying mean, it is
    calculated with the distance function that is provided by graph.

    :param cluster: The cluster to determine the mean inter cluster score for
    :param graph: The underlying graph that offers a distance function
    :param mean: A precalculated centroid for given cluster
    :return: Mean distances within the given cluster to its centroid
    """
    distance = 0
    assert cluster
    if mean is None:
        mean = graph.distance.mean(list(cluster))
    for node in cluster:
        distance += graph.distance(mean, node)
    return distance / float(len(list(cluster)))