@@ -1085,7 +1085,7 @@ We now briefly explore two alternative discrepancy measures.
10851085
10861086### Chernoff Entropy
10871087
1088- Chernoff entropy was motivated by an early application of the theory of large deviations < https://en.wikipedia.org/wiki/Large_deviations_theory> .
1088+ Chernoff entropy was motivated by an early application of the [ theory of large deviations]( https://en.wikipedia.org/wiki/Large_deviations_theory) .
10891089
10901090```{note}
10911091Large deviation theory provides refinements of the central limit theorem.
@@ -1173,15 +1173,15 @@ The [Jensen-Shannon divergence](https://en.wikipedia.org/wiki/Jensen%E2%80%93Sha
11731173For probability densities $f$ and $g$, the **Jensen-Shannon divergence** is defined as:
11741174
11751175$$
1176- D(f,g) = \frac{1}{2} D(f|| m) + \frac{1}{2} D(g|| m)
1176+ D(f,g) = \frac{1}{2} KL(f, m) + \frac{1}{2} KL(g, m)
11771177$$ (eq:js_divergence)
11781178
11791179where $m = \frac{1}{2}(f+g)$ is a mixture of $f$ and $g$.
11801180
11811181```{note}
11821182We studied KL divergence in the [section above](rel_entropy) with respect to a reference distribution $h$.
11831183
1184- Because in general $KL(f,g) \neq KL(g,f)$, KL divergence is not symmetric, but Jensen-Shannon divergence is symmetric.
1184+ Because in general $KL(f, g) \neq KL(g, f)$, KL divergence is not symmetric, but Jensen-Shannon divergence is symmetric.
11851185
11861186(In fact, the square root of the Jensen-Shannon divergence is a metric referred to as the Jensen-Shannon distance.)
11871187
@@ -1210,7 +1210,7 @@ def js_divergence(f, g):
12101210
12111211def kl_divergence(f, g):
12121212 """
1213- Compute KL divergence D(f|| g)
1213+ Compute KL divergence D(f, g)
12141214 """
12151215 def integrand(w):
12161216 return f(w) * np.log(f(w) / g(w))
@@ -1248,8 +1248,8 @@ for i, ((f_a, f_b), (g_a, g_b)) in enumerate(distribution_pairs):
12481248
12491249 results.append({
12501250 'Pair': f"f=Beta({f_a},{f_b}), g=Beta({g_a},{g_b})",
1251- 'KL(f|| g)': f"{kl_fg:.4f}",
1252- 'KL(g|| f)': f"{kl_gf:.4f}",
1251+ 'KL(f, g)': f"{kl_fg:.4f}",
1252+ 'KL(g, f)': f"{kl_gf:.4f}",
12531253 'JS divergence': f"{js_div:.4f}",
12541254 'Chernoff entropy': f"{chernoff_ent:.4f}"
12551255 })
@@ -1263,15 +1263,15 @@ The above table indicates how Jensen-Shannon divergence, and Chernoff entropy
12631263Let's also visualize how these diverge measures covary
12641264
12651265```{code-cell} ipython3
1266- kl_fg_values = [float(result['KL(f|| g)']) for result in results]
1266+ kl_fg_values = [float(result['KL(f, g)']) for result in results]
12671267js_values = [float(result['JS divergence']) for result in results]
12681268chernoff_values = [float(result['Chernoff entropy']) for result in results]
12691269
12701270fig, axes = plt.subplots(1, 2, figsize=(12, 5))
12711271
12721272# JS divergence and KL divergence
12731273axes[0].scatter(kl_fg_values, js_values, alpha=0.7, s=60)
1274- axes[0].set_xlabel('KL divergence KL(f|| g)')
1274+ axes[0].set_xlabel('KL divergence KL(f, g)')
12751275axes[0].set_ylabel('JS divergence')
12761276axes[0].set_title('JS divergence and KL divergence')
12771277
@@ -1349,7 +1349,7 @@ def plot_dist_diff():
13491349
13501350 # Add divergence information
13511351 axes[row, col].set_title(
1352- f'KL(f|| g)={kl_fg:.3f}, JS={js_div:.3f}, C={chernoff_ent:.3f}',
1352+ f'KL(f, g)={kl_fg:.3f}, JS={js_div:.3f}, C={chernoff_ent:.3f}',
13531353 fontsize=12)
13541354 axes[row, col].legend(fontsize=14)
13551355
@@ -1439,7 +1439,7 @@ Now let's visualize the correlations
14391439```{code-cell} ipython3
14401440def plot_error_divergence(data):
14411441 """
1442- Plot log-scale correlations between error probability and divergence measures.
1442+ Plot correlations between error probability and divergence measures.
14431443 """
14441444 # Filter out near-zero error probabilities for log scale
14451445 nonzero_mask = data['error_prob'] > 1e-6
0 commit comments