Files
enso/diffusion/__pycache__/diffusion_utils.cpython-310.pyc
T

37 lines
2.8 KiB
Plaintext
Raw Normal View History

2024-07-01 11:35:48 +08:00
o
<zdu ã@s4ddlZddlZddZddZddZdd „ZdS)
éNcd||||fD] }t|tjƒr|nqˆdusJdƒfdd||fDƒ\}}dd||t ||¡||dt | ¡S)
Compute the KL divergence between two gaussians.
Shapes are automatically broadcasted, so batches can be compared to
scalars, among other use cases.
Nz&at least one argument must be a Tensorcs,g|]}t|tjƒr |nt |¡ ˆ¡qS©)Ú
isinstanceÚthÚTensorÚtensorÚto)Ú.0Úrrú]/maindata/data/shared/multimodal/zhengcong.fei/code/dit-moe/code/diffusion/diffusion_utils.pyÚ
<listcomp>sÿÿznormal_kl.<locals>.<listcomp>çà?gð¿é)rrrÚexp)Úmean1Úlogvar1Úmean2Úlogvar2Úobjrr
r Ú normal_kl
s* þ

þÿþ ýüÿrc Cs2ddt t dtj¡|dt |d¡¡S)zb
A fast approximation of the cumulative distribution function of the
standard normal.
r
çð?g@g÷Hmâä¦?é)rÚtanhÚnpÚsqrtÚpiÚpow)r rrr Úapprox_standard_normal_cdf's2rcCs@||}t | ¡}||}tj t |¡t |¡¡ |¡}|S)a
Compute the log-likelihood of a continuous Gaussian distribution.
:param x: the targets
:param means: the Gaussian mean Tensor.
:param log_scales: the Gaussian log stddev Tensor.
:return: a tensor like x of log probabilities (in nats).
)rrÚ
distributionsÚNormalÚ
zeros_likeÚ ones_likeÚlog_prob)r ÚmeansÚ
log_scalesÚ
centered_xÚinv_stdvZ normalized_xÚ log_probsrrr Ú"continuous_gaussian_log_likelihood/s
  r(c
C|j|jkr|jksJJ||}t | ¡}||d}t|ƒ}||d}t|ƒ}t |jdd¡} t d|jdd¡}
||} t |dk| t |dk|
t | jdd¡¡¡} | j|jksfJ| S)az
Compute the log-likelihood of a Gaussian distribution discretizing to a
given image.
:param x: the target images. It is assumed that this was uint8 values,
rescaled to the range [-1, 1].
:param means: the Gaussian mean Tensor.