Skip to content

Edit Schelling lecture series for clarity and consistency#301

Merged
mmcky merged 2 commits intomainfrom
schell_misc_edits
Apr 8, 2026
Merged

Edit Schelling lecture series for clarity and consistency#301
mmcky merged 2 commits intomainfrom
schell_misc_edits

Conversation

@jstac
Copy link
Copy Markdown
Contributor

@jstac jstac commented Apr 7, 2026

Summary

  • Streamline prose and code across all five Schelling segregation model lectures
  • Fix typos, merge redundant functions, and align patterns for consistency
  • Net reduction of ~300 lines while preserving all content

Test plan

  • Build the lectures and verify all code cells execute correctly
  • Review rendered output for formatting and figure display
  • Verify cross-lecture links resolve correctly

🤖 Generated with Claude Code

…ance

Streamline prose, merge redundant functions, fix typos, and align
patterns across all five Schelling segregation model lectures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 7, 2026

Deploy Preview for incomparable-parfait-2417f8 ready!

Name Link
🔨 Latest commit a940775
🔍 Latest deploy log https://app.netlify.com/projects/incomparable-parfait-2417f8/deploys/69d57e5521d4c40009fc8d67
😎 Deploy Preview https://deploy-preview-301--incomparable-parfait-2417f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented Apr 7, 2026

Detailed changelog

schelling.md (pure Python lecture)

  • Typo fix: Added missing word "of" in the unhappiness definition ("$k > 6$ her" → "$k > 6$ of her")

schelling_numpy.md

  • Trimmed prose: Cut verbose step-by-step walkthroughs of basic NumPy operations (broadcasting, argsort, fancy indexing, boolean sums) down to brief, targeted commentary. The code is readable on its own; explanations now focus on the non-obvious parts.
  • Merged three functions into one: get_distances, get_neighbors, and is_happy collapsed into a single is_unhappy function (5 lines with inline comments). This removes ~30 lines of code and two layers of indirection.
  • Renamed is_happyis_unhappy: Aligns with the JAX lectures, where the simulation logic naturally asks "is this agent unhappy?". All call sites updated accordingly.
  • Fixed redundant happiness check: update_agent previously re-checked happiness at the top of its while loop even though the caller had just confirmed the agent was unhappy. Switched to a while is_unhappy(...) pattern that reads naturally.
  • Removed unused count_happy function: Defined and demoed but never used in the simulation.
  • Idiomatic types array: Replaced np.array([0] * n0 + [1] * n1) with np.zeros/slice assignment.
  • Cleaner simulation loop: Replaced while/manual counter with for/break and a converged flag.
  • Added Performance section: Brief closing that bridges to the JAX lecture, mentioning JIT compilation, GPU acceleration, and faster nearest neighbor computations.
  • Removed redundant "first step" phrasing in the overview.
  • Fixed typo: neighbor_types == agent_type!= in the walkthrough text (code was already correct).
  • Lowercase "visualization" in section intro.

schelling_jax.md

  • Removed "How JAX Differs from NumPy" section (52 lines): Covered immutability, functional programming, and random keys in the abstract before any model code. These concepts are already familiar by this point in the lecture series. Each concept is now introduced inline where it first appears.
  • Merged three functions into one: Same get_distances/get_neighbors/is_unhappy merge as the NumPy lecture.
  • Cut "Tips for Using JAX" section: Every tip restated something already demonstrated in the code.
  • Replaced "Summary" section: Cut the bullet-point recap and replaced with a one-line bridge to the parallel lecture.
  • Idiomatic types array: jnp.concatenate([jnp.zeros(...), jnp.ones(...)]) instead of Python list construction.
  • Cleaner simulation loop: for/break with converged flag, matching the NumPy lecture.
  • Fixed warm-up cell: Removed calls to deleted functions.

schelling_jax_parallel.md

  • Fixed typo: "In this lecture, introduce" → "In this lecture, we introduce".
  • Updated copied NumPy code: Synced with all edits from the NumPy lecture (merged functions, is_unhappy, for/break, idiomatic types array).
  • Updated copied JAX code: Synced with all edits from the JAX lecture (merged is_unhappy, jnp.concatenate, converged flag).
  • Updated parallel simulation loop: Same for/break and converged flag pattern.
  • Merged "Discussion" and "Key Takeaways": Both said the same thing (parallelism trades iterations for speed, GPUs help). Combined into one concise Discussion section.
  • Fixed warm-up cell: Removed calls to deleted functions.

schelling_shocks.md

  • Merged three functions into one: Same is_unhappy merge as the other JAX lectures.
  • Renamed section heading: "Distance and Neighbor Functions" → "Core Functions".
  • Aligned update_agent_location with parallel lecture: Folded the happy-agent check inside the function (matching schelling_jax_parallel.md's pattern) instead of computing unhappiness separately in parallel_update_step. This eliminates redundant unhappiness computation.
  • Idiomatic types array: jnp.concatenate instead of Python list construction.
  • Tightened Discussion: Removed redundant numbered list that restated the surrounding paragraphs.
  • Fixed warm-up cell: Removed calls to deleted functions.

All files

  • Whitespace formatting: Enforced the QuantEcon convention of blank lines above and below each sentence in prose sections.

@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented Apr 7, 2026

@mmcky Please review, merge and make live. Thanks!

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

@github-actions github-actions bot temporarily deployed to pull request April 7, 2026 20:49 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 7, 2026 20:53 Inactive
@jstac
Copy link
Copy Markdown
Contributor Author

jstac commented Apr 7, 2026

@mmcky Please review, merge and make life when you have time. Thanks!

--- Ah, sorry, duplicate comment, i thought the last one hadn't been saved. Pls ignore.

@mmcky
Copy link
Copy Markdown
Contributor

mmcky commented Apr 7, 2026

Reviewed — code changes are correct and consistent across all five files. Added a commit fixing three minor punctuation issues (missing commas). LGTM to merge.

@github-actions github-actions bot temporarily deployed to pull request April 7, 2026 22:08 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 7, 2026 22:12 Inactive
@mmcky mmcky merged commit 907f64f into main Apr 8, 2026
7 checks passed
@mmcky mmcky deleted the schell_misc_edits branch April 8, 2026 00:21
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.

2 participants