Skip to content

Use an overflow-free analysis-confidence sigmoid - #11

Merged
peterdsharpe merged 1 commit into
peterdsharpe:masterfrom
cdhainaut:fix/stable-confidence-sigmoid
Sep 26, 2026
Merged

peterdsharpe merged 1 commit into
peterdsharpe:masterfrom
cdhainaut:fix/stable-confidence-sigmoid

Conversation

@cdhainaut

Copy link
Copy Markdown
Contributor

Summary

Replace the clipped exponential form of the analysis-confidence sigmoid with the mathematically equivalent overflow-free form

0.5 * (1 + tanh(x / 2))

and add a public-API regression test that evaluates a vectorized case far outside the training distribution and checks that both the forward values and CasADi MX reverse derivatives remain finite.

Context

In NeuralFoil 0.2.2, sufficiently negative confidence logits can overflow exp(-x). The forward aerodynamic outputs remain finite, but the overflowing node can contaminate an MX reverse sweep with 0 * inf, producing NaN derivatives.

Current master already prevents the reproducer from failing by clipping the sigmoid input. The tanh form removes the overflowing exponential path and the float64-derived clipping constants altogether while preserving the sigmoid values to floating-point precision over the active range.

Validation

python -m pytest tests -q: 32 passed.

The regression case produces non-finite MX reverse entries at indices 5, 6, and 7 with the installed NeuralFoil 0.2.2, and finite forward and reverse values with this change. The two sigmoid forms differ by at most 2.22e-16 over 20,001 points on [-40, 40].

Fixes #10.

@peterdsharpe
peterdsharpe merged commit b25ea2b into peterdsharpe:master Sep 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MX reverse mode produces NaN gradients when the analysis confidence sigmoid overflows

2 participants