Skip to content

Commit aeb3efa

Browse files
added doc for nashequi group
1 parent 70d888e commit aeb3efa

File tree

1 file changed

+251
-0
lines changed

1 file changed

+251
-0
lines changed

GameTheory/trial.m2

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,257 @@ correlatedEquilibria List := X -> (
269269

270270

271271

272+
--mixedProbabilityRing;
273+
mixedProbabilityRing = method()
274+
mixedProbabilityRing List := L ->(
275+
p := getSymbol "p";
276+
probabilityRing := QQ[flatten apply(#L, i -> apply(L#i, j->p_{i,j}))];
277+
probabilityRing
278+
)
279+
mixedProbabilityRing Tensor := T ->(
280+
indexSet := format T;
281+
mixedProbabilityRing indexSet
282+
)
283+
284+
adifferencesFromFirst = L -> (apply(toList(1..#L-1), i->L#i-L#0))
285+
286+
monomialFromIndex = method()
287+
monomialFromIndex (List, ZZ, Ring):= (L, i, R) ->(
288+
p := getSymbol "p";
289+
monomial := product toList apply(pairs L, (j,r)->(s := if j >= i then j + 1 else j; p_{s,r}_R));
290+
monomial
291+
)
292+
293+
equilibriumPolynomials = method()
294+
equilibriumPolynomials (Tensor, ZZ, Ring) := (T, u, R)->(
295+
indexSet := format T;
296+
tensorIndices := T#"indexes";
297+
nStrategies := indexSet#u;
298+
accumulatedHash := new MutableHashTable;
299+
for tensorIndex in tensorIndices do (
300+
newCoefficient := T#tensorIndex;
301+
thisStrategy := tensorIndex#u;
302+
monomialIndex := drop(tensorIndex,{u,u});
303+
if not (accumulatedHash #? monomialIndex) then accumulatedHash#monomialIndex = new MutableList from nStrategies: 0;
304+
accumulatedHash#monomialIndex#thisStrategy = newCoefficient;
305+
);
306+
polynomials := apply(pairs accumulatedHash, (k,v)->(
307+
monomial := monomialFromIndex(k, u, R);
308+
apply(differencesFromFirst v, i-> i_R * monomial)
309+
));
310+
sum polynomials
311+
)
312+
313+
nashEquilibriumRing = method()
314+
nashEquilibriumRing List := L -> (
315+
-- L is a list consisting of n- tensors; requires them to be of the same dimension/shape
316+
indexSet := format first L;
317+
polyRing := mixedProbabilityRing indexSet;
318+
polyRing
319+
)
320+
nashEquilibriumIdeal = method()
321+
nashEquilibriumIdeal (Ring, List) := (R, L) -> (
322+
indexSet := format first L;
323+
probabilityRing := R;
324+
completeGeneratingSet := flatten(apply(pairs L, (i,T) -> equilibriumPolynomials(T,i,probabilityRing)));
325+
p := getSymbol "p";
326+
linearRelations := apply(pairs indexSet, (i,j)-> sum(j, k->p_{i,k}_probabilityRing) - 1);
327+
fullGeneratingSet := join(completeGeneratingSet, linearRelations);
328+
ideal fullGeneratingSet
329+
)
330+
331+
directProductList = method()
332+
directProductList List := L -> (
333+
if #L == 0 then error "Empty list of polytopes";
334+
P := L#0;
335+
for i from 1 to (#L - 1) do (
336+
P = directProduct(P, L#i);
337+
);
338+
P
339+
)
340+
341+
deltaList = method()
342+
deltaList List := d -> (
343+
n := #d;
344+
result := {};
345+
for i from 0 to (n - 1) do (
346+
polyFactors := for j from 0 to (n - 1) list (
347+
if j == i then (
348+
convexHull(matrix(apply(d#i - 1, k -> {0})))
349+
) else (
350+
simplex(d#j - 1)
351+
)
352+
);
353+
P := directProductList(polyFactors);
354+
for rep from 1 to (d#i - 1) do (
355+
result = append(result, P)
356+
);
357+
);
358+
result
359+
)
360+
361+
maxNumberEquilibria = method()
362+
maxNumberEquilibria List := d -> (
363+
myTuple := deltaList d;
364+
mv := mixedVolume(myTuple);
365+
print("The maximum number of totally mixed Nash equilibria for a " | toString(d) |
366+
" game is " | toString(mv));
367+
mv
368+
)
369+
370+
beginDocumentation()
371+
372+
doc ///
373+
Node
374+
Key
375+
GameTheory
376+
Headline
377+
a Package
378+
Description
379+
Text
380+
Computations in game theory.
381+
Caveat
382+
Nothing here yet.
383+
Subnodes
384+
"Ideals of Nash equilibria"
385+
Node
386+
Key
387+
"Ideals of Nash equilibria"
388+
Headline
389+
computing the ideal of a totally mixed Nash equilibria
390+
Description
391+
Text
392+
This package provides methods for constructing the mixed probability polynomial rings and computing the Nash equilibrium polynomials and ideals, as well as the max number of isolated totally mixed Nash Equilibra via polyhedral methods. It depends on the Polyhedra package. An introduction together with the relevant definitions is given in Chapter 6, Sturmfels, Bernd, @EM "Solving Systems of Polynomial Equations"@. American Mathematical Society, 2002. ISBN 978-0-8218-3251-6.
393+
Text
394+
This package uses the following functions in the @TO Polyhedra@ package:
395+
Text
396+
@UL {
397+
{TO convexHull},
398+
{TO directProduct},
399+
{TO mixedVolume},
400+
{TO simplex},
401+
}@
402+
Subnodes
403+
nashEquilibriumRing
404+
nashEquilibriumIdeal
405+
maxNumberEquilibria
406+
Node
407+
Key
408+
(nashEquilibriumRing, List)
409+
nashEquilibriumRing
410+
Headline
411+
make the Nash Equilibrium ring
412+
Usage
413+
nashEquilibriumRing L
414+
Inputs
415+
L:List
416+
a list of n-@TO Tensor@s with uniform dimensions
417+
Outputs
418+
:Ring
419+
a polynomial ring generated from the mixed probabilities
420+
Description
421+
Text
422+
An $n$-player game consists of players labeled with $0,1,\cdots, n-1$. The $i$-th player can choose from $d_i$ pure strategies. Let $p_{i,j}$ be the probablility of the $i$-th player choosing the $j$-the strategy, where $j=0,\cdots, d_j-1$. The ideal of the totally mixed Nash equilibria of the game is defined in the polynomial ring over a field $k$ with generators $\{p_{i,j}:0\leq i\leq n-1, 0\leq j\leq d_j-1\}$.
423+
424+
This method computes this ring over $k=\mathbb{Q}$ from a list of tensors representing the payoff matrices of all the $n$ players. The ring generators are ordered lexicographically.
425+
Example
426+
tensors = apply(3, i -> randomTensor {2,4,3})
427+
R = nashEquilibriumRing tensors
428+
baseRing R
429+
gens R
430+
Node
431+
Key
432+
(nashEquilibriumIdeal, Ring, List)
433+
nashEquilibriumIdeal
434+
Headline
435+
make the Nash Equilibrium ideal
436+
Usage
437+
nashEquilibriumIdeal(R, L)
438+
Inputs
439+
R:Ring
440+
the Nash Equilibrium ring. Typically obtained via @TO nashEquilibriumRing@
441+
L:List
442+
a list of payoff tensors
443+
Outputs
444+
:Ideal
445+
An ideal in the Nash Equilibrium ring R generated by the Nash equilibrium polynomials, along with the linear relations of those probabilities variables, that the probabilities of each players sum to 1
446+
Description
447+
Text
448+
For an $n$-player game, the totally mixed Nash equilibria are the zero loci in the interior of the polytope of a system of polynomials in the variables $\{p_{i,j}:0\leq i\leq n-1, 0\leq j\leq d_j-1\}$. The coefficients of these polynomials are differences of the entries of the payoff matrices. From an algebraic-geometric point of view, these polynomials, together with the linear constraints that $\sum_j p_{i,j}=1$ for each $i$, generate an ideal in the polynomial ring computed by @TO nashEquilibriumRing@.
449+
450+
This method computes this Nash equilibrium ideal by generating the polynomials from the payoff matrices first, and appending the linear relations that the sum of probabilities for each player is one.
451+
Example
452+
tensors = apply(3, i -> randomTensor {2,2,2})
453+
R = nashEquilibriumRing tensors
454+
gens R
455+
I = nashEquilibriumIdeal(R, tensors)
456+
Text
457+
Here the embient ring $R$ is explicitly computed before finding the ideal $I$. Alternatively, one can assign both the ring and the ideal to variables in the same line:
458+
Example
459+
I2 = nashEquilibriumIdeal(R2 = nashEquilibriumRing tensors, tensors)
460+
gens R2
461+
Node
462+
Key
463+
(maxNumberEquilibria, List)
464+
maxNumberEquilibria
465+
Headline
466+
compute the maximum number of totally mixed Nash equilibria
467+
Usage
468+
maxNumberEquilibria L
469+
Inputs
470+
L:List
471+
a list of integers representing the dimensions of the game
472+
Outputs
473+
:ZZ
474+
an integer value, the mixed volume, representing the maximum number of totally mixed Nash equilibria
475+
Description
476+
Text
477+
For an $n$-player game where the $i$-th player has $d_i$ pure strategies, the maximum number of isolated totally mixed Nash equilibria is given by the mixed volume of the following list of polytopes:
478+
479+
\[ (\Delta^{(0)}, \cdots, \Delta^{(0)},\Delta^{(1)}, \cdots, \Delta^{(1)}, \cdots, \Delta^{(n-1)}, \cdots, \Delta^{(n-1)}),\]
480+
481+
where each $\Delta^{(i)}$ repeats $d_i - 1 $ times, and is defined by the direct product of simplices
482+
483+
\[ \Delta^{(i)} := \Delta_{d_1-1}\times \Delta_{d_2-1} \times \cdots \Delta_{d_{i-2}-1} \times \{0\} \times \Delta_{d_{i}-1} \times \cdots \times \Delta^{d_{i-1}-1}).\]
484+
485+
This function first generates a tuple of delta polytopes from d, computes their mixed volume, prints a summary message, and returns the mixed volume. The mixed volume is computed via the function @TO mixedVolume@ in the @TO polyhedra@ package. This function currently runs very slow for higher dimension and requires improvement.
486+
Example
487+
d = {2,2,2}
488+
mv = maxNumberEquilibria d
489+
Text
490+
Alternatively, if you have a tensor $T$, you can compute its maximum number as follows:
491+
Example
492+
T = randomTensor {2,2,2}
493+
mv2 = maxNumberEquilibria format T
494+
Node
495+
Key
496+
Tensor
497+
Headline
498+
representing the payoff matrices
499+
///
500+
501+
TEST ///
502+
-- Test nashEquilibriumRing with a list of tensors
503+
tensorList = apply(3, i -> randomTensor {2,2,2})
504+
R5 = nashEquilibriumRing tensorList
505+
assert(numgens R5 > 0)
506+
507+
-- Test nashEquilibriumIdeal construction
508+
I = nashEquilibriumIdeal(R5, tensorList)
509+
assert(isIdeal I)
510+
511+
-- Test maxNumberEquilibria (prints and returns the mixed volume)
512+
mv = maxNumberEquilibria {2,2,2}
513+
assert(mv == 2)
514+
515+
-- Test maxNumberEquilibria using a tensor's format
516+
T2 = randomTensor {2,2,2}
517+
mv2 = maxNumberEquilibria format T2
518+
assert(mv2 == 2)
519+
///
520+
521+
end--
522+
272523

273524

274525
--***************************************--

0 commit comments

Comments
 (0)