feat: extends interface of Matrix to support for broad range of types

This commit is contained in:
Volodymyr Orlov
2020-03-26 15:28:26 -07:00
parent 84ffd331cd
commit 02b85415d9
27 changed files with 1021 additions and 868 deletions
+1 -43
View File
@@ -1,44 +1,2 @@
pub mod distance;
pub static EPSILON:f64 = 2.2204460492503131e-16_f64;
pub trait NumericExt {
fn ln_1pe(&self) -> f64;
fn sigmoid(&self) -> f64;
}
impl NumericExt for f64 {
fn ln_1pe(&self) -> f64{
if *self > 15. {
return *self;
} else {
return self.exp().ln_1p();
}
}
fn sigmoid(&self) -> f64 {
if *self < -40. {
return 0.;
} else if *self > 40. {
return 1.;
} else {
return 1. / (1. + f64::exp(-self))
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sigmoid() {
assert_eq!(1.0.sigmoid(), 0.7310585786300049);
assert_eq!(41.0.sigmoid(), 1.);
assert_eq!((-41.0).sigmoid(), 0.);
}
}
pub mod num;