NAME
Game::Theory::TwoPersonMatrix - Reduce & analyze a 2 person matrix game
VERSION
version 0.04
SYNOPSIS
use Game::Theory::TwoPersonMatrix;
my $g = Game::Theory::TwoPersonMatrix->new(
1 => { strategy => { 1 => \@s1, 2 => \@s2, } },
2 => { strategy => { 1 => \@t1, 2 => \@t2, } },
);
$g->reduce(2, 1);
$g->reduce(1, 2);
my $m = $g->mixed;
print Dumper $m;
my $n = $g->nash;
print Dumper $n;
DESCRIPTION
A Game::Theory::TwoPersonMatrix
reduces and analyzes a two person matrix game of player names, strategies and numerical utilities.
* This module depends on Math::Calculus::Differentiate
, which in turn depends on Math::Calculus::Expression
- a module not present on metacpan.org. These must be downloaded and built by hand. The latter may be obtained at http://search.cpan.org/~jonathan/Math-Calculus-Expression-0.2.2.
The players must have the same number of strategies, and each strategy must have the same size utility vectors as all the others.
Player strategies are given by a 2D matrix of utilities such that,
[ [ u1, u2 .. un] .. [ v1, v2 .. vn ] ]
Where each "ui" is a utility measure for the strategy "U."
Player 1 and 2 are the "row" and "column" players, respectively. This is due to the tabular format of a matrix game:
Player 2
--------
Strategy 1 2
Player | 1 1,0 1,3
1 | 3 0,2 2,4
The same game in "linear form" is:
P1: { 1: [1,1], 3: [0,2] }
P2: { 1: [0,2], 2: [3,4] }
In "bimatrix" form, the game is:
| 1 1 | | 0 2 |
P1 = | 0 2 | P2 = | 3 4 |
METHODS
new()
my $g = Game::Theory::TwoPersonMatrix->new(%args);
Create a new Game::Theory::TwoPersonMatrix
object.
Player defaults:
1 => { 1 => [1,0], 2 => [0,1] }, # The "row player"
2 => { 1 => [1,0], 2 => [0,1] } # The "column player"
reduce()
$g->reduce_game(1, 2); # Player 1 given opponent 2
print Dumper $g->{1}, $g->{2};
$g->reduce_game(2, 1); # Player 2 given opponent 1
print Dumper $g->{1}, $g->{2};
Reduce the game by elimination of a single strictly dominated strategy of the player.
Use repeated application of this method to solve a game, or verify that it is insoluble.
nash()
my $equilibria = $g->nash;
print Dumper $equilibria;
Find the Nash equilibria.
mixed()
my $p = $g->mixed;
print Dumper $p;
Example:
| 0 3 | | 3 0 |
A = | 2 1 | B = | 1 2 |
Where A is the "row player" and B is the "column player."
The payoff probabilities for their mixed strategies are,
PA = 0*p1*q1 + 3*p1*q2 + 2*p2*q1 + 1*p2*q2
PB = 3*p1*q1 + 0*p1*q2 + 1*p2*q1 + 2*p2*q2
Through substitution, simplification and differentiation, these equations become,
PA' = 3*(1 - q) - 2*q - 1*(1 - q)
PB' = 3*p + 1 - p - 2*(1 - p)
Which can be further simplified (by hand) to,
PA' = -4*p + 2
PB' = 4*p - 1
When set equal to zero and solved (by hand) for p (and q), to find the optimum probabilities for each strategy when playing "mixed strategies."
For a description of mixed strategies and deriving probability profiles, please see the relevant literature.
TO DO
Find or make an algebraic solver...
Add tests for mixed()
SEE ALSO
The game theory sections and exercises of "Games and Decision Making" http://www.amazon.com/Games-Decision-Making-Charalambos-Aliprantis/dp/019530022X/
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.