calpit.nn.ispline_nn
IsplineNN: a Cal-PIT network that is monotone in alpha by construction.
Classes
Output layer that is a monotone function of alpha built from I-spline basis functions. |
|
Network for Cal-PIT whose output is monotone in the coverage level alpha. |
Functions
|
Module Contents
- class ISplineLayer(in_features, num_basis, dropout_p=0)[source]
Bases:
torch.nn.ModuleOutput layer that is a monotone function of alpha built from I-spline basis functions.
The output is a convex combination of cubic I-spline basis functions of alpha on [0, 1], with weights from a softmax over a linear map of the input. Each basis function increases from 0 to 1, so the output is non-decreasing in alpha and lies in [0, 1].
- Parameters:
in_features (int) – The number of input features.
num_basis (int) – The number of I-spline basis functions.
dropout_p (float, optional) – The dropout probability applied to the weights. Defaults to 0.
- Raises:
ImportError – If spline-basis is not installed.
- interp1d(x, y, x_new)[source]
Linearly interpolates tabulated basis functions.
- Parameters:
x (torch.Tensor) – The sorted grid, shape (n_grid,).
y (torch.Tensor) – The basis functions on the grid, shape (n_grid, num_basis).
x_new (torch.Tensor) – The points to interpolate at, shape (n_points,).
- Returns:
The interpolated values, shape (n_points, num_basis).
- Return type:
torch.Tensor
- class IsplineNN(n_features, hidden_layers=None, dropout_p=0.5, num_basis=10)[source]
Bases:
torch.nn.ModuleNetwork for Cal-PIT whose output is monotone in the coverage level alpha.
An MLP of PReLU layers maps the features x to the weights of an ISplineLayer, which evaluates the I-splines at alpha. The weights do not depend on alpha, so the predicted PIT CDF is non-decreasing in alpha, runs from 0 at alpha = 0 to 1 at alpha = 1, and the recalibrated densities from CalPIT.transform are non-negative.
- Parameters:
n_features (int) – The number of features, not counting alpha.
hidden_layers (list of int, optional) – The widths of the hidden layers. Defaults to [512, 512, 512].
dropout_p (float, optional) – The dropout probability in the ISplineLayer. Defaults to 0.5.
num_basis (int, optional) – The number of I-spline basis functions. Defaults to 10.
- Variables:
output (str) – “probability”; the network returns r itself, not its logit.
- Raises:
ImportError – If spline-basis is not installed.
- forward(alpha, x)[source]
Evaluates the network.
- Parameters:
alpha (torch.Tensor) – The coverage levels in [0, 1], shape (batch,).
x (torch.Tensor) – The features, shape (batch, n_features).
- Returns:
The predicted probability that the PIT is at most alpha, shape (batch,).
- Return type:
torch.Tensor
- forward_curves(alpha, x)[source]
Evaluates the network at many coverage levels per object, running the MLP once per object.
- Parameters:
alpha (torch.Tensor) – The coverage levels in [0, 1], shape (batch, n_alpha).
x (torch.Tensor) – The features, shape (batch, n_features).
- Returns:
The predicted probability that the PIT is at most alpha, shape (batch, n_alpha).
- Return type:
torch.Tensor