calpit.nn.utils
PyTorch versions of calpit’s numerical helpers.
Functions
|
Calculates conditional density estimation loss on holdout data. |
|
Does trapezoid integration between the same limits as the grid, in PyTorch. |
Module Contents
- cde_loss(cde_estimates: torch.Tensor, y_grid: torch.Tensor, y_test: torch.Tensor) tuple[source]
Calculates conditional density estimation loss on holdout data. This is a PyTorch version of the original function.
- Parameters:
cde_estimates (torch.Tensor) – An array where each row is a density estimate on y_grid
y_grid (torch.Tensor) – An array of the grid points at which cde_estimates is evaluated.
y_test (torch.Tensor) – An array of the true y values corresponding to the rows of cde_estimates
- Returns:
A tuple containing the loss and the standard error of the loss.
- Return type:
tuple
- Raises:
ValueError – If the dimensions of the input tensors are not compatible.
- trapz_grid_torch(y: torch.Tensor, x: torch.Tensor) torch.Tensor[source]
Does trapezoid integration between the same limits as the grid, in PyTorch.
- Parameters:
y (torch.Tensor) – The values to integrate, shape (n_rows, n_grid).
x (torch.Tensor) – The grid points, shape (n_grid,).
- Returns:
The integrals from x[0] to each grid point, shape (n_rows, n_grid).
- Return type:
torch.Tensor