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

Dev -> main #775

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions scoring/score_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
'submission_directory',
None,
'Path to submission directory containing experiment directories.')
flags.DEFINE_string('output_dir',
'scoring_results',
'Path to save performance profile table and plot.')
flags.DEFINE_string(
'output_dir',
'scoring_results',
'Path to save performance profile artifacts, submission_summaries and results files.'
)
flags.DEFINE_boolean('compute_performance_profiles',
False,
'Whether or not to compute the performance profiles.')
Expand All @@ -51,11 +53,16 @@
None,
'Filename to save the processed results that are fed into the performance profile functions.'
)
flags.DEFINE_boolean(
flags.DEFINE_string(
'load_results_from_filename',
None,
'Filename to load processed results from that are fed into performance profile functions'
)
flags.DEFINE_string(
'exclude_submissions',
'',
'Optional comma seperated list of names of submissions to exclude from scoring.'
)
FLAGS = flags.FLAGS


Expand Down Expand Up @@ -129,6 +136,22 @@ def get_submission_summary(df, include_test_split=True):
return df


def compute_leaderboard_score(df, normalize=False):
"""Compute leaderboard score by taking integral of performance profile.

Args:
df: pd.DataFrame returned from `compute_performance_profiles`.
normalize: divide by the range of the performance profile's tau.

Returns:
pd.DataFrame with one column of scores indexed by submission.
"""
scores = np.trapz(df, x=df.columns)
if normalize:
scores /= df.columns.max() - df.columns.min()
return pd.DataFrame(scores, columns=['score'], index=df.index)


def main(_):
results = {}
os.makedirs(FLAGS.output_dir, exist_ok=True)
Expand All @@ -144,6 +167,8 @@ def main(_):
for submission in os.listdir(
os.path.join(FLAGS.submission_directory, team)):
print(submission)
if submission in FLAGS.exclude_submissions.split(','):
continue
experiment_path = os.path.join(FLAGS.submission_directory,
team,
submission)
Expand Down Expand Up @@ -185,9 +210,13 @@ def main(_):
os.mkdir(FLAGS.output_dir)
performance_profile.plot_performance_profiles(
performance_profile_df, 'score', save_dir=FLAGS.output_dir)
perf_df = tabulate(
performance_profile_str = tabulate(
performance_profile_df.T, headers='keys', tablefmt='psql')
logging.info(f'Performance profile:\n {perf_df}')
logging.info(f'Performance profile:\n {performance_profile_str}')
scores = compute_leaderboard_score(performance_profile_df)
scores.to_csv(os.path.join(FLAGS.output_dir, 'scores.csv'))
scores_str = tabulate(scores, headers='keys', tablefmt='psql')
logging.info(f'Scores: \n {scores_str}')


if __name__ == '__main__':
Expand Down
Loading