Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dataframe.groupby instead of iterating #61

Merged
merged 17 commits into from
Dec 2, 2019
Merged
Prev Previous commit
Next Next commit
Add support for empty predictions.
Select non-empty elements before making hypothesis ID an index.
This avoids "non-empty take from an empty axes" error.
  • Loading branch information
Jack Valmadre committed Nov 15, 2019
commit 08ab6d384f35fe60322ac242a90c0414c888c7be
9 changes: 6 additions & 3 deletions motmetrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def id_global_assignment(df):
nh = hids.shape[0]

df = df.raw.reset_index()
df = df.set_index(['OId','HId'])
df = df.sort_index(level=[0,1])
df = df.set_index('OId')
df = df.sort_index()

fpmatrix = np.full((no+nh, no+nh), 0.)
fnmatrix = np.full((no+nh, no+nh), 0.)
Expand All @@ -332,7 +332,10 @@ def id_global_assignment(df):
fpmatrix[c+no,c] = hc

for r, o in enumerate(oids):
df_o = df.loc[o, 'D'].dropna()
# Select non-empty events for this object.
df_o = df.loc[o, ['HId', 'D']].dropna()
# Re-index by hypothesis and select single column.
df_o = df_o.set_index('HId').loc[:, 'D']
for h, ex in df_o.groupby(level=0).count().iteritems():
c = hids_idx[h]

Expand Down