1\ logistic     The Logistic function and its first derivative
2\     logistic =   Exp( c + a x ) / (1 + Exp( c + a x ) )
3\   d_logistic = a Exp( c + a x ) / (1 + Exp( c + a x ) )^2
4
5\ Forth Scientific Library Algorithm #4
6
7\ This code conforms with ANS requiring:
8\      1. The Floating-Point word set
9\
10
11\ (c) Copyright 1994 Everett F. Carter.  Permission is granted by the
12\ author to use this software for any application provided this
13\ copyright notice is preserved.
14
15
16cr .( Logistic          V1.2           17 October 1994   EFC )
17
18
19: logistic ( --, f: x a c -- z )
20        FROT FROT
21        F* F+
22        FEXP
23        FDUP 1.0e0 F+
24        F/
25;
26
27: d_logistic ( -- , f: x a c -- z )
28        FSWAP FROT
29        FOVER F* FROT F+
30        FEXP
31
32        FDUP 1.0e0 F+ FDUP F*
33        F/ F*
34;
35
36\ Examples % 1.0 % 1.0 % 0.0 logistic f.  0.731059
37\          % 3.2 % 1.5 % 0.2 logistic f.  0.993307
38\          % 3.2 % 1.5 % 0.2 d_logistic f. 0.00997209
39
40# The Code
41
42~~~
43:logistic (-,f:xac-z)
44  f:rot f:rot
45  f:* f:+
46  f:E f:swap f:power
47  f:dup .1.0e0 f:+
48  f:/ ;
49
50:d_logistic (-,f:xac-z)
51  f:swap f:rot
52  f:over f:* f:rot f:+
53  f:E f:swap f:power
54  f:dup .1.0e0 f:+ f:dup f:*
55  f:/ f:* ;
56~~~
57
58# Tests
59
60```
61.1.0 .1.0 .0.0 logistic f:put nl
62.3.2 .1.5 .0.2 logistic f:put nl
63```
64