-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified reset output, added rllab example
- Loading branch information
Showing
10 changed files
with
235 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import gym | ||
|
||
# Register gym environment. By specifying kwargs, | ||
# you are able to choose which patient to simulate. | ||
# patient_name must be 'adolescent#001' to 'adolescent#010', | ||
# or 'adult#001' to 'adult#010', or 'child#001' to 'child#010' | ||
from gym.envs.registration import register | ||
register( | ||
id='simglucose-adolescent2-v0', | ||
entry_point='simglucose.envs:T1DSimEnv', | ||
kwargs={'patient_name': 'adolescent#002'} | ||
) | ||
|
||
env = gym.make('simglucose-adolescent2-v0') | ||
|
||
observation, reward, done, info = env.reset() | ||
for t in range(100): | ||
env.render() | ||
print(observation) | ||
# Action in the gym environment is a scalar | ||
# representing the basal insulin, which differs from | ||
# the regular controller action outside the gym | ||
# environment (a tuple (basal, bolus)). | ||
# In the perfect situation, the agent should be able | ||
# to control the glucose only through basal instead | ||
# of asking patient to take bolus | ||
action = env.action_space.sample() | ||
observation, reward, done, info = env.step(action) | ||
if done: | ||
print("Episode finished after {} timesteps".format(t + 1)) | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from rllab.algos.ddpg import DDPG | ||
from rllab.envs.normalized_env import normalize | ||
from rllab.exploration_strategies.ou_strategy import OUStrategy | ||
from rllab.policies.deterministic_mlp_policy import DeterministicMLPPolicy | ||
from rllab.q_functions.continuous_mlp_q_function import ContinuousMLPQFunction | ||
from rllab.envs.gym_env import GymEnv | ||
from gym.envs.registration import register | ||
|
||
register( | ||
id='simglucose-adolescent2-v0', | ||
entry_point='simglucose.envs:T1DSimEnv', | ||
kwargs={'patient_name': 'adolescent#002'} | ||
) | ||
|
||
env = GymEnv('simglucose-adolescent2-v0') | ||
env = normalize(env) | ||
|
||
policy = DeterministicMLPPolicy( | ||
env_spec=env.spec, | ||
# The neural network policy should have two hidden layers, each with 32 hidden units. | ||
hidden_sizes=(32, 32) | ||
) | ||
|
||
es = OUStrategy(env_spec=env.spec) | ||
|
||
qf = ContinuousMLPQFunction(env_spec=env.spec) | ||
|
||
algo = DDPG( | ||
env=env, | ||
policy=policy, | ||
es=es, | ||
qf=qf, | ||
batch_size=32, | ||
max_path_length=100, | ||
epoch_length=1000, | ||
min_pool_size=10000, | ||
n_epochs=1000, | ||
discount=0.99, | ||
scale_reward=0.01, | ||
qf_learning_rate=1e-3, | ||
policy_learning_rate=1e-4 | ||
) | ||
algo.train() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.