Skip to content

Commit

Permalink
Update matching options
Browse files Browse the repository at this point in the history
  • Loading branch information
lidakanari committed Jun 12, 2018
1 parent d9463f3 commit d4d6cb3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tmd/Topology/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,26 @@ def symmetric(p):
return [(p[0] + p[1]) / 2., (p[0] + p[1]) / 2]


def matching_diagrams(p1, p2, plot=False, method='munkres', use_diag=True):
def matching_diagrams(p1, p2, plot=False, method='munkres', use_diag=True, new_fig=True, subplot=(111)):
'''Returns a list of matching components
Possible matching methods:
- munkress
- marriage problem
'''
from scipy.spatial.distance import cdist
import munkres
from view import common as _cm

def plot_matching(p1, p2, indices):
def plot_matching(p1, p2, indices, new_fig=True, subplot=(111)):
'''Plots matching between p1, p2
for the corresponding indices
'''
import pylab as plt
fig = plt.figure()
fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot)
for i,j in indices:
plt.plot((p1[i][0], p2[j][0]), (p1[i][1], p2[j][1]), color='black')
plt.scatter(p1[i][0], p1[i][1], c='r')
plt.scatter(p2[j][0], p2[j][1], c='b')
ax.plot((p1[i][0], p2[j][0]), (p1[i][1], p2[j][1]), color='black')
ax.scatter(p1[i][0], p1[i][1], c='r')
ax.scatter(p2[j][0], p2[j][1], c='b')

if use_diag:
p1_enh = p1 + [symmetric(i) for i in p2]
Expand All @@ -375,7 +376,7 @@ def plot_matching(p1, p2, indices):
indices = _marriage_problem(first_pref, second_pref)

if plot:
plot_matching(p1_enh, p2_enh, indices)
plot_matching(p1_enh, p2_enh, indices, new_fig=new_fig, subplot=subplot)

ssum = np.sum([D[i][j] for (i,j) in indices])

Expand Down

0 comments on commit d4d6cb3

Please sign in to comment.