{"slug": "open-source-ml-book-with-simulated-ecosystem-for-adtech", "title": "Open-source ML book with simulated ecosystem for AdTech", "summary": "Ben Weber released the open-source book Machine Learning in Mobile AdTech along with companion code: a simulated mobile ad market, a Go bidder that trades in it, and Python pipelines that train, validate, and publish its models. The simulator models users and devices, publisher apps, three ad exchanges running first-price auctions, competing bidders, a measurement partner attributing installs by last touch, organic installs, advertisers, fraud, and traffic patterns, and exposes ground-truth probabilities behind every click, install, and win so models, forecasts, and A/B tests can be checked against what actually happened. The free online edition and EPUB are available, the simulator runs with 'docker compose up --build' on Linux and macOS (WSL 2 or PowerShell versions on Windows), and an AGENTS.md file directs AI coding agents such as Claude Code, Codex, and Cursor through the chapter exercises.", "body_md": "Source for the book *Machine Learning in Mobile AdTech* and its companion\ncode: a simulated mobile ad market, a Go bidder that trades in it, and the\nPython pipelines that train, validate, and publish its models.\n\n**Read it:** [free online edition](https://bgweber.github.io/AdtechBook/) ·\n[free EPUB](https://github.com/bgweber/AdtechBook/releases/latest) ·\n[paperback on Amazon](https://www.amazon.com/dp/B0HSX91M9W)\n\nFinding the book or simulator useful? [Leaving a quick rating or review on\nAmazon](https://www.amazon.com/review/create-review?asin=B0HSX91M9W) (no purchase required) helps other engineers discover it.\n\nThe EPUB's equations need a reader with math (MathML) support, such as Apple Books, Thorium Reader, or Calibre. Kindle doesn't support it and shows the equations garbled, so on Kindle, read the chapters with equations online.\n\n**Run the simulator:** start a simulated ad market, a Go bidder, and its console with one command,\nthen follow the book chapter by chapter. The **[walkthrough](https://github.com/bgweber/AdtechBook/blob/main/WALKTHROUGH.md)** has the commands for\nthe exercises in Parts II to IV and screenshots of what you'll see. The commands are for Linux and\nmacOS; on Windows, use WSL 2 or the [PowerShell versions](https://github.com/bgweber/AdtechBook/blob/main/WALKTHROUGH-windows.md).\n\n```\ndocker compose up --build    # then open http://localhost:8081\n```\n\n**We encourage you to work through the examples with an AI coding agent,** such as Claude Code,\nCodex, or Cursor, open in this repo. It can give you each chapter's commands for your machine,\ncheck your output against the book, and help when a step fails. [AGENTS.md](https://github.com/bgweber/AdtechBook/blob/main/AGENTS.md) tells\nit how; the walkthrough stays the reference for people.\n\nThe heart of this repo is a simulated mobile ad market. You run a real bidder against it, train models on what the bidder logged, and check every model against the truth, which only a simulator knows. The market includes:\n\n- **Users and their devices** , each with a country, a phone model, how much they play, tastes for game genres, and the apps already installed. They click, install, keep playing, buy, and earn ad revenue.\n- **Publisher apps** : the supply, with their ad placements, ad density, price floors, and popularity.\n- **Three ad exchanges** with their own quirks, running first-price auctions, sending win, loss, and billing notices, reporting the minimum bid to win, and sending invoices.\n- **Competing bidders** , who set the price to beat in each auction, with a shared component, which is what makes the winner's curse.\n- **A measurement partner (MMP)** that attributes installs by last touch, with click and view windows, and sends postbacks with delays, losses, and duplicates.\n- **Other ad networks** that touch the same devices, so some installs our ads drove are credited elsewhere.\n- **Organic installs** , which happen with no ad at all, including people who play so many games that they would have found the app without our ad.\n- **Advertisers** with campaigns, budgets, targets, and creatives, some of whom share their full install data.\n- **Fraud** : bot devices and fraudulent publisher apps.\n- **Traffic patterns** : daily cycles by time zone, and scenarios for failures, bad labels, hypercasual ad revenue, traffic surges, and a market shift.\n- **The ground truth** : the true probability behind every click, install, and win, and the lift of every impression, so every model, forecast, and A/B test can be checked against what really happened.\n\n*The simulated market, the bidder, and the training service, with the events between them and the files each one writes and reads.*\n\nEverything the market does shows up on the bidder's console, as it would in a real DSP:\n\n*The bidder's live console: requests, bids, wins, and spend for every campaign in the simulated market (Chapter 5).*\n\n*Evaluating a click model: ROC and precision-recall curves, and calibration checked against the simulator's true rates (Chapter 9).*\n\n*Monitoring models in production: hourly mean predictions against their baselines, with deploys and alerts marked (Chapter 24).*\n\n*The embedding viewer: the deep model's app embeddings, with one genre highlighted and an app's nearest neighbors ringed. On this small market, they haven't learned genres (Chapter 26).*\n\nThe book comes with a simulated mobile ad market, **adsim**, and the code\nthat bids into it and learns from it. The simulator knows the truth: next to\nthe logs a DSP would see, it writes the true click, install, and lift\nprobabilities behind every impression, so you can check a model against\nwhat really happened, not just against noisy outcomes.\n\n| Component | What it is | \n|---|---|\n| `code/sim/` : adsim 0.9, the simulated market | Crawl, walk, and run markets; OpenRTB requests with exchange quirks; first-price auctions with a winner's curse; clicks, installs, organic installs, MMP attribution, delayed postbacks, purchases, ad revenue, and non-attributed data; holdouts; truth tables. Runs offline with a Python policy, or live against a real bidder: OpenRTB over HTTP in simulated time, `tmax` enforced, notice URLs called, postbacks delivered. Scenarios for failures, bad labels, Ad ROAS, uplift, traffic surges, and a market shift, and true rates for every creative. See[`code/sim/README.md`](https://github.com/bgweber/AdtechBook/blob/main/code/sim/README.md) | \n| `code/dsp/` : bidder 0.23, the Go reference DSP | Parsing and normalization of each exchange's quirks, device profiles, eligibility and selection, the bid ledger with FeatureVectors, notices, holdouts, kill switches, a fallback ladder, alerts, and reconciliation. LightGBM click, install, and win models served natively in Go with parity checks before every deploy; bid shading; pricing for CPC, CPI, ROAS, Ad ROAS, and CPA goals with win curves, uplift, and one pricing equation; pacing; shadow mode, canaries, and A/B tests; incrementality; a prediction monitor with drills and playbooks; a DCNv2 served in pure Go; and a live console with a Deep models tab. See [`code/dsp/README.md`](https://github.com/bgweber/AdtechBook/blob/main/code/dsp/README.md) | \n| `code/training/` : adtrain 0.20, training, validation, publishing | Datasets from the bidder's ledger with automated checks, an FTRL click model, LightGBM conversion, value, win, and uplift models, out-of-time validation and readouts, publishing with golden examples, lift and pacing analysis, label quarantine, and train/serve parity. For Part IV: trees against a DCNv2, pretraining a transformer, exporting for Go serving, retraining through a market shift, learned campaign selection, and personalized creative selection, all on a laptop's CPU. See [`code/training/README.md`](https://github.com/bgweber/AdtechBook/blob/main/code/training/README.md) | \n| `code/onnxbench/` | Chapter 17's comparison of ONNX Runtime from Go with the bidder's own tree evaluator. Not part of `docker compose` | \n| `compose.yaml` : Docker Compose | The bidder, the training service, and the simulator, plus a `loadtest` profile for the load generator | \n\nEvery exercise in Parts II, III, and IV runs, through Chapter 36: the\n**[walkthrough](https://github.com/bgweber/AdtechBook/blob/main/WALKTHROUGH.md)** has every command, and\n[AGENTS.md](https://github.com/bgweber/AdtechBook/blob/main/AGENTS.md) helps an AI coding agent guide you through them. Each\nchapter's \"Try it on the simulator\" box ends with the versions it was tested\nwith.\n\nQuick start, no Docker needed:\n\n```\npip install -e code/sim[test]\npython -m adsim --preset crawl --scale laptop --days 1 --seed 7 --out out/crawl\npytest code/sim\n```\n\nSee [`code/sim/README.md`](https://github.com/bgweber/AdtechBook/blob/main/code/sim/README.md) for the tables it writes and\nhow the market works.\n\nWatch the Go bidder trade in the simulated market, with Docker:\n\n```\ndocker compose up --build\n```\n\nThen open the console at [http://localhost:8081](http://localhost:8081). The simulator plays two\ndays and stops. Open the **Models** tab and click **Train**: the training\nservice builds click examples from the bidder's logs, trains a click\nmodel, validates it, and the bidder deploys it if it passes its checks.\nThen play more days with the model pricing the bids:\n\n```\ndocker compose run --rm sim\n```\n\nEach run continues the market where the bidder's ledger left off, so the\nmodel sees new days, never a replay. To start over, stop everything and\ndelete the `out` folder.\n\nThis needs a current\nDocker with Compose v2, the `docker compose` command (Docker Desktop\nincludes it). If you get `unknown flag: --build` or `'compose' is not a docker command`, your Docker is too old: update Docker Desktop. Without\nDocker, see [`code/dsp/README.md`](https://github.com/bgweber/AdtechBook/blob/main/code/dsp/README.md).\n\nadsim runs a live market for a real bidder, with the scenarios each chapter needs; Appendix E of the book documents its equations and versions. It still leaves out:\n\n- iOS and ATT: devices without an IFA, SKAdNetwork postbacks with coarse values and delays, and contextual-only signals.\n- Click injection and click spamming fraud, beyond the 10-second rejection rule.\n- Devices that change during a run: installs don't change which apps a device plays, and its fatigue only builds within a day.\n- Competing bidders that learn and adapt their shading.\n- A scoreboard: fixed markets where policies are scored against the simulator's truth.\n- Speed: the built-in policy loops in Python, so the `medium` and`large` scales are slow.\n\nThe simulator, the bidder, and the training service run with Docker\nCompose (`compose.yaml`), and the load generator runs with\n`--profile loadtest`. The simulator alone also runs without Docker (the\nquick start above), and so does rendering the book.\n\nPart IV's deep models (Chapters 25 to 29, 35, and 36) are PyTorch, built for a laptop's CPU: the training image installs the CPU build, and each chapter's command runs in a few minutes on the Part IV dataset. The code doesn't use a GPU. To scale up, with bigger datasets, wider models, and longer histories, install the CUDA build of PyTorch and move the models and their inputs to the GPU: the book provides the code, not the compute.\n\nThe book is openly licensed and the code is open source, and contributions are welcome. Good\nplaces to start are the simulator features it leaves out, listed above. Open an issue to discuss a change before a large\npull request. See [CONTRIBUTING.md](https://github.com/bgweber/AdtechBook/blob/main/CONTRIBUTING.md).\n\n- **Text and figures:**[CC BY-NC-SA 4.0](https://github.com/bgweber/AdtechBook/blob/main/LICENSE) . You can share and adapt\nthem for non-commercial purposes, with credit, under the same license. The\ncover and the author photo are not covered by this license.\n- **Code:**[MIT](https://github.com/bgweber/AdtechBook/blob/main/LICENSE-CODE) . This covers`code/` ,`scripts/` ,`filters/` ,\nthe build configuration, and the code samples in the book, so you can use\nthem in your own projects, including commercial ones.\n\n```\n_quarto.yml                 Book config: chapters, HTML/PDF/EPUB formats\nindex.qmd, preface.qmd      Welcome page and preface\nparts/, chapters/           Part pages and one .qmd file per chapter\nappendices/                 Glossary, OpenRTB fields, templates, reading, the simulated world\ncode/sim/                   Python: adsim, the simulated market\ncode/dsp/                   Go: the reference bidder and its console\ncode/training/              Python: training, validation, publishing (adtrain)\ncode/onnxbench/             Go: Chapter 17's ONNX Runtime comparison\ncompose.yaml                Docker Compose: the bidder, the trainer, and the simulator\nWALKTHROUGH.md              Every exercise's commands (WALKTHROUGH-windows.md for PowerShell)\nAGENTS.md                   Guidance for AI coding agents working through the exercises\nimages/                     Figures, the ebook cover (cover.jpg, added to the EPUB by\n                            scripts/polish_epub.py), and the README cover (cover-front.jpg).\n                            Console screenshots are color for the web and EPUB, with a\n                            high-contrast grayscale *-print.png version for the print PDF\nstyles/preamble.tex         Print styling: headers, code boxes, copyright page\nstyles/epub.css             Ebook styling\nscripts/polish_epub.py      Makes the EPUB a native ebook (runs after each render)\n_freeze/                    Saved code output (committed; see below)\nrequirements.txt            Python packages CI needs to render\nLICENSE, LICENSE-CODE       CC BY-NC-SA 4.0 for text and figures; MIT for code\nCONTRIBUTING.md             How to contribute, and how contributions are licensed\n.github/workflows/          Book build/publish and code test workflows\n```\n\nThe `Tests` workflow runs on every push and pull request: `pytest code` for\nthe Python code, and `go vet` and `go test ./...` in `code/dsp/`. To run\nthem locally:\n\n```\npip install -e code/sim[test] -e code/training[test]\npytest code\ncd code/dsp && go test ./...\n```\n\nThe Go tests include a parity test against a model the Python code\ntrained (`code/dsp/internal/model/testdata`, made with\n`python -m adtrain.fixture`), so training and serving can't drift apart\nwithout a test failing.\n\n1. Install [Quarto](https://quarto.org/docs/get-started/) .\n2. Install Python 3.12 and the packages: `pip install -r requirements.txt` .\n3. For the PDF, install a TeX distribution: `quarto install tinytex` .\n\nLive preview of the web edition (reloads on save):\n\n```\nquarto preview\n```\n\nBuild every edition into `_book/`:\n\n```\nquarto render\n```\n\nBuild one edition:\n\n```\nquarto render --to pdf\n```\n\nThe chapters have no code cells that run when the book renders: the\ncompanion code runs on its own, with the commands in `WALKTHROUGH.md`.\n`execute: freeze: auto` in `_quarto.yml` is there for any that are added\nlater; it saves their results in `_freeze/`, and CI reuses them.", "url": "https://wpnews.pro/news/open-source-ml-book-with-simulated-ecosystem-for-adtech", "canonical_source": "https://github.com/bgweber/AdTechBook", "published_at": "2026-12-05 22:15:53+00:00", "updated_at": "2026-12-05 22:46:31.919176+00:00", "lang": "en", "topics": ["machine-learning", "ai-tools", "developer-tools"], "entities": ["Ben Weber", "Machine Learning in Mobile AdTech", "AdtechBook", "Claude Code", "Codex", "Cursor", "Amazon", "GitHub"], "also_reported_by": [], "takeaway": "The repo ships a simulated ad market with ground-truth click, install, and win probabilities plus a Go bidder and Python training pipelines, so practitioners can validate models and A/B tests against known truth rather than noisy production logs.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/open-source-ml-book-with-simulated-ecosystem-for-adtech", "markdown": "https://wpnews.pro/news/open-source-ml-book-with-simulated-ecosystem-for-adtech.md", "text": "https://wpnews.pro/news/open-source-ml-book-with-simulated-ecosystem-for-adtech.txt", "jsonld": "https://wpnews.pro/news/open-source-ml-book-with-simulated-ecosystem-for-adtech.jsonld"}}