forked from ryanjulian/rllab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trpo_cartpole_tf.py
47 lines (40 loc) · 1.3 KB
/
trpo_cartpole_tf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from sandbox.rocky.tf.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.box2d.cartpole_env import CartpoleEnv
from rllab.envs.normalized_env import normalize
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import ConjugateGradientOptimizer
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import FiniteDifferenceHvp
from sandbox.rocky.tf.policies.gaussian_mlp_policy import GaussianMLPPolicy
from sandbox.rocky.tf.envs.base import TfEnv
from rllab.misc.instrument import stub, run_experiment_lite
def run_task(*_):
env = TfEnv(normalize(CartpoleEnv()))
policy_parameters = {
"name": "policy",
"env_spec": env.spec,
"policy_type": GaussianMLPPolicy,
"hidden_sizes": (32, 32)
}
policy = GaussianMLPPolicy(policy_parameters)
baseline = LinearFeatureBaseline(env_spec=env.spec)
algo = TRPO(
env=env,
policy=policy,
policy_parameters=policy_parameters,
baseline=baseline,
batch_size=4000,
max_path_length=100,
n_itr=40,
discount=0.99,
step_size=0.01,
plot=True,
# optimizer=ConjugateGradientOptimizer(hvp_approach=FiniteDifferenceHvp(base_eps=1e-5))
)
algo.train()
run_experiment_lite(
run_task,
n_parallel=4,
snapshot_mode="last",
seed=1,
plot=True,
)