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
0e1da2d7
Commit
0e1da2d7
authored
May 16, 2013
by
Steven Cordwell
Browse files
initial changes to support sql examples
parent
a6c17f16
Changes
2
Hide whitespace changes
Inline
Side-by-side
mdp.py
View file @
0e1da2d7
...
...
@@ -92,13 +92,15 @@ http://www.inra.fr/mia/T/MDPtoolbox/.
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import
sqlite3
from
math
import
ceil
,
log
,
sqrt
from
random
import
randint
,
random
from
time
import
time
from
numpy
import
absolute
,
array
,
diag
,
empty
,
matrix
,
mean
,
mod
,
multiply
from
numpy
import
ndarray
,
ones
,
zeros
from
numpy.random
import
rand
from
numpy
import
absolute
,
arange
,
array
,
diag
,
empty
,
matrix
,
mean
,
mod
from
numpy
import
multiply
,
ndarray
,
ones
,
zeros
from
numpy.random
import
permutation
,
rand
from
scipy.sparse
import
csr_matrix
as
sparse
# __all__ = ["check", "checkSquareStochastic"]
...
...
@@ -493,7 +495,7 @@ def exampleForest(S=3, r1=4, r2=2, p=0.1):
# we want to return the generated transition and reward matrices
return
(
P
,
R
)
def
exampleRand
(
S
,
A
,
is_sparse
=
False
,
mask
=
None
):
def
exampleRand
(
S
,
A
,
is_sparse
=
False
,
is_sqlite
=
False
,
mask
=
None
):
"""Generate a random Markov Decision Process.
Parameters
...
...
@@ -540,7 +542,21 @@ def exampleRand(S, A, is_sparse=False, mask=None):
except
AttributeError
:
raise
TypeError
(
mdperr
[
"mask_numpy"
])
# generate the transition and reward matrices based on S, A and mask
if
is_sparse
:
if
is_sqlite
:
# to be usefully represented as a sparse matrix, the number of nonzero
# entries should be less than 1/3 of dimesion of the matrix, so (SxS)/3
conn
=
sqlite3
.
connect
(
"mdp.db"
)
with
conn
:
c
=
conn
.
cursor
()
for
a
in
range
(
A
):
c
.
execute
(
"CREATE TABLE "
)
for
s
in
range
(
S
):
n
=
randint
(
1
,
int
(
S
/
3
)
-
1
)
row
=
tuple
([
s
]
*
n
)
col
=
tuple
(
permutation
(
arange
(
S
))[
0
:
n
])
val
=
rand
(
n
)
val
=
tuple
(
val
/
val
.
sum
())
elif
is_sparse
:
# definition of transition matrix : square stochastic matrix
P
=
empty
(
A
,
dtype
=
object
)
# definition of reward matrix (values between -1 and +1)
...
...
util.py
View file @
0e1da2d7
# -*- coding: utf-8 -*-
"""
Created on Wed May 15 17:09:35 2013
@author: steve
"""
import
sqlite3
class
DatabaseManager
(
object
):
""""""
def
__init__
(
self
,
db
):
self
.
conn
=
sqlite3
.
connect
(
db
)
self
.
cur
=
self
.
conn
.
cursor
()
def
__del__
(
self
):
self
.
conn
.
close
()
def
argmax
(
self
,
axis
=
None
):
pass
def
dot
(
self
,
a
,
b
):
pass
def
max
(
self
,
axis
=
None
):
pass
\ No newline at end of file
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