fix sigmoid implementation stability in pim-simulator
All checks were successful
Validate Operations / validate-operations (push) Successful in 23m4s

This commit is contained in:
NiccoloN
2026-04-23 10:34:29 +02:00
parent 89b3501aa8
commit cff929a083

View File

@@ -55,16 +55,24 @@ pub trait HasSigm {
impl HasSigm for f32 { impl HasSigm for f32 {
fn sigm(self) -> Self { fn sigm(self) -> Self {
if self >= 0.0 {
1.0 / (1.0 + (-self).exp())
} else {
let ex = self.exp(); let ex = self.exp();
ex / (1.0 + ex) ex / (1.0 + ex)
} }
}
} }
impl HasSigm for f64 { impl HasSigm for f64 {
fn sigm(self) -> Self { fn sigm(self) -> Self {
if self >= 0.0 {
1.0 / (1.0 + (-self).exp())
} else {
let ex = self.exp(); let ex = self.exp();
ex / (1.0 + ex) ex / (1.0 + ex)
} }
}
} }
pub trait HasExp { pub trait HasExp {