ActiveBOToytask/plotter/reward_plotter.py

42 lines
1.3 KiB
Python
Raw Normal View History

2023-06-01 08:57:18 +00:00
import numpy as np
import matplotlib.pyplot as plt
import os
def plot_csv(paths, x_axis, y_axis):
for path_ in paths:
data = np.genfromtxt(path_, delimiter=',', skip_header=1, dtype=float)
mean = np.mean(data, axis=1)
std = np.std(data, axis=1)
x = np.linspace(0, mean.shape[0], mean.shape[0])
# Extract the first part of the filename and use it as a label
2023-06-01 13:46:13 +00:00
label = os.path.basename(path_).split('-')[0:5]
label = f"{label[1]}, {label[2]}, {float(label[3].replace('_','.'))}, nrbfs = {int(label[4])}"
2023-06-01 08:57:18 +00:00
plt.plot(x, mean, label=label)
plt.fill_between(
x,
mean - 1.96 * std,
mean + 1.96 * std,
alpha=0.5
)
plt.xlabel(x_axis)
plt.xlim([0, mean.shape[0]])
plt.ylabel(y_axis)
plt.grid(True)
plt.legend(loc="best")
plt.show()
if __name__ == '__main__':
2023-06-01 13:46:13 +00:00
filenames = ['mc-ei-random-1_0-5-1685622201_6965265.csv',
'mc-pi-random-1_0-5-1685622464_9843714.csv',
'mc-cb-random-1_0-5-1685622728_8990934.csv']
2023-06-01 08:57:18 +00:00
home_dir = os.path.expanduser('~')
file_path = os.path.join(home_dir, 'Documents/IntRLResults')
paths = [os.path.join(file_path, filename) for filename in filenames]
plot_csv(paths, 'Episodes', 'Reward')