Skip to content

[newton_method] Some suggestions on code and wording #1063

Description

@longye-tian

Hi @jstac

I was reading through the newton_method lecture with codex and here are some potential updates.

I'd be grateful if you could take a look when you have a chance.

Overview

  • At lines 66–72, the descriptions use “the fixed point” and “the zero,” which can imply uniqueness. Use “a fixed point” and “a zero” instead.

Fixed-point computation using Newton's method

  • At line 123, specify that the savings rate satisfies $s \in (0,1)$, rather than only $s>0$.

  • At lines 283–291, define the linear approximation with equality:

$$ \hat g(x):=g(x_0)+g'(x_0)(x-x_0). $$

  • At lines 293–306, state that the Newton update requires $1-g'(x_t)\neq 0$.

  • At lines 336–367, plot_trajectories relies on the global value of k_star, which may have been calculated from different parameters. Calculate k_star = exact_fixed_point(params) inside the function instead.

Root-finding in one dimension

  • [qe-writing-006] At line 378, change the heading from “Root-Finding in one dimension” to the sentence-case form “Root-finding in one dimension.”

  • At lines 397–405, define the linear approximation with equality:

$$ \hat f(x):=f(x_0)+f'(x_0)(x-x_0). $$

  • At lines 405–418, state that each Newton update requires $f'(x_t)\neq 0$.

  • At line 460, correct “We can convert to this to a zero-finding problem” to “We can convert this to a zero-finding problem.”

Multivariate Newton's method

  • At lines 485–486, change “5,000 goods” to “3,000 goods” to match the code implementation later.

  • At line 492, change “A two-goods market equilibrium” to “A two-good market equilibrium.”

  • [qe-writing-001] At lines 513, 606, and 701, split each two-sentence paragraph so that it contains one sentence per paragraph.

  • At line 606, capitalize “Python.”

  • At lines 621–643, plot_excess_demand reads A, b, and c from mutable global state. Pass these parameters explicitly so that the two-good plots can still be rerun after the variables are reassigned for the 3,000-good example.

  • At line 624, update the mesh-grid comment from combinations of p_1 and p_2 to combinations of p_0 and p_1 so that it matches with the notation in the text.

  • [qe-fig-003] At lines 620–643, remove the embedded ax.set_title(). It also causes the combined plot at lines 667–671 to end with the misleading title “Excess demand for good 1,” even though both goods are shown.

  • At line 661, the prose describes a “black contour line,” but the code does not explicitly set the contour color. Currently it looks like purple not black. We can set the contour color to black.

  • At lines 725–735, update the manually calculated Jacobian. For

$$ e_i(p)=\exp(-(Ap)_i)+c_i-b_i\sqrt{p_i}, $$

so each exponential derivative contain the complete row product $(Ap)_i$. The element-by-element implementation could be:

def jacobian_e(p, A, b, c):
    p_0, p_1 = p
    a_00, a_01 = A[0, :]
    a_10, a_11 = A[1, :]

    exp_0 = jnp.exp(-(a_00 * p_0 + a_01 * p_1))
    exp_1 = jnp.exp(-(a_10 * p_0 + a_11 * p_1))

    j_00 = -a_00 * exp_0 - (b[0] / 2) * p_0 ** (-1 / 2)
    j_01 = -a_01 * exp_0
    j_10 = -a_10 * exp_1
    j_11 = -a_11 * exp_1 - (b[1] / 2) * p_1 ** (-1 / 2)

    J = [[j_00, j_01], [j_10, j_11]]
    return jnp.array(J)
  • At lines 760–768, state that the multivariate Newton update requires $J_e(p_n)$ to be nonsingular.

  • At lines 777–799, the multivariate newton definition overwrites the scalar implementation from the preceding section. Give it a distinct name such as newton_nd and update all downstream multivariate calls in Section 7.4 and the exercise solutions.

Exercise 1

  • At lines 904–909, denote the three initial vectors by $k_0^{(1)}$, $k_0^{(2)}$, and $k_0^{(3)}$, currently it looks like $k1_0$, $k2_0$, and $k3_0$.

  • At lines 917–934, clarify that the three-dimensional analytical benchmark is $(k^,k^,k^)^\top$ , where the linked $k^$ is the scalar analytical solution.

Exercise 2

  • At lines 1053–1058, denote the three initial price vectors by $p_0^{(1)}$, $p_0^{(2)}$, and $p_0^{(3)}$, currently the number is after the letter: $p1_0$, $p2_0$, and $p3_0$.

What do you think? Happy to put up a PR.

Best,
Longye

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementImprovement to existing material

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions