Skip to main content

DTR-Bench: An in silico Environment and Benchmark Platform for Reinforcement Learning Based Dynamic Treatment Regime

Project description

DTR-Bench

Status GitHub Issues GitHub Pull Requests License


An in silico Environment and Benchmark Platform for Reinforcement Learning Based Dynamic Treatment Regime

📝 Table of Contents

🧐 About

DTR-Bench (DTR-Bench) is an expanding reinforcement learning simulation platform with a unified pipeline including hyperparameter search, training, evaluation, and visualisation.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

  • Python 3.10: The project is developed using Python 3.10. It is recommended to use the same version to avoid compatibility issues.

Installing

  1. Install the DTR-Gym and the DTR-Bench
pip install dtrgym
  1. Install the required packages
cd SimMedEnv
pip install -r requirements.txt
  1. Test the installation
python test_installation.py

Running the getting started demo

We provide a simple example to show how to use the DTR-Bench. The example is in the get_start.py file.

You can run the example by:

python get_start.py

After running the example, you will see the following a plot like this. It shows the effect of the treatment given by the train RL policy in the simulation environment.

get_start

🎈 Module Description

Offpolicy RL Algorithms

The DTRBench provides a set of off-policy RL algorithms to train the RL policy in the simulation environments. These policies are developed based on Tianshou. The off-policy RL algorithms include:

Discrete RNN-based Continuous
DDQN DQN-rnn DDPG
DDQN-dueling DDQN-rnn TD3
DQN C51-rnn SAC
C51 discrete-SAC-rnn
discrete-SAC

Run RL Functions

Running functions in reinforcement learning, which includes hyperparameters grid-searching, policies training and evaluation, and baseline policies evaluation.

Visualisation

The DTRBench provides a standard visualisation tool to visualise the treatment effect of the trained RL policy in the simulation environments. It enables visualising the environment states, observations, actions, and the reward.

🔧 Usage

The DTR-Bench provides a set of APIs to interact with the simulation environments and the benchmark policies.

It can be used to:

  1. Create a simulation environment.
  2. Optimize the hyperparameters of the RL policy training.
  3. Train a RL policy in the simulation environments.
  4. Visualize the treatment effect of the trained RL policy.

Create a Simulation Environment

import gymnasium as gym
import DTRGym  # this line is necessary!

gym.make('AhnChemoEnv-discrete', n_act=11)

Please remember to import DTRGym to register the simulation environments.

Hyperparameters Search

  1. Discrete policies todo: change the cd path
cd SimMedEnv
export PYTHONPATH="."

python DTRBench/run_rl/online_discrete_search.py --policy_name=DQN --task SimGlucoseEnv --n_trials 100 --num_actions 11 --setting 1
  1. continuous policies
cd SimMedEnv
export PYTHONPATH="."

python DTRBench/run_rl/online_continuous_search.py --policy_name=DDPG --task OberstSepsisEnv --n_trials 100 --setting 1

Online Training and Testing

  1. Discrete Policies
cd SimMedEnv
export PYTHONPATH="."
conda activate torch

python DTRBench/run_rl/online_discrete_retrain.py --policy_name=DQN --task SimGlucoseEnv --num_actions 11 --setting 1
  1. Continuous Policies
cd SimMedEnv
export PYTHONPATH="."
conda activate torch

python DTRBench/run_rl/online_continuous_retrain.py --policy_name=DDPG --task SimGlucoseEnv --setting 1
  1. Baseline Policies (RandomPolicy, MaxPolicy, MinPolicy)
cd SimMedEnv
export PYTHONPATH="."
conda activate torch

python DTRBench/run_rl/online_baseline.py --task OberstSepsisEnv

Visualisation

cd SimMedEnv
export PYTHONPATH="."

python DTRBench/visual_fn/visual.py

Download the Hyperparameters and Test Results

The hyperparameters and test results are stored on Kaggle.

Reference

If you use the DTR-Bench in your research, please cite the following paper:

to be updated

✍️ Sepcial Thanks

Special thanks to the following contributors that make the DTR-Bench possible:

  • @Mingcheng Zhu - who developed DTRGym and produced extensive DTRBench experiments.
  • To be continued

🎉 Acknowledgement

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DTR-Bench-0.1.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

DTR_Bench-0.1.0-py3-none-any.whl (45.6 kB view details)

Uploaded Python 3

File details

Details for the file DTR-Bench-0.1.0.tar.gz.

File metadata

  • Download URL: DTR-Bench-0.1.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for DTR-Bench-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e5f5bdf1dad21bba9e08e2359b43a2337f4e83526963b05aad71daa10c44eb5
MD5 f72ca5be3ab59c525fdd2fd1ed2f22e1
BLAKE2b-256 f3adc84a0944f98bede9c803366596a8c895892b9cd0bd0586796f3abf1ccfec

See more details on using hashes here.

File details

Details for the file DTR_Bench-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: DTR_Bench-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 45.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for DTR_Bench-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b567d524ca43c08a113ec90f58305401ca675b6888529fb90841172a8e1b5c2
MD5 d521d959d3471991d97f2ec2af66adb0
BLAKE2b-256 8731e7d0c82a4fa30452ff987dcd9b6d4120793ed25e11a18ba5d6c7509c17ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page