Neng is a tool for computing Nash equilibrium in non-cooperative games (the strategic situation where contestants/players facing each other and not making any alliances). The game is represented by payoffs or outcomes for every combination of actions of every players. Every player has at least two strategies from which he can freely choose.
Nash equilibrium is presenting to us balanced situation, thus situation where no player wants to change his strategy. It’s important to tell that it does not tell us when the players has biggest outcomes.
mod: | neng Module |
---|
Main method of script. Based on information from arguments executes needed commands.
Parse arguments of script.
Returns: | parsed arguments |
---|---|
Return type: | dict |
Bases: object
Class Game wrap around all informations of noncooperative game. Also it provides basic analyzation of game, like pureBestResponse, if the game is degenerate. It also contains an algorithm for iterative elimination of strictly dominated strategies and can compute pure Nash equilibria using brute force.
>>> g = Game(game_str)
>>> ne = g.findEquilibria(method='pne')
>>> print g.printNE(ne)
Initialize basic attributes in Game
Parameters: |
|
---|
Iterative elimination of strictly dominated strategies.
Eliminates all strict dominated strategies, preserve self.array and self.shape in self.init_array and self.init_shape. Stores numbers of deleted strategies in self.deleted_strategies. Deletes strategies from self.array and updates self.shape.
Lyapunov function. If LyapunovFunction(p) == 0 then p is NE.
Beside this function we need that strategy_profile is in universum Delta (basicaly to have character of probabilities for each player). We can assure this with two methods: normalization and penalization.
Parameters: | strategy_profile_flat (list) – list of parameters to function |
---|---|
Returns: | value of Lyapunov function in given strategy profile |
Return type: | float |
Check if every strategy of strategy profile is best response to other strategies.
Parameters: | strategy_profile (StrategyProfile) – examined strategy profile |
---|---|
Returns: | whether every strategy is best response to others |
Return type: | bool |
Check if given container of strategy profiles contains only Nash equlibria.
Parameters: | nes – container of strategy profiles to examine |
---|---|
Returns: | whether every strategy profile pass NE test |
Return type: | boool |
Find all equilibria, using method
Parameters: | method (str, one of Game.METHODS) – of computing equilibria |
---|---|
Returns: | list of NE, if not found returns None |
Return type: | list of StrategyProfile |
Function computes pure Nash equlibria using brute force algorithm.
Returns: | list of StrategyProfile that are pure Nash equilibria |
---|---|
Return type: | list |
Degenerate game is defined for two-players games and there can be infinite number of mixed Nash equilibria.
Returns: | True if game is said as degenerated |
---|---|
Return type: | bool |
Check if strategy of player from strategy_profile is best response for opponent strategies.
Parameters: |
|
---|---|
Returns: | True if strategy_profile[players] is best response |
Return type: | bool |
Function to compute payoff of given strategy_profile.
Parameters: |
|
---|---|
Returns: | value of payoff |
Return type: | float |
Bases: object
Read games from different file formats (.nfg payoff, .nfg outcome), see http://www.gambit-project.org/doc/formats.html for more information.
Bases: object
Wraps information about strategy profile of game.
Parameters: |
|
---|
Copy constructor for StrategyProfile. Copies content of self to new object.
Returns: | StrategyProfile with same attributes |
---|
Normalizes values in StrategyProfile, values can’t be negative, bigger than one and sum of values of one strategy has to be 1.0.
Returns: | self |
---|
Bases: object
Class CMAES represent algorithm Covariance Matrix Adaptation - Evolution Strategy. It provides function minimization.
Parameters: |
|
---|
Termination criteria of method. They are checked every iteration. If any of them is true, computation should end.
Returns: | True if some termination criteria was met, False otherwise |
---|---|
Return type: | bool |
Method for actual function minimization. Iterates while not end. If unsuccess termination criteria is met then the method is restarted with doubled population. If the number of maximum evaluations is reached or the function is acceptable minimized, iterations ends and result is returned.
Return type: | scipy.optimize.Result |
---|
Init variables that can change after restart of method, basically that are dependent on lamda.
Parameters: |
|
---|
Generate new generation of individuals.
Return type: | np.array |
---|---|
Returns: | new generation |
Restart whole method to initial state, but with population multiplied by lamda_factor.
Parameters: | lamda_factor (int) – multiply factor |
---|
Bases: object
Class providing support enumeration method for finding all mixed Nash equilibria in two-players games.
Return set of equations for given player and combination of strategies for 2 players games in support_enumeration
This function returns matrix to compute (Nisan algorithm 3.4)
For given (subset of strategies) of player 1 we can write down next equations:
Where is probability of ith strategy, is payoff for player 2 with strategies , payoff for player 1
In matrix form (k = num_supports):
Analogically for result y for player 2 with payoff matrix A
Parameters: |
|
---|---|
Returns: | equation matrix for solving in np.linalg.solve |
Return type: | np.array |