From 5c514ef4f4b0de8643158f95986e0d8f6df78c71 Mon Sep 17 00:00:00 2001 From: nisha617 Date: Wed, 1 Oct 2025 16:52:14 +1000 Subject: [PATCH 1/5] Update cd_analytical.py --- lectures/_static/lecture_specific/optgrowth/cd_analytical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lectures/_static/lecture_specific/optgrowth/cd_analytical.py b/lectures/_static/lecture_specific/optgrowth/cd_analytical.py index ec713ca..ea09dd2 100644 --- a/lectures/_static/lecture_specific/optgrowth/cd_analytical.py +++ b/lectures/_static/lecture_specific/optgrowth/cd_analytical.py @@ -1,7 +1,7 @@ def v_star(y, α, β, μ): """ - True value function + 真实价值函数 """ c1 = np.log(1 - α * β) / (1 - β) c2 = (μ + α * np.log(α * β)) / (1 - α) @@ -11,7 +11,7 @@ def v_star(y, α, β, μ): def σ_star(y, α, β): """ - True optimal policy + 真实最优策略 """ return (1 - α * β) * y From 6669861a6d8a319eedb332c641418e8e64629ea9 Mon Sep 17 00:00:00 2001 From: nisha617 Date: Wed, 1 Oct 2025 16:56:27 +1000 Subject: [PATCH 2/5] Update solve_model.py --- .../lecture_specific/optgrowth/solve_model.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lectures/_static/lecture_specific/optgrowth/solve_model.py b/lectures/_static/lecture_specific/optgrowth/solve_model.py index 06333ef..c6f6c34 100644 --- a/lectures/_static/lecture_specific/optgrowth/solve_model.py +++ b/lectures/_static/lecture_specific/optgrowth/solve_model.py @@ -4,12 +4,12 @@ def solve_model(og, verbose=True, print_skip=25): """ - Solve model by iterating with the Bellman operator. + 通过迭代贝尔曼算子求解 """ - # Set up loop - v = og.u(og.grid) # Initial condition + # 设置迭代循环 + v = og.u(og.grid) # 初始条件 i = 0 error = tol + 1 @@ -18,12 +18,12 @@ def solve_model(og, error = np.max(np.abs(v - v_new)) i += 1 if verbose and i % print_skip == 0: - print(f"Error at iteration {i} is {error}.") + print(f"第 {i} 次迭代的误差为 {error}。") v = v_new if error > tol: - print("Failed to converge!") + print("未能收敛!") elif verbose: - print(f"\nConverged in {i} iterations.") + print(f"\n在 {i} 次迭代后收敛。") return v_greedy, v_new From 003dfba7ab8d3cdafaf79a7b1ad6fb0e45b6f1e1 Mon Sep 17 00:00:00 2001 From: nisha617 Date: Wed, 1 Oct 2025 16:58:20 +1000 Subject: [PATCH 3/5] Update ogm.py --- .../lecture_specific/optgrowth_fast/ogm.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lectures/_static/lecture_specific/optgrowth_fast/ogm.py b/lectures/_static/lecture_specific/optgrowth_fast/ogm.py index 73d5a50..ef28a9e 100644 --- a/lectures/_static/lecture_specific/optgrowth_fast/ogm.py +++ b/lectures/_static/lecture_specific/optgrowth_fast/ogm.py @@ -2,12 +2,12 @@ from numba.experimental import jitclass opt_growth_data = [ - ('α', float64), # Production parameter - ('β', float64), # Discount factor - ('μ', float64), # Shock location parameter - ('s', float64), # Shock scale parameter - ('grid', float64[:]), # Grid (array) - ('shocks', float64[:]) # Shock draws (array) + ('α', float64), # 生产参数 + ('β', float64), # 折现因子 + ('μ', float64), # 冲击的均值参数 + ('s', float64), # 冲击的尺度参数 + ('grid', float64[:]), # 网格(数组) + ('shocks', float64[:]) # 冲击样本(数组) ] @jitclass(opt_growth_data) @@ -25,32 +25,32 @@ def __init__(self, self.α, self.β, self.μ, self.s = α, β, μ, s - # Set up grid + # 设置网格 self.grid = np.linspace(1e-5, grid_max, grid_size) - # Store shocks (with a seed, so results are reproducible) + # 存储冲击(设置随机种子以确保结果可重复) np.random.seed(seed) self.shocks = np.exp(μ + s * np.random.randn(shock_size)) def f(self, k): - "The production function" + "生产函数" return k**self.α def u(self, c): - "The utility function" + "效用函数" return np.log(c) def f_prime(self, k): - "Derivative of f" + "生产函数的一阶导数" return self.α * (k**(self.α - 1)) def u_prime(self, c): - "Derivative of u" + "效用函数的一阶导数" return 1/c def u_prime_inv(self, c): - "Inverse of u'" + "效用函数一阶导数的反函数" return 1/c From 7c99b664390db72f2eece471c1d29c8f166d5a9e Mon Sep 17 00:00:00 2001 From: nisha617 Date: Wed, 1 Oct 2025 16:59:33 +1000 Subject: [PATCH 4/5] Update ogm_crra.py --- .../optgrowth_fast/ogm_crra.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lectures/_static/lecture_specific/optgrowth_fast/ogm_crra.py b/lectures/_static/lecture_specific/optgrowth_fast/ogm_crra.py index fdd828f..33374f1 100644 --- a/lectures/_static/lecture_specific/optgrowth_fast/ogm_crra.py +++ b/lectures/_static/lecture_specific/optgrowth_fast/ogm_crra.py @@ -2,13 +2,13 @@ from numba.experimental import jitclass opt_growth_data = [ - ('α', float64), # Production parameter - ('β', float64), # Discount factor - ('μ', float64), # Shock location parameter - ('γ', float64), # Preference parameter - ('s', float64), # Shock scale parameter - ('grid', float64[:]), # Grid (array) - ('shocks', float64[:]) # Shock draws (array) + ('α', float64), # 生产参数 + ('β', float64), # 折现因子 + ('μ', float64), # 冲击的均值参数 + ('γ', float64), # 偏好参数 + ('s', float64), # 冲击的尺度参数 + ('grid', float64[:]), # 网格(数组) + ('shocks', float64[:]) # 冲击样本(数组) ] @jitclass(opt_growth_data) @@ -27,29 +27,29 @@ def __init__(self, self.α, self.β, self.γ, self.μ, self.s = α, β, γ, μ, s - # Set up grid + # 设置网格 self.grid = np.linspace(1e-5, grid_max, grid_size) - # Store shocks (with a seed, so results are reproducible) + # 存储冲击(设置随机种子以确保结果可重复) np.random.seed(seed) self.shocks = np.exp(μ + s * np.random.randn(shock_size)) - def f(self, k): - "The production function." + "生产函数" return k**self.α def u(self, c): - "The utility function." + "效用函数" return c**(1 - self.γ) / (1 - self.γ) def f_prime(self, k): - "Derivative of f." + "生产函数的一阶导数" return self.α * (k**(self.α - 1)) def u_prime(self, c): - "Derivative of u." + "效用函数的一阶导数" return c**(-self.γ) - def u_prime_inv(c): + def u_prime_inv(self, c): + "效用函数一阶导数的反函数" return c**(-1 / self.γ) From 825e7829127e71f3a839f112497727b41c2a390a Mon Sep 17 00:00:00 2001 From: nisha617 Date: Wed, 1 Oct 2025 17:05:18 +1000 Subject: [PATCH 5/5] Update solve_time_iter.py --- .../coleman_policy_iter/solve_time_iter.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lectures/_static/lecture_specific/coleman_policy_iter/solve_time_iter.py b/lectures/_static/lecture_specific/coleman_policy_iter/solve_time_iter.py index 1440489..e8ae433 100644 --- a/lectures/_static/lecture_specific/coleman_policy_iter/solve_time_iter.py +++ b/lectures/_static/lecture_specific/coleman_policy_iter/solve_time_iter.py @@ -1,11 +1,11 @@ -def solve_model_time_iter(model, # Class with model information - σ, # Initial condition +def solve_model_time_iter(model, # 含有模型信息的类 + σ, # 初始条件 tol=1e-4, max_iter=1000, verbose=True, print_skip=25): - # Set up loop + # 设置迭代循环 i = 0 error = tol + 1 @@ -14,12 +14,12 @@ def solve_model_time_iter(model, # Class with model information error = np.max(np.abs(σ - σ_new)) i += 1 if verbose and i % print_skip == 0: - print(f"Error at iteration {i} is {error}.") + print(f"第 {i} 次迭代的误差为 {error}。") σ = σ_new if error > tol: - print("Failed to converge!") + print("未能收敛!") elif verbose: - print(f"\nConverged in {i} iterations.") + print(f"\n在 {i} 次迭代后收敛。") return σ_new