How to use the lingpy.algorithm.misc.squareform function in lingpy

To help you get started, we’ve selected a few lingpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lingpy / lingpy / lingpy / compare / lexstat.py View on Github external
indices = self.get_list(row=c, flat=True)
            matrix = []
            for idxA, idxB in util.combinations2(indices):
                try:
                    d = function(idxA, idxB)
                except ZeroDivisionError:
                    log.warning(
                        "Encountered Zero-Division for the comparison of "
                        "{0} ({2}) and {1} ({3})".format(
                            ''.join(self[idxA, self._segments]),
                            ''.join(self[idxB, self._segments]),
                            idxA, idxB
                            ))
                    d = 100
                matrix += [d]
            matrix = misc.squareform(matrix)
            if not concept:
                yield c, indices, matrix
            else:
                yield matrix
github lingpy / lingpy / lingpy / compare / partial.py View on Github external
for (idxA, posA, sliceA), (idxB, posB, sliceB) in combinations(tracer, r=2):
                    
                    if idxA == idxB:
                        d = 1
                    else:
                        try:
                            d = function(idxA, idxB, sliceA, sliceB)
                        except ZeroDivisionError:
                            lingpy.log.warning(
                                "Encountered Zero-Division for the comparison of "
                                "{0} and {1}".format(
                                    ''.join(self[idxA, self._tokens]),
                                    ''.join(self[idxB, self._tokens])))
                            d = 100
                    matrix += [d]
                matrix = lingpy.algorithm.misc.squareform(matrix)
            if not concept:
                yield c, tracer, matrix
            else:
                yield matrix
github lingpy / lingpy / lingpy / align / multiple.py View on Github external
self._numbers, gop, scale, self.scorer, mode)
            k = 0
            for i, j in combinations_with_replacement(range(self.height), 2):
                almA, almB, sim, dist = alignments[k]
                k += 1
                if i < j:
                    if mode == 'local':
                        almA = almA[1]
                        almB = almB[1]
                    self._alignments[i][j] = [almA, almB, sim]
                    self._alignments[j][i] = [almA, almB, sim]
                    self.matrix += [dist]
                elif i == j:
                    self._alignments[i][j] = [almA, almB, sim]

        self.matrix = misc.squareform(self.matrix)
github lingpy / lingpy / lingpy / algorithm / cluster.py View on Github external
dist_b = matrix[idxB][b]
                new_matrix.append(((dist_a + dist_b) - dist_ab) / 2.0)
            elif i < j and b == idxA:
                dist_a = matrix[idxA][a]
                dist_b = matrix[idxB][a]
                new_matrix.append(((dist_a + dist_b) - dist_ab) / 2.0)
    
    # get values of new_clusters into clusters
    clusters = {}
    for key,val in new_clusters.items():
        clusters[key] = val

    # return score
    return _neighbor(
            clusters,
            squareform(new_matrix),
            tree_matrix,
            constant_matrix,
            tracer
            )