forked from giomgit/potion-fork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showresults_cartpole_orig.py
76 lines (60 loc) · 2.88 KB
/
showresults_cartpole_orig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# %%
from matplotlib import pyplot as plt
from expsuite import PyExperimentSuite
from experiments.plot_utils import plot_ci, get_dataframe
"""
***************************************************************************************************
Plot
***************************************************************************************************
"""
mysuite = PyExperimentSuite(config='experiments_cartpole_orig.cfg')
# mysuite = PyExperimentSuite(config='experiments_cartpole_chi2.cfg')
experiments = ['means_20', 'stds_20']
'''
# Command line arguments
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--config', '-c', help='Experiment configuration file', type=str,
default='experiments.cfg')
parser.add_argument('--experiment', '-e', help='Experiments to be shown', dest='experiments', action = 'append',type=str,
default=None)
# Parse arguments
args = parser.parse_known_args()[0]
mysuite = PyExperimentSuite(config = args.config)
if args.experiments is not None:
experiments = args.experiments
else:
experiments = mysuite.cfgparser.sections()
'''
plt.rcParams.update({
"text.usetex": True,
"font.family": "Helvetica",
'text.latex.preamble': r"\usepackage{amsmath}"
})
# Varying initial policy mean
# -----------------------------------------------------
if 'means_20' in experiments:
df = get_dataframe(mysuite, experiment_name='means_20', xkey='mu_init', cos_sim=True)
fig,axes = plt.subplots(1, 2, dpi = 200)
line_is = plot_ci(df,'grad_cos_sim','mu_init', axes[0])
axes[0].set(xlabel = r'Policy mean $\boldsymbol{\theta}_\mu$', ylabel = 'Cosine similarity')
axes[0].set_ylim([-1.2, 1.2])
line_is = plot_ci(df,'var_grad_is','mu_init', axes[1], 'o-')
line_mc = plot_ci(df,'var_grad_mc','mu_init', axes[1], 's--')
axes[1].set(xlabel = r'Policy mean $\boldsymbol{\theta}_\mu$', ylabel = 'Variance of gradient estimates')
axes[1].legend([line_is[0], line_mc[0]], ["off-policy", "on-policy"])
fig.tight_layout()
plt.show()
# Varying initial policy variance
# -----------------------------------------------------
if 'stds_20' in experiments:
df = get_dataframe(mysuite, experiment_name='stds_20', xkey='logstd_init', cos_sim=True)
fig,axes = plt.subplots(1, 2, dpi = 200)
line_is = plot_ci(df,'grad_cos_sim','logstd_init', axes[0])
axes[0].set(xlabel = 'Policy log standard deviation', ylabel = 'Cosine similarity')
axes[0].set_ylim([-1.2, 1.2])
line_is = plot_ci(df,'var_grad_is','logstd_init', axes[1], 'o-')
line_mc = plot_ci(df,'var_grad_mc','logstd_init', axes[1], 's--')
axes[1].set(xlabel = 'Policy log standard deviation', ylabel = 'Variance of gradient estimates')
axes[1].legend([line_is[0], line_mc[0]], ["off-policy", "on-policy"])
fig.tight_layout()
plt.show()