NAME

Game::Theory::TwoPersonMatrix - Reduce & analyze a 2 person matrix game

VERSION

version 0.0501

SYNOPSIS

use Game::Theory::TwoPersonMatrix;
my $g = Game::Theory::TwoPersonMatrix->new(
  1 => { strategy => { 1 => \@u11, 2 => \@u12, } },
  2 => { strategy => { 1 => \@u21, 2 => \@u22, } },
);
$g->player_strategy(1);
$g->player_strategy(2);
$g->reduce(2, 1); # Player 2 given player 1
$g->reduce(1, 2); # Player 1 given player 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()

$g = Game::Theory::TwoPersonMatrix->new();
$g = Game::Theory::TwoPersonMatrix->new(%args);
$g = Game::Theory::TwoPersonMatrix->new(
  1 => { strategy => { 1 => [1,1,3], 2 => [0,0,3], 3 => [0,2,5] }, choice => { 1 => 0.2, 2 => 0.3, 3 => 0.5}, },
  2 => { strategy => { 1 => [0,2,2], 2 => [3,1,4], 3 => [0,0,3] }, choice => { 1 => 0.2, 2 => 0.3, 3 => 0.5}, },
);

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"

If not provided, the strategic choices are computed equally from the number of strategies.

player_strategy()

Return the given player's strategy.

player_choice()

Return the given player's strategic choice value.

expected_value()

Return a player's expected payoff value for the entire game.

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...

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.