Skip to content

Commit

Permalink
Select the lower left triangle to convert DistanceMatrices to long form.
Browse files Browse the repository at this point in the history
This makes the return value of delta_values order-compatible with ssd.squareform, i.e. dm.delta_values().values == ssd.squareform(dm) and all(dm.delta_values().index == pd.MultiIndex.from_tuples(itertools.combinations(corpus.index, 2)))
  • Loading branch information
thvitt committed Jun 14, 2021
1 parent 1a6856e commit 0ee6678
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions delta/deltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,17 +654,17 @@ def save(self, filename):

def _remove_duplicates(self):
"""
Returns a DistanceMatrix that has only the upper right triangle filled,
Returns a DistanceMatrix that has only the lower left triangle filled,
ie contains only the unique meaningful values.
"""
return DistanceMatrix(self.where(np.triu(np.ones(self.shape, dtype=bool),
k=1)),
return DistanceMatrix(self.where(np.tril(np.ones(self.shape, dtype=bool),
k=-1)),
copy_from=self)

def delta_values(self):
r"""
Converts the given n×n Delta matrix to a :math:`\binom{n}{2}` long
series of distinct delta values – i.e. duplicates from the lower
series of distinct delta values – i.e. duplicates from the upper
triangle and zeros from the diagonal are removed.
"""
return self._remove_duplicates().unstack().dropna()
Expand Down

0 comments on commit 0ee6678

Please sign in to comment.