Conversation
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (c8814f3) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (c575e39) 📚 Changed Lecture Pages: mccall_q |
earlier the legend overlapped on the curves, making it difficult to interpret the graph. this version fixes it
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (211832b) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (d7b49a6) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (ef3e791) 📚 Changed Lecture Pages: mccall_q |
There was a problem hiding this comment.
Pull Request Overview
This PR converts the McCall job search model lecture from NumPy/Numba implementation to JAX, updating the code to use JAX's functional programming paradigm and JIT compilation. The conversion includes modernizing the code structure, fixing grammatical errors, and improving figure presentation.
Key changes include:
- Complete conversion from NumPy/Numba to JAX with functional programming approach
- Replacement of class-based structure with NamedTuple and standalone functions
- Implementation of JAX's immutable array operations and control flow primitives
| qtable, s, accept_count, t, key = state | ||
| # for first interaction, just continue since error is large | ||
| # for subsequent interactions, compute actual error | ||
| error = jnp.where(t==0, δ + 1, jnp.max(jnp.abs(qtable - state[0]))) |
There was a problem hiding this comment.
The error calculation references state[0] but state is a tuple where the first element is qtable. This creates a circular reference where the error is computed as the difference between qtable and itself, which will always be zero after the first iteration. This should reference a previous qtable value stored separately.
lectures/mccall_q.md
Outdated
|
|
||
| for n in range(N): | ||
| if n%(N/10)==0: | ||
| if n % (N // 10) == 0: |
There was a problem hiding this comment.
Integer division N // 10 can result in zero when N < 10, causing a division by zero error in the modulo operation. This should use max(1, N // 10) to ensure the divisor is never zero.
| if n % (N // 10) == 0: | |
| if n % max(1, N // 10) == 0: |
lectures/mccall_q.md
Outdated
| max_epochs = int(jnp.max(epochs_to_plot)) # Convert to Python int | ||
| # iterate on epoch numbers | ||
| for n in range(max_epochs + 1): | ||
| if n%(max_epochs/10)==0: |
There was a problem hiding this comment.
Division by zero error can occur when max_epochs is 0. The condition n%(max_epochs/10)==0 will fail. This should use max_epochs > 0 and n%(max_epochs/10)==0 or n%(max(1, max_epochs/10))==0.
| if n%(max_epochs/10)==0: | |
| if n % max(1, max_epochs // 10) == 0: |
HumphreyYang
left a comment
There was a problem hiding this comment.
Many thanks @bishmaybarik! Nice changes -- they are really good improvements. Here are some minor comments.
|
hi @HumphreyYang , these are extremely useful suggestions -- thanks a lot! I'll make all the necessary changes and push the updated version once ready. |
vectorized computation instead of repeatedly resetting arrays with for loops
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (9143f6b) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (a72d9b3) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (f1a7dca) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (f53c4ef) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (06e07c0) 📚 Changed Lecture Pages: mccall_q |
|
📖 Netlify Preview Ready! Preview URL: https://pr-624--sunny-cactus-210e3e.netlify.app (d5d2565) 📚 Changed Lecture Pages: mccall_q |
| qtable, s, accept_count, t, key = state | ||
| # for first interaction, just continue since error is large | ||
| # for subsequent interactions, compute actual error | ||
| error = jnp.where(t==0, δ + 1, jnp.max(jnp.abs(qtable - state[0]))) |
There was a problem hiding this comment.
The error calculation references state[0] which should be the previous qtable. This creates a circular reference since state is the current state tuple. Consider storing the previous qtable separately or using a different approach to calculate the error.
|
hi @HumphreyYang and @mmcky , may I know if you have any thoughts on these updates? It would be great to hear from you! |
This PR is created to convert the
mccall_q.mdlecture codes into JAX equivalents.