Numerically stable sigmoid function #436
Conversation
17bb4ac to
7bc160b
Compare
nkoukpaizan
left a comment
There was a problem hiding this comment.
A few minor comments.
The sensitivity of tanh to mu is different from exp (and to the abs forms), so it makes sense that NaNs occur at different values of mu.
@lukelowry please make sure to document (plot) the different forms we are exploring somewhere (PR, technical document or paper) for future reference.
| \sigma(x) &= \dfrac{1}{1+e^{-\mu x}} \\ | ||
| \rho(x) &= \dfrac{(\mu x+\lvert\mu x\rvert)/2+\log(1+e^{-\lvert\mu x\rvert})}{\mu} \\ | ||
| \sigma(x) &= \dfrac{1}{2}\left(1+\tanh\left(\dfrac{\mu x}{2}\right)\right) \\ | ||
| \rho(x) &= \dfrac{x+\lvert x\rvert}{2}+\dfrac{\ln(1+e^{-\mu\lvert x\rvert})}{\mu} \\ |
There was a problem hiding this comment.
Missed this in a previous merge, but the explanation of the "softplus" form for tanh versus exp . Could
There was a problem hiding this comment.
The implementation of exp definition at very large negative values of tanh version is identical result but stable)
Regarding
I added justifications to the doc for clarity so this tracked information
|
@nkoukpaizan I went ahead and added plots since I already had some available. Let me know what you think. |
nkoukpaizan
left a comment
There was a problem hiding this comment.
There are a couple of rendering issues for CommonMath.md on GH. After those are fixed, this should be good to merge.
@nkoukpaizan Fixed, thank you for catching those rendering issues! |
GitHub MathJax behaves very strangely and is different from VSCode. I am not sure what the issues even was but these changes fixed it
808a046 to
3e350e7
Compare
Description
Updates
CommonMathsmooth step function behavior and documentation, and removes a stale expected-failure marker for the New England contingency-analysis example now that it passes.Proposed changes
tanhform.MUin one place and use it consistently insigmoid,ramp.CommonMathdocumentation.dsigmoidas its unused.CommonMath.mdequations for the tanh sigmoid and smooth ramp form.WILL_FAIL TRUEfromnewengland_ca, sinceContingencyAnalysisnow completes successfully.Checklist
-Wall -Wpedantic -Wconversion -Wextra.Changelog changes N/A
Further comments
The ContingencyAnalysis fix was completely unexpected. I needed to fix this function for my feature branch of the
REECBimplementation to run correctly. I was happy to see that this fixed another issue.@PhilipFackler How often did you encounter this when implementing
ContingencyAnalysis? I am curious, that would be useful for related commentary in the paper.I'd also like to note here that this likely means we can fix/remove the inconsistent scaling that exists in
IEEET1andTGOV1and some other models, I think. The failures were originally thought to be a solver issue but it was aNaN/infissue. Before this change I was unable to makeMUmuch larger than240but now I can increase it to be very large, so I can make the piecewise approximations as very sharp which is helpful for validation purposes