Git Product home page Git Product logo

clj-gym's Introduction

clj-gym

Clojure bindings for OpenAI's gym-http-api server.

Installation

With Leiningen/Boot:

[mthomure/clj-gym "0.1.1-SNAPSHOT"]

Usage

The clj-gym.core namespace follows OpenAI's API description.

> (require '[clj-gym.core :as g])

> (g/create "CartPole-v0")
"2f7eef5a"

> (g/envs)
{"2f7eef5a" "CartPole-v0"}

> (g/reset "2f7eef5a)
{:observation [0.023710455775827657 0.019351021639290936 0.011374305124354243 -0.016630857354495036]}

> (g/step "2f7eef5a" 0)
{:done false, :info {}, :observation [0.024097476208613477 -0.1759321880637575 0.011041687977264342 0.2796189824583605], :reward 1.0}

Get an idea of valid actions and observations using:

> (g/action-space "2f7eef5a")
{:n 2, :name "Discrete"}

> (g/observation-space "2f7eef5a")
{:high [4.8 3.4028234663852886E38 0.41887902047863906 3.4028234663852886E38], :low [-4.8 -3.4028234663852886E38 -0.41887902047863906 -3.4028234663852886E38], :name "Box", :shape [4]}

Talking to a remote server instance? Use the *url* dynamic variable.

> (binding [g/*url* "http://HOST:PORT"] (g/envs))

Running the Server

The server is available from DockerHub. To render a video and access it in the monitor files:

docker run -p 5000:5000 -v /tmp:/tmp mthomure/openai-gym-server

Then run in a repl:

(let [id (g/create "CartPole-v0")]
  (g/start-monitor id "/tmp/monitor" :video-callable true)
  (g/reset id)
  (g/step id 0 :render? true)
  (g/close-monitor id))

The monitor files should be in /tmp/monitor on the host filesystem. Note the use of :video-callable and :render?, above.

Warning: If you start-monitor with an existing directory, you'll get an HTTP 500 error. In this case, use :force? or :resume?.

Rebuilding the Docker Image

cd docker/
docker build -t mthomure/openai-gym-server .
docker login
docker push mthomure/openai-gym-server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.