Bottleneck and loss functions