项目作者: gxywy

项目描述 :
:sparkles: A plotter for reinforcement learning (RL)
高级语言: Python
项目地址: git://github.com/gxywy/rl-plotter.git
创建时间: 2019-11-09T08:08:48Z
项目社区:https://github.com/gxywy/rl-plotter

开源协议:GNU General Public License v3.0

下载


rl-plotter

PyPI GitHub GitHub last commit

README | 中文文档

This is a simple tool which can plot learning curves easily for reinforcement learning (RL)

Installation

from PIP

  1. pip install rl_plotter

from source

  1. python setup.py install

Usage

1. add basic logger

Add our logger in your code of evaluation (Recommend)

  1. from rl_plotter.logger import Logger
  2. logger = Logger(exp_name="your_exp_name", env_name, seed, locals())
  3. ····
  4. logger.update(score=evaluation_score_list, total_steps=current_training_steps)

or just use OpenAI-spinningup to log (Support)

or you can use OpenAI-baseline bench.Monitor (Not Recommend)

  1. env = logger.monitor_env(env)

2. track other variables (Optional)

if you want to track other variables, you can use our custom_logger:

  1. custom_logger=logger.new_custom_logger(filename, fieldnames=["variable 1", "variable 2", ..., "variable n"])
  2. custom_logger.update(fieldvalues=variable_value_list, total_steps=current_training_steps)

3. plot the results

After the training or when you are training your agent, you can plot the learning curves in this way:

  • switch to log directory or multi log’s parent directory (default: ./)

  • run command to plot:

  1. rl_plotter --save --show

You can also use seaborn kernel to get the same plot style as OpenAI-spinningup:

  1. rl_plotter_spinup --save --show

Example

1. commonly used commands

  1. rl_plotter --save --show --filter HalfCheetah
  2. rl_plotter --save --show --filter Ant --avg_group --shaded_std
  3. rl_plotter --save --show --filter Swimmer --avg_group --shaded_std --shaded_err
  4. rl_plotter --save --show --filter Walker2d --filename progress.txt --xkey TotalEnvInteracts --ykey AverageEpRet

2. practical examples

  1. rl_plotter --show --save --avg_group --shaded_err --shaded_std
  1. rl_plotter --show --save --avg_group --shaded_err --shaded_std --filename q --filters Walker HalfCheetah --ykey bias real_q --yduel --style default --smooth 0

3. more specific usage

you can find all parameters which can custom the style of your curves using help

  1. rl_plotter --help
  1. optional arguments:
  2. -h, --help show this help message and exit
  3. --fig_length matplotlib figure length (default: 8)
  4. --fig_width matplotlib figure width (default: 6)
  5. --style matplotlib figure style (default: seaborn)
  6. --title matplotlib figure title (default: None)
  7. --xlabel matplotlib figure xlabel
  8. --xkey x-axis key in csv file (default: l)
  9. --ykey y-axis key in csv file (support multi) (default: r)
  10. --yduel duel y axis (use if has two ykeys)
  11. --ylabel matplotlib figure ylabel
  12. --smooth smooth radius of y axis (default: 10)
  13. --resample if not zero, size of the uniform grid in x direction
  14. to resample onto. Resampling is performed via
  15. symmetric EMA smoothing (see the docstring for
  16. symmetric_ema). Default is zero (no resampling). Note
  17. that if average_group is True, resampling is
  18. necessary; in that case, default value is 512.
  19. (default: 512)
  20. --smooth_step when resampling (i.e. when resample > 0 or
  21. average_group is True), use this EMA decay parameter
  22. (in units of the new grid step). See docstrings for
  23. decay_steps in symmetric_ema or one_sided_ema functions.
  24. (default: 1.0)
  25. --avg_group average the curves in the same group and plot the mean
  26. --shaded_std shaded region corresponding to standard deviation of the group
  27. --shaded_err shaded region corresponding to error in mean estimate of the group
  28. --legend_loc location of legend
  29. --legend_outside place the legend outside of the figure
  30. --borderpad borderpad of legend (default: 0.5)
  31. --labelspacing labelspacing of legend (default: 0.5)
  32. --no_legend_group_num don't show num of group in legend
  33. --time enable this will activate parameters about time
  34. --time_unit parameters about time, x axis time unit (default: h)
  35. --time_interval parameters about time, x axis time interval (default: 1)
  36. --xformat x-axis format
  37. --xlim x-axis limitation (default: None)
  38. --log_dir log dir (default: ./)
  39. --filters filter of dirname
  40. --filename csv filename
  41. --show show figure
  42. --save save figure
  43. --dpi figure dpi (default: 400)

Features

  • custom logger, style, key, label, x-axis formatter, and so on …
  • filter of directory name
  • multi-experiment plotter
  • multiple plotting kernels (native matplotlib plotting or seaborn plotting)
  • compatible with OpenAI-baseline monitor and OpenAI-spinningup
  • corresponding color for specific experiment
  • multi y key & duel y legend

Citing the Project

If using this repository for your research or publication, please cite:

  1. @misc{rl-plotter,
  2. author = {Xiaoyu Gong},
  3. title = {RL-plotter: A plotter for reinforcement learning},
  4. year = {2020},
  5. publisher = {GitHub},
  6. journal = {GitHub repository},
  7. howpublished = {\url{https://github.com/gxywy/rl-plotter}},
  8. }

Acknowledgment

The core of this tool is inspired by baselines/plot_util.py and spinningup/plot.py