-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some documentation updates (not complete)
- Loading branch information
1 parent
c4b0521
commit 1b5338b
Showing
2 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.. _soft q imitation learning docs: | ||
|
||
======================= | ||
Soft Q Imitation Learning (SQIL) | ||
======================= | ||
|
||
<add description of SQIL> | ||
|
||
Example | ||
======= | ||
|
||
Detailed example notebook: :doc:`../tutorials/10_train_sqil` | ||
|
||
.. testcode:: | ||
:skipif: skip_doctests | ||
|
||
import numpy as np | ||
import gym | ||
from stable_baselines3 import PPO | ||
from stable_baselines3.common.evaluation import evaluate_policy | ||
from stable_baselines3.common.vec_env import DummyVecEnv | ||
from stable_baselines3.ppo import MlpPolicy | ||
|
||
from imitation.algorithms import sqil | ||
from imitation.data import rollout | ||
from imitation.data.wrappers import RolloutInfoWrapper | ||
|
||
rng = np.random.default_rng(0) | ||
env = gym.make("CartPole-v1") | ||
expert = PPO(policy=MlpPolicy, env=env) | ||
expert.learn(1000) | ||
|
||
rollouts = rollout.rollout( | ||
expert, | ||
DummyVecEnv([lambda: RolloutInfoWrapper(env)]), | ||
rollout.make_sample_until(min_timesteps=None, min_episodes=50), | ||
rng=rng, | ||
) | ||
transitions = rollout.flatten_trajectories(rollouts) | ||
|
||
sqil_trainer = sqil.SQIL( | ||
venv=DummyVecEnv([lambda: env]), | ||
demonstrations=transitions, | ||
policy="MlpPolicy", | ||
) | ||
sqil_trainer.train(n_epochs=1) | ||
reward, _ = evaluate_policy(sqil_trainer.policy, env, 10) | ||
print("Reward:", reward) | ||
|
||
.. testoutput:: | ||
:hide: | ||
|
||
... | ||
|
||
API | ||
=== | ||
.. autoclass:: imitation.algorithms.sqil.SQIL | ||
:members: | ||
:noindex: |