Skip to content

Commit b353c4e

Browse files
committed
update
1 parent 142fa51 commit b353c4e

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

lectures/information_market_equilibrium.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,11 +1032,11 @@ mystnb:
10321032
caption: price distribution convergence
10331033
name: fig-price-convergence
10341034
---
1035-
def price_expectation(h_t, p_bar_true, p_bar_alt, sigma_p, p_grid):
1035+
def price_expectation(h_t, p_bar_true, p_bar_alt, σ_p, p_grid):
10361036
"""Return the predictive price density at posterior weight h_t."""
10371037
return (
1038-
h_t * norm.pdf(p_grid, loc=p_bar_true, scale=sigma_p)
1039-
+ (1 - h_t) * norm.pdf(p_grid, loc=p_bar_alt, scale=sigma_p)
1038+
h_t * norm.pdf(p_grid, loc=p_bar_true, scale=σ_p)
1039+
+ (1 - h_t) * norm.pdf(p_grid, loc=p_bar_alt, scale=σ_p)
10401040
)
10411041
10421042
@@ -1542,7 +1542,7 @@ prior support.
15421542

15431543
```{code-cell} ipython3
15441544
def simulate_misspecified(
1545-
T, p_bar_true, p_bar_wrong, sigma_p, h0, n_paths, seed=0
1545+
T, p_bar_true, p_bar_wrong, σ_p, h0, n_paths, seed=0
15461546
):
15471547
"""Simulate learning under a misspecified two-model prior."""
15481548
rng = np.random.default_rng(seed)
@@ -1551,34 +1551,34 @@ def simulate_misspecified(
15511551
15521552
for path in range(n_paths):
15531553
h = np.array(h0, dtype=float)
1554-
prices = rng.normal(p_bar_true, sigma_p, size=T)
1554+
prices = rng.normal(p_bar_true, σ_p, size=T)
15551555
for t, price in enumerate(prices):
1556-
likes = norm.pdf(price, loc=p_bar_wrong, scale=sigma_p)
1556+
likes = norm.pdf(price, loc=p_bar_wrong, scale=σ_p)
15571557
h = h * likes
15581558
h /= h.sum()
15591559
h_paths[path, t + 1, :] = h
15601560
15611561
return h_paths
15621562
15631563
1564-
def predictive_density(weights, means, sigma_p, p_grid):
1564+
def predictive_density(weights, means, σ_p, p_grid):
15651565
"""Return the predictive density under the current posterior weights."""
15661566
density = np.zeros_like(p_grid)
15671567
for weight, mean in zip(weights, means):
1568-
density += weight * norm.pdf(p_grid, loc=mean, scale=sigma_p)
1568+
density += weight * norm.pdf(p_grid, loc=mean, scale=σ_p)
15691569
return density
15701570
15711571
15721572
T = 1000
15731573
p_true = 2.0
15741574
p_wrong = np.array([1.5, 2.3])
1575-
sigma_p = 0.4
1575+
σ_p = 0.4
15761576
h0 = np.array([0.5, 0.5])
15771577
n_paths = 30
15781578
1579-
h_misspec = simulate_misspecified(T, p_true, p_wrong, sigma_p, h0, n_paths)
1579+
h_misspec = simulate_misspecified(T, p_true, p_wrong, σ_p, h0, n_paths)
15801580
1581-
kl_vals = (p_true - p_wrong)**2 / (2 * sigma_p**2)
1581+
kl_vals = (p_true - p_wrong)**2 / (2 * σ_p**2)
15821582
for mean, kl in zip(p_wrong, kl_vals):
15831583
print(f"KL(true || N({mean:.1f}, sigma^2)) = {kl:.4f}")
15841584
@@ -1607,12 +1607,12 @@ closer_idx = np.argmin(kl_vals)
16071607
fig, ax = plt.subplots(figsize=(8, 4))
16081608
colors = plt.cm.Blues(np.linspace(0.3, 1.0, 4))
16091609
for t_snap, color in zip([0, 10, 100, T], colors):
1610-
dens = predictive_density(median_path[t_snap], p_wrong, sigma_p, p_grid)
1610+
dens = predictive_density(median_path[t_snap], p_wrong, σ_p, p_grid)
16111611
ax.plot(p_grid, dens, color=color, lw=2, label=f"t = {t_snap}")
16121612
16131613
ax.plot(
16141614
p_grid,
1615-
norm.pdf(p_grid, loc=p_wrong[closer_idx], scale=sigma_p),
1615+
norm.pdf(p_grid, loc=p_wrong[closer_idx], scale=σ_p),
16161616
"k--",
16171617
lw=2,
16181618
label="KL-best wrong model",

0 commit comments

Comments
 (0)