Utilities¶
Helper functions.
—
Initial states
- popgames.utilities.sample_initial_states(population_game, num, seed=None)[source]¶
Sample strategic distributions uniformly at random, e.g., as initial states of
Simulator.run_ensemble.The strategic distribution of each population is sampled uniformly on its simplex (scaled by the mass of the population), independently of the other populations.
- Parameters:
population_game (PopulationGame) – The population game.
num (int) – The number of strategic distributions.
seed (Union[int, np.random.Generator], optional) – Seed or random number generator. Defaults to None, in which case NumPy’s global random state is used (see
np.random.seed).
- Returns:
The strategic distributions, of shape
(num, n, 1).- Return type:
np.ndarray
Examples
>>> import numpy as np >>> import popgames as pg >>> from popgames.utilities import sample_initial_states >>> game = pg.SinglePopulationGame(num_strategies=3, fitness_function=lambda x: -x) >>> x0s = sample_initial_states(game, num=5, seed=0) >>> x0s.shape (5, 3, 1) >>> bool(np.allclose(x0s.sum(axis=1), 1.0)) True