Skip to content

[tmva][sofie] Enhance Softplus stability in ROperator_BasicUnary#21092

Open
AdityaDRathore wants to merge 1 commit intoroot-project:masterfrom
AdityaDRathore:feature/sofie-softplus
Open

[tmva][sofie] Enhance Softplus stability in ROperator_BasicUnary#21092
AdityaDRathore wants to merge 1 commit intoroot-project:masterfrom
AdityaDRathore:feature/sofie-softplus

Conversation

@AdityaDRathore
Copy link
Copy Markdown
Contributor

Description

This PR implements numerical stability improvements for the Softplus operator, addressing overflow issues identified in Issue #21071.

It supersedes PR #21023 (which was closed due to branch history alignment).

Changes

  • Hexfloat Thresholding: Implements a hard threshold check using 0x1.4p+4f (20.0f) to prevent exp() overflow for large inputs.
  • Precision Logic: Replaces the naive log(exp(x)+1) with std::log1p(std::exp(x)) to preserve precision for negative inputs.
  • Validation: Adds a dedicated unit test suite TestSofieSoftplus.cxx verifying bit-exact hexfloat emission and overflow protection.

Technical Context

Fixes #21071

cc: @sanjibansg @lmoneta @bellenot

Copy link
Copy Markdown
Collaborator

@sanjibansg sanjibansg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AdityaDRathore,
Thanks for this PR. Can you add the tests following the convention we have in the SOFIE sub-directory?
https://github.com/root-project/root/tree/master/tmva/sofie/test

This commit specializes the `UnaryOpTraits` for `kSoftplus` within
`ROperator_BasicUnary` to address numerical instability issues (Issue root-project#21071).

Changes:
- Implemented exact hexfloat thresholding (0x1.4p+4f) to prevent
  overflow for inputs > 20.0.
- Replaced `std::log(std::exp(x)+1)` with `std::log1p(std::exp(x))`
  to preserve precision for negative inputs.
- Validated via dedicated `TestSofieSoftplus` suite unit testing overflow
  and bit-exact generation.

Fixes root-project#21071
@AdityaDRathore AdityaDRathore force-pushed the feature/sofie-softplus branch from a89f380 to 2021a29 Compare April 2, 2026 18:00
@AdityaDRathore
Copy link
Copy Markdown
Contributor Author

Hi @sanjibansg, thanks for the review

I've added tests following the convention in the Sofie test directory, as you mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tmva][sofie] Improve numerical stability and overflow protection for Softplus operator

4 participants