Created
February 16, 2018 13:01
-
-
Save EndingCredits/4a64c1e12b9e0cdab5da812f596f5857 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import numpy as np | |
import matplotlib.pyplot as plt | |
fig = plt.figure() | |
ax = plt.subplot(111) | |
def savitzky_golay(y, window_size, order, deriv=0, rate=1): | |
""" | |
http://scipy.github.io/old-wiki/pages/Cookbook/SavitzkyGolay | |
""" | |
import numpy as np | |
from math import factorial | |
try: | |
window_size = np.abs(np.int(window_size)) | |
order = np.abs(np.int(order)) | |
except ValueError, msg: | |
raise ValueError("window_size and order have to be of type int") | |
if window_size % 2 != 1 or window_size < 1: | |
raise TypeError("window_size size must be a positive odd number") | |
if window_size < order + 2: | |
raise TypeError("window_size is too small for the polynomials order") | |
order_range = range(order+1) | |
half_window = (window_size -1) // 2 | |
# precompute coefficients | |
b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)]) | |
m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv) | |
# pad the signal at the extremes with | |
# values taken from the signal itself | |
firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] ) | |
lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1]) | |
y = np.concatenate((firstvals, y, lastvals)) | |
return np.convolve( m[::-1], y, mode='valid') | |
for filename in glob.iglob('*.npy'): | |
if 'aliens' in filename: | |
print(filename) | |
data = np.load(filename) | |
data = data.item()['tests'] | |
x = [] ; y = [] ; y_err = [] | |
for d in data: | |
x.append(d['step']) | |
y.append(np.mean(d['scores'])) | |
y_err.append(np.std(d['scores'])/7.07) | |
if len(y) > 4: | |
pass#y = savitzky_golay(y, window_size=51, order=4) | |
ax.errorbar(x, y, yerr=y_err, label=filename) | |
#ax.xlabel('some numbers') | |
# Shrink current axis's height by 10% on the bottom | |
box = ax.get_position() | |
ax.set_position([box.x0, box.y0 + box.height * 0.1, | |
box.width* 0.8, box.height ]) | |
# Put a legend below current axis | |
ax.legend(loc='right', bbox_to_anchor=(1.4, 0.5), | |
fancybox=True, shadow=True, ncol=1) | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment