Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
submerged_kangaroo
Reinforcement
Commits
4486a5ab
Commit
4486a5ab
authored
Dec 04, 2020
by
anon
Browse files
Approximate QLearning Agent
parent
70e6164f
Changes
1
Hide whitespace changes
Inline
Side-by-side
qlearningAgents.py
View file @
4486a5ab
...
...
@@ -190,15 +190,22 @@ class ApproximateQAgent(PacmanQAgent):
Should return Q(state,action) = w * featureVector
where * is the dotProduct operator
"""
"*** YOUR CODE HERE ***"
util
.
raiseNotDefined
()
features
=
self
.
featExtractor
.
getFeatures
(
state
,
action
)
qVal
=
0
for
feat
,
val
in
features
.
items
():
qVal
+=
val
*
self
.
weights
[
feat
]
return
qVal
def
update
(
self
,
state
,
action
,
nextState
,
reward
):
"""
Should update your weights based on transition
"""
"*** YOUR CODE HERE ***"
util
.
raiseNotDefined
()
features
=
self
.
featExtractor
.
getFeatures
(
state
,
action
)
difference
=
(
reward
+
self
.
discount
*
self
.
getValue
(
nextState
))
-
self
.
getQValue
(
state
,
action
)
for
feat
,
val
in
features
.
items
():
self
.
weights
[
feat
]
+=
self
.
alpha
*
difference
*
val
def
final
(
self
,
state
):
"Called at the end of each game."
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment