Skip to content

Commit 4766c59

Browse files
committed
updates
1 parent 33afc8c commit 4766c59

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

lectures/likelihood_ratio_process.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -635,21 +635,13 @@ Let's compute the Kullback–Leibler discrepancies by quadrature
635635
integration.
636636

637637
```{code-cell} ipython3
638-
def KL_integrand(w, q, h):
639-
640-
m = h(w) / q(w)
641-
642-
return np.log(m) * h(w)
643-
644638
def compute_KL(f, g):
645639
"""
646640
Compute KL divergence KL(f, g)
647641
"""
648-
def integrand(w):
649-
return f(w) * np.log(f(w) / g(w))
650-
651-
result, _ = quad(integrand, 1e-5, 1-1e-5)
652-
return result
642+
integrand = lambda w: f(w) * np.log(f(w) / g(w))
643+
val, _ = quad(integrand, 1e-5, 1-1e-5)
644+
return val
653645
```
654646

655647
Next we create a helper function to compute KL divergence with respect to a reference distribution $h$

0 commit comments

Comments
 (0)