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).
- KL (float, Tensor) – the Kullback Leibler divergence between the posterior and prior parameters of the model (\(\text{KL}[q\|p]\)).
- 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 aslike_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, observation_axis=-2)¶ 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. One
axis of this object’s
batch_shape
should refer toN
, which is the number of observations (can be?
if you are using a placeholder and mini-batching). The axis that indexes observations is set by theobservation_axis
setting. For data that is(N, tasks)
or(..., N, tasks)
, this should automatically work. - Y (ndarray, Tensor) – the targets of shape
(N, tasks)
. - regulariser (float, Tensor) – the regulariser on the parameters of the model to penalise model complexity.
- 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 aslike_weights(Y)
and should return a(N,)
array. - observation_axis (int) – The axis that indexes the observations. This will assume the
observations are on the second last axis, i.e.
(..., N, D)
. This is used to calculate the mini-batch size.
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. One
axis of this object’s