Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AdvRL19
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flgw
AdvRL19
Commits
0d5ed41b
Commit
0d5ed41b
authored
6 years ago
by
Kate Rakelly
Browse files
Options
Downloads
Patches
Plain Diff
HW5c fix (nit): make `build_rnn` more clear, remove unneeded arg
parent
5e908c25
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hw5/meta/train_policy.py
+6
-3
6 additions, 3 deletions
hw5/meta/train_policy.py
with
6 additions
and
3 deletions
hw5/meta/train_policy.py
+
6
−
3
View file @
0d5ed41b
...
...
@@ -57,11 +57,14 @@ def build_mlp(x, output_size, scope, n_layers, size, activation=tf.tanh, output_
x
=
tf
.
layers
.
dense
(
inputs
=
x
,
units
=
output_size
,
activation
=
output_activation
,
name
=
'
fc{}
'
.
format
(
i
+
1
),
kernel_regularizer
=
regularizer
,
bias_regularizer
=
regularizer
)
return
x
def
build_rnn
(
x
,
h
,
output_size
,
scope
,
n_layers
,
size
,
gru_size
,
activation
=
tf
.
tanh
,
output_activation
=
None
,
regularizer
=
None
):
def
build_rnn
(
x
,
h
,
output_size
,
scope
,
n_layers
,
size
,
activation
=
tf
.
tanh
,
output_activation
=
None
,
regularizer
=
None
):
"""
builds a gated recurrent neural network
inputs are first embedded by an MLP then passed to a GRU cell
make MLP layers with `size` number of units
make the GRU with `output_size` number of units
arguments:
(see `build_policy()`)
...
...
@@ -96,7 +99,7 @@ def build_policy(x, h, output_size, scope, n_layers, size, gru_size, recurrent=T
"""
with
tf
.
variable_scope
(
scope
,
reuse
=
tf
.
AUTO_REUSE
):
if
recurrent
:
x
,
h
=
build_rnn
(
x
,
h
,
gru_size
,
scope
,
n_layers
,
size
,
gru_size
,
activation
=
activation
,
output_activation
=
output_activation
)
x
,
h
=
build_rnn
(
x
,
h
,
gru_size
,
scope
,
n_layers
,
size
,
activation
=
activation
,
output_activation
=
output_activation
)
else
:
x
=
tf
.
reshape
(
x
,
(
-
1
,
x
.
get_shape
()[
1
]
*
x
.
get_shape
()[
2
]))
x
=
build_mlp
(
x
,
gru_size
,
scope
,
n_layers
+
1
,
size
,
activation
=
activation
,
output_activation
=
activation
)
...
...
@@ -115,7 +118,7 @@ def build_critic(x, h, output_size, scope, n_layers, size, gru_size, recurrent=T
"""
with
tf
.
variable_scope
(
scope
,
reuse
=
tf
.
AUTO_REUSE
):
if
recurrent
:
x
,
h
=
build_rnn
(
x
,
h
,
gru_size
,
scope
,
n_layers
,
size
,
gru_size
,
activation
=
activation
,
output_activation
=
output_activation
,
regularizer
=
regularizer
)
x
,
h
=
build_rnn
(
x
,
h
,
gru_size
,
scope
,
n_layers
,
size
,
activation
=
activation
,
output_activation
=
output_activation
,
regularizer
=
regularizer
)
else
:
x
=
tf
.
reshape
(
x
,
(
-
1
,
x
.
get_shape
()[
1
]
*
x
.
get_shape
()[
2
]))
x
=
build_mlp
(
x
,
gru_size
,
scope
,
n_layers
+
1
,
size
,
activation
=
activation
,
output_activation
=
activation
,
regularizer
=
regularizer
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment