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
a1b2f328
Commit
a1b2f328
authored
May 16, 2013
by
Steven Cordwell
Browse files
attempts to speed up sql example code
parent
0e1da2d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
mdp.py
View file @
a1b2f328
...
...
@@ -95,12 +95,12 @@ http://www.inra.fr/mia/T/MDPtoolbox/.
import
sqlite3
from
math
import
ceil
,
log
,
sqrt
from
random
import
randint
,
random
from
random
import
random
from
time
import
time
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
numpy.random
import
permutation
,
rand
,
randint
from
scipy.sparse
import
csr_matrix
as
sparse
# __all__ = ["check", "checkSquareStochastic"]
...
...
@@ -549,13 +549,14 @@ def exampleRand(S, A, is_sparse=False, is_sqlite=False, mask=None):
with
conn
:
c
=
conn
.
cursor
()
for
a
in
range
(
A
):
c
.
execute
(
"CREATE TABLE
"
)
c
.
execute
(
"CREATE TABLE
p%s (row INTEGER, col INTEGER, val REAL)"
%
a
)
for
s
in
range
(
S
):
n
=
randint
(
1
,
int
(
S
/
3
)
-
1
)
row
=
tuple
([
s
]
*
n
)
col
=
tuple
(
permutation
(
arange
(
S
))[
0
:
n
])
n
=
randint
(
1
,
S
//
3
)
row
=
(
s
,)
*
n
col
=
tuple
(
permutation
(
arange
(
S
))[
0
:
n
]
.
tolist
()
)
val
=
rand
(
n
)
val
=
tuple
(
val
/
val
.
sum
())
# tuple(np.array.tolist()) is faster than tuple(np.array)
val
=
tuple
((
val
/
val
.
sum
()).
tolist
())
elif
is_sparse
:
# definition of transition matrix : square stochastic matrix
P
=
empty
(
A
,
dtype
=
object
)
...
...
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