Research Article
A Fortran-Keras Deep Learning Bridge for Scientific Computing
Algorithm 4
Implementation of crossentropy loss function and the corresponding derivation with respect to the input logits.
real(rk) function crossentropy_loss(self, y_true, y_pred) | ! Given predicted and expected output, returns the scalar loss | class(network_type), intent(in out): self | real(rk), intent(in): y_true(), y_pred() | loss = - sum(y_true ∗ log(y_pred)) | end function loss | function d_crossentropy_loss(self, y_true, y_pred) result(loss) | ! Given predicted and expected output | ! returns the loss with respect to softmax input | class(network_type), intent(in out): self | real(rk), intent(in): y_true(), y_pred() | real(rk), allocatable: loss() | loss = y_pred - y_true | end function d_loss |
|