def mean_pairwise_similarity(<EOL>collection, metric=sim, mean_func=hmean, symmetric=False<EOL>):
if not callable(mean_func):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not callable(metric):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if hasattr(collection, '<STR_LIT>'):<EOL><INDENT>collection = collection.split()<EOL><DEDENT>if not hasattr(collection, '<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif len(collection) < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>collection = list(collection)<EOL>pairwise_values = []<EOL>for i in range(len(collection)):<EOL><INDENT>for j in range(i + <NUM_LIT:1>, len(collection)):<EOL><INDENT>pairwise_values.append(metric(collection[i], collection[j]))<EOL>if symmetric:<EOL><INDENT>pairwise_values.append(metric(collection[j], collection[i]))<EOL><DEDENT><DEDENT><DEDENT>return mean_func(pairwise_values)<EOL>
Calculate the mean pairwise similarity of a collection of strings.

    Takes the mean of the pairwise similarity between each member of a
    collection, optionally in both directions (for asymmetric similarity
    metrics.

    Parameters
    ----------
    collection : list
        A collection of terms or a string that can be split
    metric : function
        A similarity metric function
    mean_func : function
        A mean function that takes a list of values and returns a float
    symmetric : bool
        Set to True if all pairwise similarities should be calculated in both
        directions

    Returns
    -------
    float
        The mean pairwise similarity of a collection of strings

    Raises
    ------
    ValueError
        mean_func must be a function
    ValueError
        metric must be a function
    ValueError
        collection is neither a string nor iterable type
    ValueError
        collection has fewer than two members

    Examples
    --------
    >>> round(mean_pairwise_similarity(['Christopher', 'Kristof',
    ... 'Christobal']), 12)
    0.519801980198
    >>> round(mean_pairwise_similarity(['Niall', 'Neal', 'Neil']), 12)
    0.545454545455