예제 #1
0
def square_euclidean_dist(v1,v2):
    if (v1 == v2).all():
        return 0.0
    valids  = 0
    distance= 0.0
    for i in range(len(v1)):
        if numpy.isfinite(v1[i]) and numpy.isfinite(v2[i]):
            valids += 1
            d = v1[i]-v2[i]
            distance += d*d
    if valids==0:
        raise ValueError("Cannot calculate values")
    return  distance/valids
예제 #2
0
def square_euclidean_dist(v1, v2):
    if (v1 == v2).all():
        return 0.0
    valids = 0
    distance = 0.0
    for i in range(len(v1)):
        if numpy.isfinite(v1[i]) and numpy.isfinite(v2[i]):
            valids += 1
            d = v1[i] - v2[i]
            distance += d * d
    if valids == 0:
        raise ValueError("Cannot calculate values")
    return distance / valids
예제 #3
0
def safe_mean(values):
    """ Returns mean value discarding non finite values """
    valid_values = []
    for v in values:
        if numpy.isfinite(v):
            valid_values.append(v)
    return numpy.mean(valid_values), numpy.std(valid_values)
예제 #4
0
def safe_mean(values):
    """ Returns mean value discarding non finite values """
    valid_values = []
    for v in values:
        if numpy.isfinite(v):
            valid_values.append(v)
    return numpy.mean(valid_values), numpy.std(valid_values)
예제 #5
0
def safe_mean_vector(vectors):
    """ Returns mean profile discarding non finite values """
    # if only one vector, avg = itself
    if len(vectors) == 1:
        return vectors[0], numpy.zeros(len(vectors[0]))
    # Takes the vector length form the first item
    length = len(vectors[0])

    safe_mean = []
    safe_std = []

    for pos in range(length):
        pos_mean = []
        for v in vectors:
            if numpy.isfinite(v[pos]):
                pos_mean.append(v[pos])
        safe_mean.append(numpy.mean(pos_mean))
        safe_std.append(numpy.std(pos_mean))
    return safe_mean, safe_std
예제 #6
0
파일: arraytable.py 프로젝트: Ward9250/ete
def safe_mean_vector(vectors):
    """ Returns mean profile discarding non finite values """
    # if only one vector, avg = itself
    if len(vectors)==1:
        return vectors[0], numpy.zeros(len(vectors[0]))
    # Takes the vector length form the first item
    length = len(vectors[0])

    safe_mean = []
    safe_std  = []

    for pos in range(length):
        pos_mean = []
        for v in vectors:
            if numpy.isfinite(v[pos]):
                pos_mean.append(v[pos])
        safe_mean.append(numpy.mean(pos_mean))
        safe_std.append(numpy.std(pos_mean))
    return safe_mean, safe_std
예제 #7
0
파일: clustertree.py 프로젝트: Ward9250/ete
    def link_to_arraytable(self, arraytbl):
        """ Allows to link a given arraytable object to the tree
        structure under this node. Row names in the arraytable object
        are expected to match leaf names.

        Returns a list of nodes for with profiles could not been found
        in arraytable.

        """

        # Initialize tree with array data

        if type(arraytbl) == ArrayTable:
            array = arraytbl
        else:
            array = ArrayTable(arraytbl)

        missing_leaves = []
        matrix_values = [i for r in range(len(array.matrix))\
                           for i in array.matrix[r] if numpy.isfinite(i)]

        array._matrix_min = min(matrix_values)
        array._matrix_max = max(matrix_values)

        for n in self.traverse():
            n.arraytable = array
            if n.is_leaf() and n.name in array.rowNames:
                n._profile = array.get_row_vector(n.name)
            elif n.is_leaf():
                n._profile = [numpy.nan]*len(array.colNames)
                missing_leaves.append(n)


        if len(missing_leaves)>0:
            print("""[%d] leaf names could not be mapped to the matrix rows.""" %\
                len(missing_leaves), file=stderr)

        self.arraytable = array
예제 #8
0
    def link_to_arraytable(self, arraytbl):
        """ Allows to link a given arraytable object to the tree
        structure under this node. Row names in the arraytable object
        are expected to match leaf names.

        Returns a list of nodes for with profiles could not been found
        in arraytable.

        """

        # Initialize tree with array data

        if type(arraytbl) == ArrayTable:
            array = arraytbl
        else:
            array = ArrayTable(arraytbl)

        missing_leaves = []
        matrix_values = [i for r in range(len(array.matrix))\
                           for i in array.matrix[r] if numpy.isfinite(i)]

        array._matrix_min = min(matrix_values)
        array._matrix_max = max(matrix_values)

        for n in self.traverse():
            n.arraytable = array
            if n.is_leaf() and n.name in array.rowNames:
                n._profile = array.get_row_vector(n.name)
            elif n.is_leaf():
                n._profile = [numpy.nan] * len(array.colNames)
                missing_leaves.append(n)

        if len(missing_leaves) > 0:
            print("""[%d] leaf names could not be mapped to the matrix rows.""" %\
                len(missing_leaves), file=stderr)

        self.arraytable = array