Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta. Args: d1: instance of a Beta distribution object. d2: instance of a Beta distribution object. name: (optional) Name to use for created operations. default is "kl_beta_beta". Returns: Batchwise KL(d1 |
(d1, d2, name=None)
| 377 | |
| 378 | @kullback_leibler.RegisterKL(Beta, Beta) |
| 379 | def _kl_beta_beta(d1, d2, name=None): |
| 380 | """Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta. |
| 381 | |
| 382 | Args: |
| 383 | d1: instance of a Beta distribution object. |
| 384 | d2: instance of a Beta distribution object. |
| 385 | name: (optional) Name to use for created operations. |
| 386 | default is "kl_beta_beta". |
| 387 | |
| 388 | Returns: |
| 389 | Batchwise KL(d1 || d2) |
| 390 | """ |
| 391 | def delta(fn, is_property=True): |
| 392 | fn1 = getattr(d1, fn) |
| 393 | fn2 = getattr(d2, fn) |
| 394 | return (fn2 - fn1) if is_property else (fn2() - fn1()) |
| 395 | with ops.name_scope(name, "kl_beta_beta", values=[ |
| 396 | d1.concentration1, |
| 397 | d1.concentration0, |
| 398 | d1.total_concentration, |
| 399 | d2.concentration1, |
| 400 | d2.concentration0, |
| 401 | d2.total_concentration, |
| 402 | ]): |
| 403 | return (delta("_log_normalization", is_property=False) |
| 404 | - math_ops.digamma(d1.concentration1) * delta("concentration1") |
| 405 | - math_ops.digamma(d1.concentration0) * delta("concentration0") |
| 406 | + (math_ops.digamma(d1.total_concentration) |
| 407 | * delta("total_concentration"))) |
nothing calls this directly
no test coverage detected