Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import json
import numpy as np
def error(msg):
sys.exit(msg)
def running_mean(x, n):
cumsum = np.cumsum(np.insert(x, 0, 0))
return (cumsum[n:] - cumsum[:-n]) / n
def usage():
error("Usage: judge <overall_count> <trial_count> <json>")
def main():
if len(sys.argv) != 4: usage()
overall_count = int(sys.argv[1])
trial_count = int(sys.argv[2])
stats_path = sys.argv[3]
with open(stats_path, "r") as in_:
stats = json.load(in_)
rewards = stats["episode_rewards"]
avg_overall = np.mean(rewards[-overall_count:])
avg_best = max(running_mean(rewards, trial_count))
print("overall: {}".format(avg_overall))
print("best: {}".format(avg_best))
if __name__ == "__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment