Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
lli
YM-Seminar
Commits
f83a4918
Commit
f83a4918
authored
May 04, 2021
by
lli
Browse files
update
parent
1059735f
Changes
1
Hide whitespace changes
Inline
Side-by-side
algorithms/a2c.py
View file @
f83a4918
...
...
@@ -55,7 +55,7 @@ class PolicyNetwork(nn.Module):
loss
=
0
for
log_prob
,
value
,
Gt
in
zip
(
log_probs
,
state_values
,
returns
):
advantage
=
Gt
-
value
.
item
()
policy_loss
=
(
-
log_prob
*
advantage
)
policy_loss
=
-
log_prob
*
advantage
Gt
=
torch
.
unsqueeze
(
Gt
,
0
)
value_loss
=
F
.
smooth_l1_loss
(
value
,
Gt
)
...
...
@@ -65,8 +65,7 @@ class PolicyNetwork(nn.Module):
self
.
optimizer
.
zero_grad
()
loss
.
backward
()
self
.
optimizer
.
step
()
return
loss
# self.scheduler.step()
return
loss
.
item
()
def
get_action
(
self
,
state
):
action_probs
,
state_value
=
self
.
predict
(
state
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment