From 8b95576a92f41c27f5e58fe26360ce098350fdf4 Mon Sep 17 00:00:00 2001 From: pzhokhov Date: Tue, 6 Nov 2018 17:02:20 -0800 Subject: [PATCH 1/2] more viz + build fixes (#703) * viz docs * writing vizualization docs * documenting plot_util * docstrings in plot_util * autopep8 and flake8 * spelling (using default vim spellchecker and ingoring things like dataframe, docstring and etc) * rephrased viz.md a little bit * more examples of viz code usage in the docs --- .travis.yml | 2 +- baselines/common/plot_util.py | 20 +++++++++++++++----- docs/viz/viz.md | 25 ++++++++++++++++++++++--- setup.py | 1 + 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 712fc84..7ca7e6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ install: script: - flake8 . --show-source --statistics - - docker run baselines-test pytest -v . + - docker run baselines-test pytest -v --forked . diff --git a/baselines/common/plot_util.py b/baselines/common/plot_util.py index 6f4c272..1d105c8 100644 --- a/baselines/common/plot_util.py +++ b/baselines/common/plot_util.py @@ -240,6 +240,8 @@ def plot_results( split_fn=default_split_fn, group_fn=default_split_fn, average_group=False, + shaded_std=True, + shaded_err=True, figsize=None, legend_outside=False, resample=0, @@ -261,9 +263,15 @@ def plot_results( Curves in the same group have the same color (if average_group is False), or averaged over (if average_group is True). The default value is the same as default value for split_fn - average_group: bool - if True, will average the curves in the same group. The mean of the result is plotted, with lighter - shaded region around corresponding to the standard deviation, and darker shaded region corresponding to - the error of mean estimate (that is, standard deviation over square root of number of samples) + average_group: bool - if True, will average the curves in the same group and plot the mean. Enables resampling + (if resample = 0, will use 512 steps) + + shaded_std: bool - if True (default), the shaded region corresponding to standard deviation of the group of curves will be + shown (only applicable if average_group = True) + + shaded_err: bool - if True (default), the shaded region corresponding to error in mean estimate of the group of curves + (that is, standard deviation divided by square root of number of curves) will be + shown (only applicable if average_group = True) figsize: tuple or None - size of the resulting figure (including sub-panels). By default, width is 6 and height is 6 times number of sub-panels. @@ -346,8 +354,10 @@ def plot_results( ystderr = ystd / np.sqrt(len(ys)) l, = axarr[isplit][0].plot(usex, ymean, color=color) g2l[group] = l - ax.fill_between(usex, ymean - ystderr, ymean + ystderr, color=color, alpha=.4) - ax.fill_between(usex, ymean - ystd, ymean + ystd, color=color, alpha=.2) + if shaded_err: + ax.fill_between(usex, ymean - ystderr, ymean + ystderr, color=color, alpha=.4) + if shaded_std: + ax.fill_between(usex, ymean - ystd, ymean + ystd, color=color, alpha=.2) # https://matplotlib.org/users/legend_guide.html diff --git a/docs/viz/viz.md b/docs/viz/viz.md index d54ca37..8d65816 100644 --- a/docs/viz/viz.md +++ b/docs/viz/viz.md @@ -27,9 +27,8 @@ And you can now start TensorBoard with: tensorboard --logdir=$OPENAI_LOGDIR ``` -## Loading summaries of the results +## Loading summaries of the results ([notebook](https://colab.research.google.com/drive/1Wez1SA9PmNkCoYc8Fvl53bhU3F8OffGm)) If the summary overview provided by tensorboard is not sufficient, and you would like to either access to raw environment episode data, or use complex post-processing notavailable in tensorboard, you can load results into python as [pandas](https://pandas.pydata.org/) dataframes. -The colab notebook with the full version of the code is available [here](https://colab.research.google.com/drive/1Wez1SA9PmNkCoYc8Fvl53bhU3F8OffGm) (use "Open in playground" button to get a runnable version) For instance, the following snippet: ```python @@ -106,12 +105,32 @@ The results are split into two groups based on batch size and are plotted on a s Showing all seeds on the same plot may be somewhat hard to comprehend and analyse. We can instead average over all seeds via the following command: + The lighter shade shows the standard deviation of data, and darker shade - -error in estimate of the mean (that is, standard deviation divided by square root of number of seeds) +error in estimate of the mean (that is, standard deviation divided by square root of number of seeds). Note that averaging over seeds requires resampling to a common grid, which, in turn, requires smoothing (using language of signal processing, we need to do low-pass filtering before resampling to avoid aliasing effects). You can change the amount of smoothing by adjusting `resample` and `smooth_step` arguments to achieve desired smoothing effect See the docstring of `plot_util` function for more info. +To plot both groups on the same graph, we can use the following: +```python +pu.plot_results(results, average_group=True, split_fn=lambda _: '') +``` +Option `split_fn=labmda _:'' ` effectively disables splitting, so that all curves end up on the same panel. + + + +Now, with many groups the overlapping shaded regions may start looking messy. We can disable either +light shaded region (corresponding to standard deviation of the curves in the group) or darker shaded region +(corresponding to the error in mean estimate) by using `shaded_std=False` or `shaded_err=False` options respectively. +For instance, + +```python +pu.plot_results(results, average_group=True, split_fn=lambda _: '', shaded_std=False) +``` +produces the following plot: + + diff --git a/setup.py b/setup.py index f77faf0..2e5e36a 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ extras = { 'test': [ 'filelock', 'pytest', + 'pytest-forked', 'atari-py' ], 'bullet': [ From 7bb405c7a7bb6e7a82291db05074e3c7524234bf Mon Sep 17 00:00:00 2001 From: pzhokhov Date: Wed, 7 Nov 2018 14:25:35 -0800 Subject: [PATCH 2/2] Update viz.md --- docs/viz/viz.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/viz/viz.md b/docs/viz/viz.md index 8d65816..a10a1f6 100644 --- a/docs/viz/viz.md +++ b/docs/viz/viz.md @@ -1,4 +1,4 @@ -# Loading and visualizing results +# Loading and visualizing results ([colab notebook](https://colab.research.google.com/drive/1Wez1SA9PmNkCoYc8Fvl53bhU3F8OffGm)) In order to compare performance of algorithms, we often would like to visualize learning curves (reward as a function of time steps), or some other auxiliary information about learning aggregated into a plot. Baselines repo provides tools for doing so in several different ways, depending on the goal. @@ -27,7 +27,7 @@ And you can now start TensorBoard with: tensorboard --logdir=$OPENAI_LOGDIR ``` -## Loading summaries of the results ([notebook](https://colab.research.google.com/drive/1Wez1SA9PmNkCoYc8Fvl53bhU3F8OffGm)) +## Loading summaries of the results If the summary overview provided by tensorboard is not sufficient, and you would like to either access to raw environment episode data, or use complex post-processing notavailable in tensorboard, you can load results into python as [pandas](https://pandas.pydata.org/) dataframes. For instance, the following snippet: