From 3f0ff53369366417021b2a0e024ed87367748bf1 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 24 Feb 2019 11:04:27 -0600 Subject: [PATCH] math.functions: add logit function and a test. sigmoid is known as expit in scipy --- basis/math/functions/functions-tests.factor | 1 + basis/math/functions/functions.factor | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index da9630d33f..36a9fbf15c 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -268,6 +268,7 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11 { t } [ 3 15 roots [ 15 ^ 3 .01 ~ ] all? ] unit-test { .5 } [ 0 sigmoid ] unit-test +{ t } [ 0 [ sigmoid logit ] keep .000001 ~ ] unit-test { 1 } [ 12 signum ] unit-test { -1 } [ -5.0 signum ] unit-test diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 026d033a2d..0a0d408426 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -434,8 +434,12 @@ M: float round-to-odd [ (round-to-odd?) ] (float-round) ; [ recip 2pi * 0 swap complex boa e^ ] [ [ ^ * ] 2with map ] tri ; +! expit : sigmoid ( x -- y ) neg e^ 1 + recip ; inline +: logit ( x -- y ) [ ] [ 1 swap - ] bi /f log ; inline + + GENERIC: signum ( x -- y ) M: real signum sgn ;