Skip to content

Instantly share code, notes, and snippets.

@taotao54321
Created November 8, 2016 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taotao54321/cec152162be9888c0e55c9d588460fe0 to your computer and use it in GitHub Desktop.
Save taotao54321/cec152162be9888c0e55c9d588460fe0 to your computer and use it in GitHub Desktop.
#!/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