Check that composite distance function is in valid form. Don't modify the
    composite distance in any way.

def _validate_composite_distance(distance):
    """
    Check that composite distance function is in valid form. Don't modify the
    composite distance in any way.
    """

    if not isinstance(distance, list):
        raise TypeError("Input 'distance' must be a composite distance.")

    if len(distance) < 1:
        raise ValueError("Composite distances must have a least one distance "
                         "component, consisting of a list of feature names, "
                         "a distance function (string or function handle), "
                         "and a weight.")

    for d in distance:

        ## Extract individual pieces of the distance component
        try:
            ftrs, dist, weight = d
        except:
            raise TypeError("Elements of a composite distance function must " +
                            "have three items: a set of feature names (tuple or list), " +
                            "a distance function (string or function handle), " +
                            "and a weight.")

        ## Validate feature names
        if len(ftrs) == 0:
            raise ValueError("An empty list of features cannot be passed " +\
                             "as part of a composite distance function.")

        if not isinstance(ftrs, (list, tuple)):
            raise TypeError("Feature names must be specified in a list or tuple.")

        if not all([isinstance(x, str) for x in ftrs]):
            raise TypeError("Feature lists must contain only strings.")


        ## Validate standard distance function
        if not isinstance(dist, str) and not hasattr(dist, '__call__'):
            raise ValueError("Standard distances must be the name of a distance " +
                             "function (string) or a distance function handle")

        if isinstance(dist, str):
            try:
                _tc.distances.__dict__[dist]
            except:
                raise ValueError("Distance '{}' not recognized".format(dist))


        ## Validate weight
        if not isinstance(weight, (int, float)):
            raise ValueError(
                "The weight of each distance component must be a single " +\
                "integer or a float value.")

        if weight < 0:
            raise ValueError("The weight on each distance component must be " +
                             "greater than or equal to zero.")