MachineSex/figures/plot_figS11_directed_recombination.py
Giorgio Gilestro ab3dc10587 Restructure: descriptive tier and experiment names, paper/manuscript
- paper/pnas -> paper/manuscript (venue-neutral)
- configs/layer1 -> configs/inheritance, src/knowledge -> src/inheritance
  (imported as `inheritance`), make layer1 -> make inheritance; layer2 alias dropped
- inheritance and trained-network bundles named after the manuscript figure
  they feed (fig2_grounding_sweep, figS3_rebaselining, ...), or descriptively
  where they feed none; configs keep their `experiment:` value so parquet
  hashes are unchanged, only output.dir moves
- figure scripts, SI figure sources, notebooks, REPRODUCING.md, README and the
  SI Methods/tables updated; make clean no longer deletes tracked manifests;
  reproduce.sh hashes the s{seed}/ layouts too

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y64o8FKP7rCuXzC48pxpMm
2026-09-13 17:00:40 +01:00

64 lines
3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""E10 figure — directed sex beats biological sex (the distinctly-AI superpower).
On rugged (epistatic) landscapes, blind "biological" sex — random mates, no offspring selection —
suffers outbreeding depression: offspring are worse than the parents. But an AI can do what biology
cannot: choose complementary mates, evaluate *many* recombinant offspring, and keep only the fittest,
over several rounds, with no two-parent limit. This **directed sex** avoids the catastrophe and
matches or exceeds the best parent even when skills are entangled.
Two panels: (A) deployed capability vs landscape ruggedness — best single parent, random (blind) sex,
directed sex, and the global optimum; (B) each strategy's edge over the best parent, making the
random-sex collapse and the directed-sex rescue explicit. Reads only the committed bundle.
Usage: python figures/plot_figS11_directed_recombination.py [results/figS11_directed_recombination]
"""
from __future__ import annotations
import sys
from pathlib import Path
import matplotlib.pyplot as plt
sys.path.insert(0, str(Path(__file__).parent))
from _figlib import load_bundle, mean_ci, savefig, letter_axes # noqa: E402
def main(results_dir: str = "results/figS11_directed_recombination") -> None:
df, _ = load_bundle(results_dir)
fig, axes = plt.subplots(1, 2, figsize=(13, 5))
# Panel A: the three strategies + global optimum vs ruggedness.
ax = axes[0]
for col, c, lab in [("global_opt", "green", "global optimum"),
("directed_sex", "#d62728", "directed sex (AI: choose + select)"),
("best_parent", "#7f7f7f", "best single parent"),
("random_sex", "#1f77b4", "random sex (blind, biology)")]:
k, m, ci = mean_ci(df, "K", col)
ls = ":" if col == "global_opt" else "-o"
ax.plot(k, m, ls, color=c, label=lab) if col == "global_opt" else \
ax.errorbar(k, m, yerr=ci, fmt=ls, color=c, capsize=3, label=lab)
ax.set(xlabel="landscape ruggedness $K$ (epistasis)", ylabel="deployed capability (fitness)",
title="Random sex craters with ruggedness;\ndirected sex tracks/exceeds the best parent")
ax.legend(frameon=False, fontsize=8)
# Panel B: edge over best parent (random collapse vs directed rescue).
ax = axes[1]
bp = df.groupby("K")["best_parent"].mean()
for col, c, lab in [("directed_sex", "#d62728", "directed sex"),
("random_sex", "#1f77b4", "random sex")]:
s = df.groupby("K")[col].mean() - bp
ax.plot(s.index, s.values, "-o", color=c, label=lab)
ax.axhline(0, ls=":", color="gray", lw=1, label="best parent")
ax.set(xlabel="landscape ruggedness $K$", ylabel="capability best parent",
title="Directed sex stays ≥ parents; blind sex\nfalls far below (outbreeding depression)")
ax.legend(frameon=False, fontsize=9)
fig.tight_layout()
letter_axes(fig)
savefig(fig, results_dir, "figS11_directed_recombination")
if __name__ == "__main__":
main(*sys.argv[1:])