MCPcopy Create free account
hub / github.com/danijar/dreamerv3 / plot_runs

Function plot_runs

plot.py:203–251  ·  view source on GitHub ↗
(df, stats, args)

Source from the content-addressed store, hash-verified

201
202
203def plot_runs(df, stats, args):
204 print('Plotting...')
205 tasks = natsort(df.task.unique())
206 snames = [] if stats is None else stats.name.unique()
207 methods = natsort(df.method.unique())
208 total = len(tasks) + len(snames)
209 cols = args.cols or (4 + (total > 24) + (total > 35) + (total > 48))
210 fig, axes = plots(total, cols, args.size)
211
212 grouped = df.groupby(['task', 'method'])[['xs', 'ys', 'seed']].agg(np.stack)
213 for task, ax in zip(tasks, axes[:len(tasks)]):
214 style(ax, xticks=args.xticks, yticks=args.yticks)
215 title = task.replace('_', ' ').replace(':', ' ').split(' ', 1)[1].title()
216 ax.set_title(title)
217 args.xlim and ax.set_xlim(0, 1.03 * args.xlim)
218 args.ylim and ax.set_ylim(0, 1.03 * args.ylim)
219 for i, method in enumerate(methods):
220 try:
221 sub = grouped.loc[task, method]
222 except KeyError:
223 print(f"Missing method '{method}' on task '{task}'")
224 continue
225 bins = sub['xs'][0]
226
227 if args.agg:
228 mean = nanmean(sub['ys'], 0)
229 std = nanstd(sub['ys'], 0)
230 curve(ax, bins, mean, mean - std, mean + std, method, i)
231 else:
232 for j in range(sub['xs'].shape[0]):
233 curve(ax, sub['xs'][j], sub['ys'][j], None, None, method, i)
234
235 if stats is not None:
236 grouped = stats.groupby(['name', 'method'])[['xs', 'ys']].agg(np.stack)
237 for sname, ax in zip(snames, axes[len(tasks):]):
238 style(ax, xticks=args.xticks, yticks=args.yticks, darker=True)
239 ax.set_title(sname)
240 args.xlim and ax.set_xlim(0, 1.03 * args.xlim)
241 for i, method in enumerate(methods):
242 sub = grouped.loc[sname, method]
243 curve(ax, sub['xs'], sub['ys'], None, None, method, i)
244
245 legend(fig, adjust=True, ncol=args.legendcols or min(4, cols, len(axes)))
246
247 outdir = elements.Path(args.outdir) / elements.Path(args.indirs[0]).stem
248 outdir.mkdir()
249 filename = outdir / 'curves.png'
250 fig.savefig(filename, dpi=150)
251 print('Saved', filename)
252
253
254def plots(amount, cols=4, size=(3, 3), **kwargs):

Callers 1

mainFunction · 0.85

Calls 5

natsortFunction · 0.85
plotsFunction · 0.85
styleFunction · 0.85
curveFunction · 0.85
legendFunction · 0.85

Tested by

no test coverage detected