Skip to content

The Frontier (fastbook ch.7–12), mobile fixes, district placards & tour polish#2

Merged
CodeWithOz merged 5 commits into
mainfrom
claude/musing-leavitt-bee803
Jun 12, 2026
Merged

The Frontier (fastbook ch.7–12), mobile fixes, district placards & tour polish#2
CodeWithOz merged 5 commits into
mainfrom
claude/musing-leavitt-bee803

Conversation

@CodeWithOz

@CodeWithOz CodeWithOz commented Jun 12, 2026

Copy link
Copy Markdown
Owner

What this adds

🌉 The Frontier — fastbook chapters 7–12 as a new city area

The map extends south across a river into the Frontier, where the data stops being images. Six new buildings, 23 inspection panels, four new live trainers — every number on screen still comes from real tensors training in the tab. Models were checked against the actual book notebooks, now vendored at reference/fastbook-master.zip (AGENTS.md instructs future agents to read the chapters before building on them):

District / building Book material
Refinement Row — Refinement Gym ch.7: normalization (real train-set stats), label smoothing ((1−ε+ε/N) targets), mixup (λ∈0.5–1 per the book's pseudocode), TTA over 5 shifted views — all racing an identically-initialized plain twin on the same batches
Taste Quarter — Taste Cinema ch.8: the book's DotProductBias (factors + biases + sigmoid_range(0,5.5)) with weight decay on a planted-structure ratings grid; dot-product desk, learned-bias interpretation, factor projector vs planted genres
Table Grove — Decision Arboretum ch.9: CART trees by variance reduction (the candidate-question audition), a walkable tree, bagged forest with OOB error + importance, and a "regrow the forest" operation showing sampling variance live
Language Lane — Tokenizer Mill + Sentiment Studio ch.10–11: tokenize → vocab (min-freq) → numericalize pipeline with xxbos/xxunk; live bag-of-words classifier with one inspectable weight per word, verdict updates as you type
Sequence Summit — Echo Tower ch.12: the book's LMModel2 on human numbers, next-word quiz on the held-out tail, most-common-token baseline, greedy/sampled generation

Frontier datasets are deterministic generators with planted structure + noise — models must rediscover it live, which lets panels honestly compare planted truth vs learned parameters.

📱 Mobile fixes

  • D-pad uses one ▲ glyph CSS-rotated per direction (no iOS emoji arrows, no mixed glyph sizes); ▶/⏸/⏭ get text-presentation selectors
  • Interiors clamp-follow the avatar like the street camera (no more walking offscreen)
  • Panels scroll vertically only: canvases shrink keeping aspect ratio, tables scroll in their own box, long pickers capped
  • Drawing canvas gets touch-action: none — dragging paints instead of scrolling

🪧 World & tour polish

  • District names are lawn-sign placards (navy board, gold text, posts) with decor cleared beneath; wider grass strips
  • Plaza redesigned: a network monument (edges light up while the main model trains) + a tour kiosk — press E beside it to ride a scripted express glide to stop ①; avatar spawns next to it
  • "↓ THE FRONTIER" markers on all river crossings; chevrons continue past stop ⑮ to the junction and stop at the final stop ㉑
  • Loop pulses are now chips carrying the actual digits of the current mini-batch
  • Fixed a pre-existing fmt() bug that truncated round integers everywhere (1700 → "17")

Testing

  • npm test: 29/29 (gradient checks, training smoke tests, new frontier scenario/tree/generator tests)
  • tsc --noEmit and production build clean
  • Walked the city in-browser at mobile (375px) and desktop sizes: all 58 panels open without console errors or horizontal overflow

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Frontier district with six new interactive buildings showcasing advanced ML concepts: collaborative filtering (movie recommendations), sentiment analysis, RNN language modeling, decision trees/random forests, and training refinement techniques.
    • Expanded guided city tour to 21 stops with new "express travel" mode featuring smooth easing.
    • Added interactive visualization panels for each new scenario with real-time exploration tools.

CodeWithOz and others added 4 commits June 12, 2026 15:01
The Frontier — a new area south of a river, six buildings / 22 panels,
everything trained live and checked against the vendored book notebooks
(reference/fastbook-master.zip, see AGENTS.md principle 7):
- Refinement Gym (ch.7): normalization, label smoothing ((1-ε+ε/N)
  targets), mixup (λ∈0.5..1 like the book's pseudocode), TTA over five
  shifted views — racing an identically-initialized plain twin on the
  same batches
- Taste Cinema (ch.8): DotProductBias with sigmoid_range and weight
  decay on a planted-structure ratings grid; dot-product desk, learned
  bias interpretation, factor projector vs planted genres
- Decision Arboretum (ch.9): CART trees by variance reduction, the
  candidate-question audition, bagged forest, OOB error, importance
- Tokenizer Mill + Sentiment Studio (ch.10-11): tokenize/numericalize
  pipeline with xxbos/xxunk + min-freq, live bag-of-words classifier
  (template corpus keeps function words class-balanced)
- Echo Tower (ch.12): the book's LMModel2 on human numbers, next-word
  quiz on the held-out tail, most-common-token baseline, generation

Mobile fixes:
- D-pad arrows: one ▲ glyph CSS-rotated (no iOS emoji variants, no
  mixed glyph sizes); FE0E on play/pause/step glyphs
- interiors clamp-follow the avatar like the street camera
- panels: vertical-only scrolling, canvases shrink with aspect ratio,
  tables scroll inside their own box, drawpad gets touch-action:none

World: district names are now lawn-sign placards (navy board, gold
text) with decor cleared beneath; grass strips widened; tour 1-21.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ree walk, fmt fix

From user review of the frontier build:
- The Grown Tree: path-focused layout — the chosen apartment's walk is
  expanded and highlighted top-to-bottom, every untaken branch folds
  into a clickable stub (no more squished columns at any width)
- fix fmt(): the trailing-zero strip was eating round integers
  (1700 -> "17", 1040 -> "104") across every panel
- Forest Lookout: 'regrow the forest' refits 20 trees on fresh
  bootstrap draws — MAE/OOB/importance wobble live (sampling variance,
  the thing bagging tames); single tree stays deterministic by design
- Review Reader: verdict re-reads as you type (the old 'read it'
  button re-classified the same text, so it looked dead)
- plaza redesign: a network monument (3-4-3 layers, edges light up
  while the main model trains) on a DL WORLD plinth, plus a tour
  kiosk — press E beside it to ride a scripted express glide to
  stop (1); avatar now spawns next to the kiosk
- '↓ THE FRONTIER' markers at the west and east bridges (the central
  sign is easy to miss on phones)
- tour chevrons: continue past stop 15 to the T-junction, stop at
  Echo Tower (no arrows past the final stop)
- loop pulses are now chips carrying the actual digits of the current
  mini-batch instead of abstract yellow dots
- heavy training tests get explicit 30s timeouts (were flaking at the
  default 5s under machine load)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sentiment Studio stands across the x30-31 column, so the central
vertical road's continuation to the south road was a dead-end stub
against the building's roof. The avenue now stops at the frontier's
first road; the west/east edge roads remain the through-routes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Align it with Taste Cinema (x22), clearing the x30-31 column so the
central avenue connects the north road to the frontier's bottom road
in one straight run — the proper fix for the earlier dead-end stub.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@CodeWithOz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 42 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2f4e966-13b9-48dc-b886-2fddebf945ad

📥 Commits

Reviewing files that changed from the base of the PR and between 5549310 and 4ecb3ff.

📒 Files selected for processing (2)
  • src/sim/tabular.ts
  • tests/frontier.test.ts

Walkthrough

This PR introduces the Frontier, a substantial expansion adding four new machine-learning training scenarios, synthetic dataset generators, interactive UI panels, decision-tree/forest models, world geography expansion, and an express-tour mechanic. The implementation progresses from data utilities through scenario implementations, world integration, comprehensive UI instrumentation, city geography, game mechanics, and testing.

Changes

Frontier ML Models & Interactive Learning Environment

Layer / File(s) Summary
Synthetic Dataset Generators
src/sim/datasets.ts
Deterministic seeded data generators for collaborative filtering (user/movie ratings), text sentiment reviews with tokenization, human-readable number sequences, and tabular regression (rent predictions). All use fixed holdout rules and controlled noise for reproducibility.
Scenario Type & IDs
src/sim/scenarios.ts, src/sim/scenarios2.ts
Expanded ScenarioId union to include refinery, collab, sentiment, rnnlm; added scenario module boilerplate with documentation and helper utilities.
Refinery Scenario: Normalization, Label-Smoothing, Mixup, and TTA
src/sim/scenarios2.ts
Configurable MNIST digit classifier with optional input normalization, label smoothing, and mixup augmentation. Runs plain twin in parallel for comparison, records loss graphs, and provides test-time augmentation via shifted-image averaging.
Collaborative Filtering Scenario: Matrix Factorization
src/sim/scenarios2.ts
User/movie factor matrix factorization with learned biases, sigmoid-scaled 0..5.5 predictions, MSE + L2 loss, and factor/bias inspection helpers.
Sentiment & Language Model Scenarios
src/sim/scenarios2.ts
SentimentNet (bag-of-words logistic regression with per-token weights and contribution analysis) and RnnLm (unrolled RNN with context embedding, hidden-state iteration, and temperature-sampled generation).
Decision Trees and Random Forests for Tabular Regression
src/sim/tabular.ts
Gradient-free CART-style tree fitting with recursive splits, feature-subset support, and recursive paths. Bootstrap ensemble with seeded PRNGs, out-of-bag error, feature importance via split-gain accumulation, and Arboretum singleton precomputing models on rent data.
World Class: New Trainers and Scenario Access
src/sim/world.ts
Four new Trainer instances (refinery, cinema, sentiment, echo) with public getters for underlying scenarios and expanded trainer list for consistent warm-up.
Refinery UI Panels: Training Instrumentation
src/ui/panels/refinery.ts
Five interactive panels: Twin Race Bench (refined vs. plain metrics), Normalization Bar (batch statistics), Label-Smoothing Bench (smoothed targets), Mixup Blender (mixed inputs), and Test-Time Augmentation panel.
Collaborative Filtering UI: Ratings and Factors
src/ui/panels/collab.ts
Four cinema panels: ratings heatmap, training bench with RMSE, dot-product factor/bias inspection, and factor projector with 2D embedding visualization and bias rankings.
Decision Tree & Forest UI: Regression Inspection
src/ui/panels/arbor.ts
Split audition table with MSE/gain, interactive tree path viewer with fold/unfold, and forest metrics panel with out-of-bag explanation and regrow control.
Language & Sentiment UI: Tokenization and Classification
src/ui/panels/language.ts
Six panels: tokenization, vocabulary wall, numericalization heatmap, training bench, free-form text classifier with top-token contributions, and learned-weight wall.
RNN Language Model UI: Corpus and Generation
src/ui/panels/echo.ts
Four panels: corpus statistics, hidden-state visualization, next-word prediction quiz with top-8 probabilities, and generation interface with greedy/sampled modes.
Panel Registration, Metrics Formatting, and Styling
src/ui/panels/index.ts, src/ui/panels/common.ts, src/style.css, src/ui/hud.ts, src/ui/touch.ts, src/ui/widgets.ts
Wires all new panel modules, adds fmtMetric helper for consistent formatting, introduces Frontier widget CSS (chips, trees, path highlighting), updates emoji glyphs for iOS consistency, refines D-pad rotation, and adjusts mobile responsive layout.
Buildings and World Geography Expansion
src/world/buildings.ts
Expands trainer type for six identifiers, repositions nine buildings downward 2 tiles, adds six new Frontier buildings (gym, cinema, arbor, tokenmill, sentstudio, echo) with placements and interior stations.
City Map: Monument, Kiosk, and District Signs
src/world/city.ts
Expands MAP_H to 65, introduces Monument/Kiosk tiles, defines district-sign system with cleared footprints, rewrites city generation, updates collision, and adds monument/kiosk rendering. Training-loop visualization now renders digit-carrying chips instead of dots.
Game: Express Tour Mechanics and Avatar Movement
src/world/game.ts
Adds scripted tour mode: avatar spawn repositioned, travel path and sparkle trail tracking, kiosk-triggered express ride, eased waypoint interpolation with direction updates, trail fading, and center-when-fits camera behavior. Suppresses prompts during travel and adds kiosk-specific interaction text.
Documentation, Guides, and End-to-End Tests
AGENTS.md, README.md, src/main.ts, tests/frontier.test.ts, tests/training.test.ts
Expanded AGENTS.md with concept naming and Frontier conventions; updated README with longer tour range and expanded curriculum map; updated welcome overlay narrative; added comprehensive test suite for data generators, scenario training, tree/forest metrics, and refinery TTA.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

The PR introduces substantial new functionality across multiple domains (data generation, ML model implementations, UI panels, world mechanics) with moderate logic density. While individual components follow clear patterns, the breadth of changes (5 new UI modules, tabular models, game mechanics, city expansion) and interconnected dependencies require careful review of each checkpoint. The implementation is self-contained but dense enough to demand thorough inspection of scenario semantics, tree-fitting correctness, UI wiring, and game-state management.

🐰 A Frontier awaits, where digits dance and models play,
Ten buildings born to teach what weights convey,
From chips that train to trees that split with gain,
The city grows—tour ① guides us down the lane!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding the Frontier (chapters 7-12), mobile UI fixes, and district/tour improvements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/musing-leavitt-bee803

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/sim/tabular.ts`:
- Around line 187-208: oobMae and predictForest currently divide by
counted/trees.length without guarding against zero, causing NaN; update oobMae
(function oobMae, referencing forest.trees, forest.bags and predictTree) to
return a safe numeric default (e.g. 0) when counted === 0 before doing total /
counted, and update predictForest (function predictForest, which calls
predictTree) to return the same safe default when trees.length === 0 before
dividing; keep existing aggregation logic otherwise.

In `@tests/frontier.test.ts`:
- Around line 28-42: The loadMnistFromDisk() helper lacks validation of the
MNIST file magic number; update loadMnistFromDisk to read and verify the first 4
bytes/magic (e.g., "DLW1") before proceeding with offsets and throw a clear
format/error when it doesn't match so corrupt files fail fast; locate and mirror
the validation approach used in tests/training.test.ts but implement it inside
loadMnistFromDisk (reference function name loadMnistFromDisk and the
DataView/Uint8Array buffer handling) and ensure the error message clearly
indicates an invalid MNIST magic/header.
- Line 156: The test hard-codes the feature index as 1 when asserting feature
importance (expect(Math.max(...imp)).toBe(imp[1])); change it to derive the
index from the feature names instead of a literal: compute sizeIdx =
TAB_FEATS.indexOf("size m²") (and assert sizeIdx !== -1) then use
expect(Math.max(...imp)).toBe(imp[sizeIdx]); this keeps the assertion robust if
TAB_FEATS or feature ordering from makeTabularData()/featureImportance()
changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f21c6bc1-f3f3-4eb2-ac93-f781ef761021

📥 Commits

Reviewing files that changed from the base of the PR and between b2b83a9 and 5549310.

⛔ Files ignored due to path filters (1)
  • reference/fastbook-master.zip is excluded by !**/*.zip
📒 Files selected for processing (24)
  • AGENTS.md
  • README.md
  • src/main.ts
  • src/sim/datasets.ts
  • src/sim/scenarios.ts
  • src/sim/scenarios2.ts
  • src/sim/tabular.ts
  • src/sim/world.ts
  • src/style.css
  • src/ui/hud.ts
  • src/ui/panels/arbor.ts
  • src/ui/panels/collab.ts
  • src/ui/panels/common.ts
  • src/ui/panels/echo.ts
  • src/ui/panels/index.ts
  • src/ui/panels/language.ts
  • src/ui/panels/refinery.ts
  • src/ui/touch.ts
  • src/ui/widgets.ts
  • src/world/buildings.ts
  • src/world/city.ts
  • src/world/game.ts
  • tests/frontier.test.ts
  • tests/training.test.ts

Comment thread src/sim/tabular.ts
Comment thread tests/frontier.test.ts
Comment thread tests/frontier.test.ts Outdated
…t index in tests

- predictForest/oobMae return 0 instead of NaN when there are no trees
  or no out-of-bag rows to score
- frontier test loader validates the DLW1 magic like the training tests
- feature-importance assertion derives the size column from TAB_FEATS
  instead of hard-coding index 1

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@CodeWithOz
CodeWithOz merged commit 19d60f1 into main Jun 12, 2026
3 checks passed
@CodeWithOz
CodeWithOz deleted the claude/musing-leavitt-bee803 branch June 12, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant