ab.losses¶
Network loss functions.
-
aboleth.losses.
elbo
(likelihood, Y, N, KL, like_weights=None)¶ Build the evidence lower bound loss for a neural net.
Parameters: - likelihood (tf.distributions.Distribution) – the likelihood object that takes neural network(s) as an input. The
batch_shape
of this object should be (n_samples, N, ...), wheren_samples
is the number of likelihood samples (defined by ab.InputLayer) andN
is the number of observations (can be?
if you are using a placeholder and mini-batching). - Y (ndarray, Tensor) – the targets of shape (N, tasks).
- N (int, Tensor) – the total size of the dataset (i.e. number of observations).
- like_weights (callable, ndarray, Tensor) – weights to apply to each observation in the expected log likelihood.
This should be an array of shape (N,) or can be called as
like_weights(Y)
and should return a (N,) array.
Returns: nelbo – the loss function of the Bayesian neural net (negative ELBO).
Return type: Tensor
- likelihood (tf.distributions.Distribution) – the likelihood object that takes neural network(s) as an input. The
-
aboleth.losses.
max_posterior
(likelihood, Y, regulariser, like_weights=None, first_axis_is_obs=True)¶ Build maximum a-posteriori (MAP) loss for a neural net.
Parameters: - likelihood (tf.distributions.Distribution) – the likelihood object that takes neural network(s) as an input. The
batch_shape
of this object should be (n_samples, N, ...), wheren_samples
is the number of likelihood samples (defined by ab.InputLayer) andN
is the number of observations (can be?
if you are using a placeholder and mini-batching). - Y (ndarray, Tensor) – the targets of shape (N, tasks).
- like_weights (callable, ndarray, Tensor) – weights to apply to each observation in the expected log likelihood.
This should be an array of shape (N,) or can be called as
like_weights(Y)
and should return a (N,) array. - first_axis_is_obs (bool) – indicates if the first axis indexes the observations/data or not. This
will be True if the likelihood outputs a
batch_shape
of (N, tasks) or False ifbatch_shape
is (n_samples, N, tasks).
Returns: map – the loss function of the MAP neural net.
Return type: Tensor
- likelihood (tf.distributions.Distribution) – the likelihood object that takes neural network(s) as an input. The