Skip to content

Commit

Permalink
fix: handling NaN propagation in BCE
Browse files Browse the repository at this point in the history
  • Loading branch information
Az-r-ow committed May 17, 2024
1 parent 1af5dea commit c9eff7c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/NeuralNet/losses/BCE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class BCE : public Loss {
-(yTrim.array() * oTrim.array().log() +
(1.0 - yTrim.array()) * (1.0 - oTrim.array()).log());

if (loss.array().isNaN().any())
throw std::runtime_error(
"NaN value encountered. Inputs might be too big");

return loss.sum();
}

Expand Down

0 comments on commit c9eff7c

Please sign in to comment.