Download lightning_modules/bregman.py from ChatterjeeLab/A2D2: direct link, hf CLI and curl.
- Browser
- Download file 528 Bytes
-
https://huggingface.co/ChatterjeeLab/A2D2/resolve/main/lightning_modules/bregman.py
- Command line
-
hf download hf://ChatterjeeLab/A2D2/lightning_modules/bregman.py
-
curl -L -o bregman.py https://huggingface.co/ChatterjeeLab/A2D2/resolve/main/lightning_modules/bregman.py
528 Bytes
| # A file of bregman divergences | |
| import torch | |
| def mse(x, y): | |
| sq_diff = (x - y) ** 2 | |
| if x.shape != y.shape: | |
| assert False, "x and y must have the same shape" | |
| return sq_diff.reshape(sq_diff.size(0), -1).sum(dim=-1) | |
| # TODO: check if this formulation is correct | |
| def jump_kernel_elbo(x, y, eps=1e-6): | |
| # x_safe: true length | |
| # y_safe: predicted length | |
| x_safe = torch.clamp(x, min=eps) | |
| y_safe = torch.clamp(y, min=eps) | |
| return y_safe - x_safe + x_safe * (torch.log(x_safe) - torch.log(y_safe)) | |