Skip to content

Commit

Permalink
RFC: Replace rand() and random_sample() with random() in game_theory (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
oyamad committed Nov 24, 2022
1 parent 179eb87 commit 57b1d1e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion quantecon/game_theory/brd.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def play(self, action, action_dist, **options):
tol = options.get('tol', None)
random_state = check_random_state(options.get('random_state', None))

if random_state.rand() < self.epsilon: # Mutation
if random_state.random() < self.epsilon: # Mutation
action_dist[action] -= 1
random_state = check_random_state(random_state)
next_action = self.player.random_choice(random_state=random_state)
Expand Down
4 changes: 2 additions & 2 deletions quantecon/game_theory/game_generators/bimatrix_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def unit_vector_game(n, avoid_pure_nash=False, random_state=None):
"""
random_state = check_random_state(random_state)
payoff_arrays = (np.zeros((n, n)), random_state.random_sample((n, n)))
payoff_arrays = (np.zeros((n, n)), random_state.random((n, n)))

if not avoid_pure_nash:
ones_ind = random_state.randint(n, size=n)
Expand All @@ -603,7 +603,7 @@ def unit_vector_game(n, avoid_pure_nash=False, random_state=None):
nums_suboptimal = is_suboptimal.sum(axis=1)

while (nums_suboptimal==0).any():
payoff_arrays[1][:] = random_state.random_sample((n, n))
payoff_arrays[1][:] = random_state.random((n, n))
payoff_arrays[1].max(axis=0, out=maxes)
np.less(payoff_arrays[1], maxes, out=is_suboptimal)
is_suboptimal.sum(axis=1, out=nums_suboptimal)
Expand Down
2 changes: 1 addition & 1 deletion quantecon/game_theory/logitdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _play(self, player_ind, actions, random_state):
tuple(actions[i+1:]) + tuple(actions[:i])

cdf = self.players[i].logit_choice_cdfs[opponent_actions]
random_value = random_state.rand()
random_value = random_state.random()
next_action = cdf.searchsorted(random_value*cdf[-1], side='right')

return next_action
Expand Down
4 changes: 2 additions & 2 deletions quantecon/game_theory/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def random_game(nums_actions, random_state=None):

random_state = check_random_state(random_state)
players = [
Player(random_state.random_sample(nums_actions[i:]+nums_actions[:i]))
Player(random_state.random(nums_actions[i:]+nums_actions[:i]))
for i in range(N)
]
g = NormalFormGame(players)
Expand Down Expand Up @@ -146,7 +146,7 @@ def _random_mixed_actions(out, random_state):
if n == 1:
x[0] = 1
else:
r = random_state.random_sample(size=n-1)
r = random_state.random(size=n-1)
_probvec_cpu(r, x)
return out

Expand Down
2 changes: 1 addition & 1 deletion quantecon/game_theory/tests/test_support_enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def random_skew_sym(n, m=None, random_state=None):
if m is None:
m = n
random_state = check_random_state(random_state)
B = random_state.random_sample((n, m))
B = random_state.random((n, m))
A = np.empty((n+m, n+m))
A[:n, :n] = 0
A[n:, n:] = 0
Expand Down

0 comments on commit 57b1d1e

Please sign in to comment.