Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulhendricks/gym-r
An R package providing access to the OpenAI Gym API
https://github.com/paulhendricks/gym-r
openai-gym openai-universe r reinforcement-learning
Last synced: 6 days ago
JSON representation
An R package providing access to the OpenAI Gym API
- Host: GitHub
- URL: https://github.com/paulhendricks/gym-r
- Owner: paulhendricks
- Created: 2016-10-20T18:06:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-01T19:46:17.000Z (over 7 years ago)
- Last Synced: 2024-10-03T23:35:07.413Z (about 1 month ago)
- Topics: openai-gym, openai-universe, r, reinforcement-learning
- Language: R
- Homepage:
- Size: 60.5 KB
- Stars: 21
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
gym
===[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/gym)](http://cran.r-project.org/package=gym) [![Downloads from the RStudio CRAN mirror](http://cranlogs.r-pkg.org/badges/gym)](http://cran.rstudio.com/package=gym) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active)
[OpenAI Gym](https://github.com/openai/gym) is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This R package is a wrapper for the [OpenAI Gym API](https://github.com/openai/gym-http-api), and enables access to an ever-growing variety of environments.
Installation
------------You can install the latest development version from CRAN:
``` r
install.packages("gym")
```Or from GitHub with:
``` r
if (packageVersion("devtools") < 1.6) {
install.packages("devtools")
}
devtools::install_github("paulhendricks/gym-R", subdir = "R")
```If you encounter a clear bug, please file a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on [GitHub](https://github.com/paulhendricks/gym/issues).
Getting started
---------------### Setting up the server
To download the code and install the requirements, you can run the following shell commands:
``` bash
git clone https://github.com/openai/gym-http-api
cd gym-http-api
pip install -r requirements.txt
```This code is intended to be run locally by a single user. The server runs in python.
To start the server from the command line, run this:
``` bash
python gym_http_server.py
```For more details, please see here: .
### Running an example in R
In a separate R terminal, you can then try running the example agent and see what happens:
``` r
library(gym)remote_base <- "http://127.0.0.1:5000"
client <- create_GymClient(remote_base)
print(client)# Create environment
env_id <- "CartPole-v0"
instance_id <- env_create(client, env_id)
print(instance_id)# List all environments
all_envs <- env_list_all(client)
print(all_envs)# Set up agent
action_space_info <- env_action_space_info(client, instance_id)
print(action_space_info)
agent <- random_discrete_agent(action_space_info[["n"]])# Run experiment, with monitor
outdir <- "/tmp/random-agent-results"
env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE)episode_count <- 100
max_steps <- 200
reward <- 0
done <- FALSEfor (i in 1:episode_count) {
ob <- env_reset(client, instance_id)
for (i in 1:max_steps) {
action <- env_action_space_sample(client, instance_id)
results <- env_step(client, instance_id, action, render = TRUE)
if (results[["done"]]) break
}
}# Dump result info to disk
env_monitor_close(client, instance_id)
```Citation
--------To cite package ‘gym’ in publications use:
Paul Hendricks (2016). gym: Provides Access to the OpenAI Gym API. R package version 0.1.0. https://CRAN.R-project.org/package=gym
A BibTeX entry for LaTeX users is
@Manual{,
title = {gym: Provides Access to the OpenAI Gym API},
author = {Paul Hendricks},
year = {2016},
note = {R package version 0.1.0},
url = {https://CRAN.R-project.org/package=gym},
}