Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
pymdptoolbox
Commits
9583a8ba
Commit
9583a8ba
authored
Mar 13, 2014
by
Steven Cordwell
Browse files
use a numpy array for the rewards as sparse rewards are not currently working in mdptoolbox
parent
50719db4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/examples/tictactoe.py
View file @
9583a8ba
# -*- coding: utf-8 -*-
import
numpy
as
np
from
scipy.sparse
import
dok_matrix
as
spdok
from
scipy.sparse
import
dok_matrix
from
mdptoolbox
import
mdp
...
...
@@ -44,8 +44,9 @@ def getLegalActions(state):
def
getTransitionAndRewardArrays
():
""""""
P
=
[
spdok
((
STATES
,
STATES
))
for
a
in
range
(
ACTIONS
)]
R
=
spdok
((
STATES
,
ACTIONS
))
P
=
[
dok_matrix
((
STATES
,
STATES
))
for
a
in
range
(
ACTIONS
)]
#R = spdok((STATES, ACTIONS))
R
=
np
.
zeros
((
STATES
,
ACTIONS
))
# Naive approach, iterate through all possible combinations
for
a
in
range
(
ACTIONS
):
for
s
in
range
(
STATES
):
...
...
@@ -63,7 +64,7 @@ def getTransitionAndRewardArrays():
P
[
a
][
s
,
s1
]
=
p
R
[
s
,
a
]
=
r
P
[
a
]
=
P
[
a
].
tocsr
()
R
=
R
.
to
csc
()
#
R = R.to
lil
()
return
(
P
,
R
)
def
getTransitionProbabilities
(
state
,
action
):
...
...
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