|
2 | 2 | Generate random NormalFormGame instances.
|
3 | 3 |
|
4 | 4 | """
|
| 5 | + |
5 | 6 | import numpy as np
|
6 | 7 |
|
7 | 8 | from .normal_form_game import Player, NormalFormGame
|
8 | 9 | from ..util import check_random_state
|
| 10 | +from ..random import probvec |
9 | 11 |
|
10 | 12 |
|
11 | 13 | def random_game(nums_actions, random_state=None):
|
@@ -92,3 +94,60 @@ def covariance_game(nums_actions, rho, random_state=None):
|
92 | 94 | random_state.multivariate_normal(mean, cov, nums_actions)
|
93 | 95 | g = NormalFormGame(payoff_profile_array)
|
94 | 96 | return g
|
| 97 | + |
| 98 | + |
| 99 | +def random_pure_actions(nums_actions, random_state=None): |
| 100 | + """ |
| 101 | + Return a tuple of random pure actions (integers). |
| 102 | +
|
| 103 | + Parameters |
| 104 | + ---------- |
| 105 | + nums_actions : tuple(int) |
| 106 | + Tuple of the numbers of actions, one for each player. |
| 107 | +
|
| 108 | + random_state : int or np.random.RandomState, optional |
| 109 | + Random seed (integer) or np.random.RandomState instance to set |
| 110 | + the initial state of the random number generator for |
| 111 | + reproducibility. If None, a randomly initialized RandomState is |
| 112 | + used. |
| 113 | +
|
| 114 | + Returns |
| 115 | + ------- |
| 116 | + action_profile : Tuple(int) |
| 117 | + Tuple of actions, one for each player. |
| 118 | +
|
| 119 | + """ |
| 120 | + random_state = check_random_state(random_state) |
| 121 | + action_profile = tuple( |
| 122 | + [random_state.randint(num_actions) for num_actions in nums_actions] |
| 123 | + ) |
| 124 | + return action_profile |
| 125 | + |
| 126 | + |
| 127 | +def random_mixed_actions(nums_actions, random_state=None): |
| 128 | + """ |
| 129 | + Return a tuple of random mixed actions (vectors of floats). |
| 130 | +
|
| 131 | + Parameters |
| 132 | + ---------- |
| 133 | + nums_actions : tuple(int) |
| 134 | + Tuple of the numbers of actions, one for each player. |
| 135 | +
|
| 136 | + random_state : int or np.random.RandomState, optional |
| 137 | + Random seed (integer) or np.random.RandomState instance to set |
| 138 | + the initial state of the random number generator for |
| 139 | + reproducibility. If None, a randomly initialized RandomState is |
| 140 | + used. |
| 141 | +
|
| 142 | + Returns |
| 143 | + ------- |
| 144 | + action_profile : tuple(ndarray(float, ndim=1)) |
| 145 | + Tuple of mixed_actions, one for each player. |
| 146 | +
|
| 147 | + """ |
| 148 | + random_state = check_random_state(random_state) |
| 149 | + action_profile = tuple( |
| 150 | + [probvec(1, num_actions, random_state).ravel() |
| 151 | + for num_actions in nums_actions] |
| 152 | + ) |
| 153 | + return action_profile |
0 commit comments