update
This commit is contained in:
@@ -5,28 +5,30 @@ Author: John
|
||||
Email: johnjim0816@gmail.com
|
||||
Date: 2020-10-07 20:57:11
|
||||
LastEditor: John
|
||||
LastEditTime: 2021-03-31 14:05:52
|
||||
LastEditTime: 2021-03-31 18:47:28
|
||||
Discription:
|
||||
Environment:
|
||||
'''
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
def plot_rewards(rewards,ma_rewards,tag="train",algo = "DQN",path='./'):
|
||||
def plot_rewards(rewards,ma_rewards,tag="train",algo = "DQN",save=True,path='./'):
|
||||
sns.set()
|
||||
plt.title("average learning curve of {}".format(algo))
|
||||
plt.xlabel('epsiodes')
|
||||
plt.plot(rewards,label='rewards')
|
||||
plt.plot(ma_rewards,label='moving average rewards')
|
||||
plt.legend()
|
||||
plt.savefig(path+"rewards_curve_{}".format(tag))
|
||||
if save:
|
||||
plt.savefig(path+"rewards_curve_{}".format(tag))
|
||||
plt.show()
|
||||
|
||||
def plot_losses(losses,algo = "DQN",path='./'):
|
||||
def plot_losses(losses,algo = "DQN",save=True,path='./'):
|
||||
sns.set()
|
||||
plt.title("loss curve of {}".format(algo))
|
||||
plt.xlabel('epsiodes')
|
||||
plt.plot(losses,label='rewards')
|
||||
plt.legend()
|
||||
plt.savefig(path+"losses_curve")
|
||||
if save:
|
||||
plt.savefig(path+"losses_curve")
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Author: John
|
||||
Email: johnjim0816@gmail.com
|
||||
Date: 2021-03-12 16:02:24
|
||||
LastEditor: John
|
||||
LastEditTime: 2021-03-12 16:10:28
|
||||
LastEditTime: 2021-04-03 21:42:13
|
||||
Discription:
|
||||
Environment:
|
||||
'''
|
||||
@@ -18,4 +18,17 @@ def save_results(rewards,ma_rewards,tag='train',path='./results'):
|
||||
'''
|
||||
np.save(path+'rewards_'+tag+'.npy', rewards)
|
||||
np.save(path+'ma_rewards_'+tag+'.npy', ma_rewards)
|
||||
print('results saved!')
|
||||
print('results saved!')
|
||||
|
||||
def make_dir(*paths):
|
||||
for path in paths:
|
||||
if not os.path.exists(path): # check if exists
|
||||
os.mkdir(path)
|
||||
def del_empty_dir(*paths):
|
||||
'''del_empty_dir delete empty folders unders "paths"
|
||||
'''
|
||||
for path in paths:
|
||||
dirs = os.listdir(path)
|
||||
for dir in dirs:
|
||||
if not os.listdir(os.path.join(path, dir)):
|
||||
os.removedirs(os.path.join(path, dir))
|
||||
Reference in New Issue
Block a user