Skip to content
martin-mnPublic

About

Code and data for: An exhaustive map of binary memory-two direct reciprocity over symmetric two-player games

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

An exhaustive map of binary memory-two direct reciprocity over symmetric two-player games

Code and data to reproduce every figure and the table in the paper and its Supplementary Information.

Martin A. Nowak, Department of Mathematics and Department of Organismic and Evolutionary Biology, Harvard University.

What is computed

The 216 = 65536 binary memory-two strategies, each answering the sixteen two-round histories by cooperation or defection up to an error rate eps, projected onto the whole plane of symmetric two-player games. The game is infinitely repeated and the future is not discounted, so a payoff is the long-run average per round. Nothing here is a simulation: every layer is exact rational arithmetic over a finite strategy space, and the two regimes — the limit eps -> 0 and a fixed eps > 0 — are computed separately, because they do not agree.

The exact layer, in one paragraph

The ε→0 layer of the paper is computed exactly — the Markov chain tree theorem in integer arithmetic, all 65,535 deviations per resident retained, no extrapolation, no rational snapping, no bounding box — and independently cross-checked by a second, floating-point pipeline that agrees with it entry for entry. The exact layer, its data, its all-rate certificates and its ten-minute reproduction test live in exact/ (see exact/README.md). The all-rate certification is also what establishes the ϱ-arcs of SI §6 — above ε = 1/4 four further strategies keep equilibria arbitrarily far out inside the no-equilibrium cone — which is why SIFigure6/ has a fourth panel and the rational-ε builder build_regions_frac.py.

Layout

One folder per display item, named as the paper names it, plus the exact layer:

Figure1 … Figure5           the five main-text figures
Table1                      the main-text table
SIFigure1 … SIFigure6       the six Supplementary Information figures
exact                       the exact tree-theorem layer
friendlyrivals              the friendly-rival counts of SI §5 (pairs.c, an independent limit kernel)

Every folder has the same shape:

FigureN/
    p.py                  the plotting script that produces the published figure
    *.csv  *.npz  *.json  the computed input it reads, flat in the folder
    FigN.pdf, FigN.png    the published figure, for comparison
    README.md             what the figure shows, which input made which panel
    computation/          the code that produced the input

The last folder is called computation/ deliberately: this paper contains no simulation of any kind.

Reproducing a figure

The plotting scripts are self-contained — every input a script reads sits beside it, and no script reaches outside its own folder. From inside a figure's folder:

python3 p.py

This rewrites the figure in place. numpy, matplotlib and Pillow are needed everywhere, and sympy for Figure5, whose data.py reaches the memory-one layer through an exact symbolic pair calculation. Pillow is used by the self-check that measures the saved page. All twelve scripts have been run this way from a clean copy of their folder, and each reproduces the published figure byte for byte apart from the timestamp matplotlib embeds in a PDF.

The scripts are not all cheap, because several draw exact arrangements or large rasters. Measured on twelve cores:

folder time folder time
Figure1 2 s SIFigure1 2 s
Figure2 42 s SIFigure2 3 s
Figure3 79 s SIFigure3 58 s
Figure4 83 s SIFigure4 2 s
Figure5 81 s SIFigure5 2 s
Table1 1 s SIFigure6 13 s

Each script prints a receipt as it finishes — page dimensions, the resolution of any raster it embedded, and the assertions it checked on the way. Those checks are part of what is published: a script that cannot verify its own numbers stops rather than drawing.

Re-running a computation

computation/ holds the code that produced each folder's input, as it runs in the project tree, and it is there to be read and cited rather than as a required step. Two things follow, and both are deliberate:

  • The expensive layers are the point of shipping the reduced output. The vanishing-error limit was computed on a cluster — for every one of the 65536 residents, the exact set of games at which it is an equilibrium, tested against all 65535 rivals, which is 4.29 × 109 limiting pair distributions — and the fixed-eps layers are exact-rational passes over the same space. The .csv and .npz files shipped above are their reduced output.
  • These scripts resolve their own inputs relative to the project directory they live in, so a command copied out of computation/ will not generally run in the flattened archive folder. Each folder's README says what its computation scripts do and in what order; treat them as the record of how the data was made.

Cluster kits are self-documenting: a README describing the kit, a compile script, a Slurm array script, and the source.

WF1 in the computation READMEs is the companion project Simple evolution drives direct reciprocity to maximum payoff in social dilemmas (arXiv:2608.06147), whose archive conventions this one shares.

Notes on the mapping between folders and scripts

Recorded here because none of the three is what the name suggests:

  • Figure 1 is drawn by the project's p2.py, whose own output is named Fig2 — an internal numbering. The archived p.py writes the published name and its receipt reports it. Where a script's closing receipt named a file under the internal numbering, only that name was changed; every number a receipt measures is untouched.
  • Figure 2 is drawn by the project's p4grid.py, invoked with --vertical. The archived p.py has that flag hard-wired.
  • Figures 3 and 4 are the same script, the project's p3pair.py, differing only by a --frac flag: Figure 3 counts efficient equilibria, Figure 4 gives their share of all equilibria. Each folder stands alone with the flag fixed, so the two folders hold near-identical copies of one script by design.

Payoff conventions

Every game is brought by a positive affine change of scale to

R = 1        S = u        T = 1 + v        P = 0

so mutual cooperation earns 1, mutual defection 0, and the plane of (u, v) is the whole space of symmetric two-player games in which mutual cooperation beats mutual defection. The four quadrants are the four families — Prisoner's Dilemma u<0, v>0, Snowdrift u>0, v>0, Stag Hunt u<0, v<0, Harmony u>0, v<0. The line u + v = 1 is the switch line, where the best that two players can jointly achieve stops being mutual cooperation and becomes perfect alternation; the figures draw it throughout.

Because the plane is unbounded, several figures draw it compactified rather than cropped, by

(u, v)  ->  (u, v) / sqrt(k^2 + u^2 + v^2)

which carries the plane onto the open unit disk and the directions at infinity onto its rim. k fixes how much of the page goes to the near field: the games within |(u,v)| <= k occupy exactly half the disk's area. Most panels use k = 4; the two single-game panels of Figure 2 use k = 1.5.

License

The code is released under the MIT License; see LICENSE. The computed output included alongside it — the .csv, .npz, .json and .pkl.gz files — may be used freely for any purpose, with attribution to the paper.

About

Code and data for: An exhaustive map of binary memory-two direct reciprocity over symmetric two-player games

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages