Exemplo n.º 1
0
    def __eq__(self, other):

        if isinstance(other, EAC_FULL):
            me_condensed = self.condensed
            other_condensed = other.condensed

            me_cmp_mat = self.coassoc
            if not me_condensed:
                me_cmp_mat = squareform(self.coassoc)
            other_cmp_mat = other.coassoc
            if not other_condensed:
                other_cmp_mat = squareform(other.coassoc)

            return (me_cmp_mat == other_cmp_mat).all()

        elif isinstance(other, EAC_CSR):
            me_condensed = self.condensed
            other_condensed = other.condensed

            me_cmp_mat = self.tocsr()
            other_cmp_mat = other.tocsr()
            if other_condensed:
                other_cmp_mat = other_cmp_mat + other_cmp_mat.T

            return (me_cmp_mat == other_cmp_mat).all()

        else:
            print other.__class__
            raise TypeError(
                "Comparison only with EAC_CSR or EAC_FULL objects.")
Exemplo n.º 2
0
def full_sl_lifetime(mat, n_samples, n_clusters=0):

    # convert to diassoc
    if mat.ndim == 2:
        mat = squareform(mat)

    #Z = linkage(mat, method="single")
    Z = slink(mat, n_samples)

    if n_clusters == 0:

        cont, max_lifetime = lifetime_n_clusters(Z[:, 2])

        nc_stable = cont
    else:
        nc_stable = n_clusters

    if nc_stable > 1:
        labels = labels_from_Z(Z, n_clusters=nc_stable)
        # rename labels
        i = 0
        for l in np.unique(labels):
            labels[labels == l] = i
            i += 1
    else:
        labels = np.empty(0, dtype=np.int32)

    return nc_stable, labels
Exemplo n.º 3
0
def full_sl_lifetime(mat, n_samples, n_clusters=0):

    # convert to diassoc
    if mat.ndim == 2:
        mat = squareform(mat)

    #Z = linkage(mat, method="single")
    Z = slink(mat, n_samples)

    if n_clusters == 0:

        cont, max_lifetime = lifetime_n_clusters(Z[:,2])

        nc_stable = cont
    else:
        nc_stable = n_clusters

    if nc_stable > 1:
        labels = labels_from_Z(Z, n_clusters=nc_stable)
        # rename labels
        i=0
        for l in np.unique(labels):
            labels[labels == l] = i
            i += 1        
    else:
        labels = np.empty(0, dtype=np.int32)

    return nc_stable, labels
Exemplo n.º 4
0
def coassoc_to_condensed_diassoc(assoc_mat, max_val, copy=False):
    """
    Simple routine to tranform a full square co-association matrix in a 
    condensed form diassociation matrix. Max val is the value to use for
    normalization - usually the number of partitions. The diassociation
    matrix will have no zeros - minimum value possible is 1.
    """

    if copy:
        assoc_mat_use = assoc_mat.copy()
    else:
        assoc_mat_use = assoc_mat

    make_diassoc_2d(assoc_mat_use, max_val)  # make matrix diassoc
    fill_diag(assoc_mat_use, 0)  # clear diagonal

    condensed_diassoc = squareform(assoc_mat_use)

    return condensed_diassoc
Exemplo n.º 5
0
 def tocsr(self):
     if self.condensed:
         return csr_matrix(squareform(self.coassoc))
     else:
         return csr_matrix(self.coassoc)
Exemplo n.º 6
0
 def todense(self):
     if self.condensed:
         return squareform(self.coassoc)
     else:
         return self.coassoc.copy()