Code Monkey home page Code Monkey logo

rfqi's Introduction

Robust Reinforcement Learning using Offline Data

Implementation of the algorithm Robust Fitted Q-Iteration (RFQI). RFQI is introduced in our paper Robust Reinforcement Learning using Offline Data (NeurIPS'22). This implementation of RFQI is based on the implementation of BCQ and the implementation of PQL.

Our method is tested in OpenAI gym discrete control task, CartPole, and two MuJoCo continuous control tasks, Hopper and HalfCheetah, using the D4RL benchmark. Thus it is required that MuJoCo and D4RL are both installed prior to using this repo.

Setup

Install requirements:

pip install -r requirements.txt

Next, you need to properly register the perturbed Gym environments which are placed under the folder perturbed_env. A recommended way to do this: first, place cartpole_perturbed.py under gym/envs/classic_control, hopper_perturbed.py and half_cheetah_perturbed.py under gym/envs/mujoco. Then add the following to _init_.py under gym/envs:

register(
    id="CartPolePerturbed-v0",
    entry_point="gym.envs.classic_control.cartpole_perturbed:CartPolePerturbedEnv",
    max_episode_steps=200,
    reward_threshold=195.0,
)
register(
    id="HopperPerturbed-v3",
    entry_point="gym.envs.mujoco.hopper_perturbed:HopperPerturbedEnv",
    max_episode_steps=1000,
    reward_threshold=3800.0,
)
register(
    id="HalfCheetahPerturbed-v3",
    entry_point="gym.envs.mujoco.half_cheetah_perturbed:HalfCheetahPerturbedEnv",
    max_episode_steps=1000,
    reward_threshold=4800.0,
)

You can test this by running:

import gym

gym.make('HopperPerturbed-v3')

After installing MuJoCo and D4RL, you can run the following script to download D4RL offline data and make it conform to our format, or you can directly go to TL;DR section below:

python load_d4rl_data.py

TL;DR

Here you can find shell scripts that take you directly from offline data generation to evaluation results.

To get all data, run

sh scripts/gen_all_data.sh

To get all results, run

sh scripts/run_cartpole.sh
sh scripts/run_hopper.sh
sh scripts/run_half_cheetah.sh

To evaluate all pre-trained models, run

sh scripts/eval_all.sh

Detailed instructions

To generate the epsilon-greedy dataset for CartPole-v0 with epsilon=0.3, run the following:

python generate_offline_data.py --env=CartPole-v0 --gendata_pol=ppo --eps=0.3

To generate the mixed dataset specified in Appendix E.1, run the following:

python generate_offline_data.py --env=Hopper-v3 --gendata_pol=sac --eps=0.3 --mixed=True

To train a RFQI policy on Hopper-v3 with d4rl-hopper-medium-v0 and uncertainty hyperparameter rho=0.5, please run:

python train_rfqi.py --env=Hopper-v3 --d4rl=True --rho=0.5

You can also train a RFQI policy on Hopper-v3 with mixed dataset and uncertainty hyperparameter rho=0.5 by running

python train_rfqi.py --env=Hopper-v3 --data_eps=0.3 --gendata_pol=sac --mixed=True --rho0.5

Miscellaneous

If you are using a remote machine to run this repo, please remember to assign a display/virtual display for the evaluation suite to properly generate gifs.

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.