Commit 12502e31 authored by Steven Cordwell's avatar Steven Cordwell

[tests] Replace mdptoolbox.utils wth .util

The mdptoolbox.utils module was renamed to mdptoolbox.util and the tests
were still using the old name, Replace all occurances of utils with util
parent 610d0252
......@@ -111,11 +111,11 @@ def check(P, R):
--------
>>> import mdptoolbox, mdptoolbox.example
>>> P_valid, R_valid = mdptoolbox.example.rand(100, 5)
>>> mdptoolbox.utils.check(P_valid, R_valid) # Nothing should happen
>>> mdptoolbox.util.check(P_valid, R_valid) # Nothing should happen
>>>
>>> import numpy as np
>>> P_invalid = np.random.rand(5, 100, 100)
>>> mdptoolbox.utils.check(P_invalid, R_valid) # Raises an exception
>>> mdptoolbox.util.check(P_invalid, R_valid) # Raises an exception
"""
# Checking P
......
......@@ -27,7 +27,7 @@ def test_example_forest_R_shape():
def test_example_forest_check():
P, R = mdptoolbox.example.forest(10, 5, 3, 0.2)
assert mdptoolbox.utils.check(P, R) == None
assert mdptoolbox.util.check(P, R) == None
# exampleRand
......@@ -38,7 +38,7 @@ def test_example_rand_dense_R_shape():
assert (R_rand.shape == (ACTIONS, STATES, STATES))
def test_example_rand_dense_check():
assert mdptoolbox.utils.check(P_rand, R_rand) == None
assert mdptoolbox.util.check(P_rand, R_rand) == None
def test_example_rand_sparse_P_shape():
assert (len(P_rand_sparse) == ACTIONS)
......@@ -51,4 +51,4 @@ def test_example_rand_sparse_R_shape():
assert (R_rand_sparse[a].shape == (STATES, STATES))
def test_example_rand_sparse_check():
assert mdptoolbox.utils.check(P_rand_sparse, R_rand_sparse) == None
assert mdptoolbox.util.check(P_rand_sparse, R_rand_sparse) == None
......@@ -18,14 +18,14 @@ def test_check_square_stochastic_nonnegative_array_1():
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
R[:, a] = np.random.rand(STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_square_stochastic_nonnegative_array_2():
P = np.zeros((ACTIONS, STATES, STATES))
R = np.random.rand(ACTIONS, STATES, STATES)
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# check: P - square, stochastic and non-negative object np.arrays
......@@ -34,21 +34,21 @@ def test_check_P_square_stochastic_nonnegative_object_array():
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = np.eye(STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_object_matrix():
P = np.empty(ACTIONS, dtype=object)
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = np.matrix(np.eye(STATES))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_object_sparse():
P = np.empty(ACTIONS, dtype=object)
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = sp.sparse.eye(STATES, STATES).tocsr()
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# check: P - square, stochastic and non-negative lists
......@@ -57,21 +57,21 @@ def test_check_P_square_stochastic_nonnegative_list_array():
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P.append(np.eye(STATES))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_list_matrix():
P = []
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P.append(np.matrix(np.eye(STATES)))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_list_sparse():
P = []
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P.append(sp.sparse.eye(STATES, STATES).tocsr())
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# check: P - square, stochastic and non-negative dicts
......@@ -80,21 +80,21 @@ def test_check_P_square_stochastic_nonnegative_dict_array():
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = np.eye(STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_dict_matrix():
P = {}
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = np.matrix(np.eye(STATES))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_P_square_stochastic_nonnegative_dict_sparse():
P = {}
R = np.random.rand(STATES, ACTIONS)
for a in range(ACTIONS):
P[a] = sp.sparse.eye(STATES, STATES).tocsr()
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# check: R - square stochastic and non-negative sparse
......@@ -103,7 +103,7 @@ def test_check_R_square_stochastic_nonnegative_sparse():
R = sp.sparse.csr_matrix(np.random.rand(STATES, ACTIONS))
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# check: R - square, stochastic and non-negative object np.arrays
......@@ -113,7 +113,7 @@ def test_check_R_square_stochastic_nonnegative_object_array():
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
R[a] = np.random.rand(STATES, STATES)
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_R_square_stochastic_nonnegative_object_matrix():
P = np.zeros((ACTIONS, STATES, STATES))
......@@ -121,7 +121,7 @@ def test_check_R_square_stochastic_nonnegative_object_matrix():
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
R[a] = np.matrix(np.random.rand(STATES, STATES))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
def test_check_R_square_stochastic_nonnegative_object_sparse():
P = np.zeros((ACTIONS, STATES, STATES))
......@@ -129,7 +129,7 @@ def test_check_R_square_stochastic_nonnegative_object_sparse():
for a in range(ACTIONS):
P[a, :, :] = np.eye(STATES)
R[a] = sp.sparse.csr_matrix(np.random.rand(STATES, STATES))
assert (mdptoolbox.utils.check(P, R) == None)
assert (mdptoolbox.util.check(P, R) == None)
# checkSquareStochastic: square, stochastic and non-negative
......@@ -137,32 +137,32 @@ def test_checkSquareStochastic_square_stochastic_nonnegative_array():
P = np.random.rand(STATES, STATES)
for s in range(STATES):
P[s, :] = P[s, :] / P[s, :].sum()
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
def test_checkSquareStochastic_square_stochastic_nonnegative_matrix():
P = np.random.rand(STATES, STATES)
for s in range(STATES):
P[s, :] = P[s, :] / P[s, :].sum()
P = np.matrix(P)
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
def test_checkSquareStochastic_square_stochastic_nonnegative_sparse():
P = np.random.rand(STATES, STATES)
for s in range(STATES):
P[s, :] = P[s, :] / P[s, :].sum()
P = sp.sparse.csr_matrix(P)
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
# checkSquareStochastic: eye
def test_checkSquareStochastic_eye_array():
P = np.eye(STATES)
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
def test_checkSquareStochastic_eye_matrix():
P = np.matrix(np.eye(STATES))
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
def test_checkSquareStochastic_eye_sparse():
P = sp.sparse.eye(STATES, STATES).tocsr()
assert mdptoolbox.utils.checkSquareStochastic(P) == None
assert mdptoolbox.util.checkSquareStochastic(P) == None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment