math.functions: adding generalized signum function. Fixes #509.
parent
af8f23a78c
commit
31c7bd8e86
|
@ -336,3 +336,7 @@ HELP: roots
|
||||||
HELP: sigmoid
|
HELP: sigmoid
|
||||||
{ $values { "x" number } { "y" number } }
|
{ $values { "x" number } { "y" number } }
|
||||||
{ $description "Outputs the sigmoid, an S-shaped \"logistic\" function, from 0 to 1, of the number " { $snippet "x" } "." } ;
|
{ $description "Outputs the sigmoid, an S-shaped \"logistic\" function, from 0 to 1, of the number " { $snippet "x" } "." } ;
|
||||||
|
|
||||||
|
HELP: signum
|
||||||
|
{ $values { "x" number } { "y" number } }
|
||||||
|
{ $description "Calculates the signum value. For a real number, " { $snippet "x" } ", this is its sign (-1, 0, or 1). For a complex number, " { $snippet "x" } ", this is the point on the unit circle of the complex plane that is nearest to " { $snippet "x" } "." } ;
|
||||||
|
|
|
@ -242,3 +242,9 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
|
||||||
{ t } [ 3 15 roots [ 15 ^ 3 .01 ~ ] all? ] unit-test
|
{ t } [ 3 15 roots [ 15 ^ 3 .01 ~ ] all? ] unit-test
|
||||||
|
|
||||||
{ .5 } [ 0 sigmoid ] unit-test
|
{ .5 } [ 0 sigmoid ] unit-test
|
||||||
|
|
||||||
|
{ 1 } [ 12 signum ] unit-test
|
||||||
|
{ -1 } [ -5.0 signum ] unit-test
|
||||||
|
{ 0 } [ 0 signum ] unit-test
|
||||||
|
{ t } [ C{ 3.0 -1.5 } signum C{ 0.8944271909999157 -0.4472135954999579 } 1e-10 ~ ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -364,3 +364,9 @@ M: real atan >float atan ; inline
|
||||||
[ iota [ ^ * ] with with map ] tri ;
|
[ iota [ ^ * ] with with map ] tri ;
|
||||||
|
|
||||||
: sigmoid ( x -- y ) neg e^ 1 + recip ; inline
|
: sigmoid ( x -- y ) neg e^ 1 + recip ; inline
|
||||||
|
|
||||||
|
GENERIC: signum ( x -- y )
|
||||||
|
|
||||||
|
M: real signum sgn ;
|
||||||
|
|
||||||
|
M: complex signum dup abs / ;
|
||||||
|
|
Loading…
Reference in New Issue