Logistic function

?

Percentage Accurate: 99.8% → 99.8%
Time: 8.7s
Precision: binary32
Cost: 6656

?

\[0 \leq s \land s \leq 1.0651631\]
\[\frac{1}{1 + e^{\frac{-x}{s}}} \]
\[\begin{array}{l} \\ \frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow (exp -1.0) (/ x s)))))
float code(float x, float s) {
	return 1.0f / (1.0f + expf((-x / s)));
}
float code(float x, float s) {
	return 1.0f / (1.0f + powf(expf(-1.0f), (x / s)));
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + (exp((-1.0e0)) ** (x / s)))
end function
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))
end
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(Float32(-1.0)) ^ Float32(x / s))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + exp((-x / s)));
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + (exp(single(-1.0)) ^ (x / s)));
end
\frac{1}{1 + e^{\frac{-x}{s}}}
\begin{array}{l}

\\
\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 14 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 99.9%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Applied egg-rr99.9%

    \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}} \]
    Step-by-step derivation

    [Start]99.9%

    \[ \frac{1}{1 + e^{\frac{-x}{s}}} \]

    div-inv [=>]99.9%

    \[ \frac{1}{1 + e^{\color{blue}{\left(-x\right) \cdot \frac{1}{s}}}} \]

    exp-prod [=>]80.2%

    \[ \frac{1}{1 + \color{blue}{{\left(e^{-x}\right)}^{\left(\frac{1}{s}\right)}}} \]

    neg-mul-1 [=>]80.2%

    \[ \frac{1}{1 + {\left(e^{\color{blue}{-1 \cdot x}}\right)}^{\left(\frac{1}{s}\right)}} \]

    exp-prod [=>]80.2%

    \[ \frac{1}{1 + {\color{blue}{\left({\left(e^{-1}\right)}^{x}\right)}}^{\left(\frac{1}{s}\right)}} \]

    pow-pow [=>]99.9%

    \[ \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(x \cdot \frac{1}{s}\right)}}} \]

    div-inv [<=]99.9%

    \[ \frac{1}{1 + {\left(e^{-1}\right)}^{\color{blue}{\left(\frac{x}{s}\right)}}} \]
  3. Final simplification99.9%

    \[\leadsto \frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}} \]

Alternatives

Alternative 1
Accuracy99.8%
Cost6656
\[\frac{1}{1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}} \]
Alternative 2
Accuracy99.8%
Cost3456
\[\frac{1}{1 + e^{\frac{-x}{s}}} \]
Alternative 3
Accuracy64.2%
Cost676
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + 0.5 \cdot \left(x \cdot \left(x \cdot \frac{-1}{s \cdot \left(-s\right)}\right)\right)}\\ \end{array} \]
Alternative 4
Accuracy63.4%
Cost580
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + 0.5 \cdot \left(x \cdot \frac{x}{s \cdot s}\right)}\\ \end{array} \]
Alternative 5
Accuracy61.9%
Cost516
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x}{2 \cdot \left(s \cdot s\right)}}\\ \end{array} \]
Alternative 6
Accuracy58.7%
Cost452
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 1:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\frac{s}{x} \cdot \frac{s}{x}\right)\\ \end{array} \]
Alternative 7
Accuracy58.7%
Cost452
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 1:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s}{x \cdot \frac{x}{s}}\\ \end{array} \]
Alternative 8
Accuracy61.5%
Cost452
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\ \end{array} \]
Alternative 9
Accuracy49.8%
Cost388
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \end{array} \]
Alternative 10
Accuracy48.4%
Cost356
\[\begin{array}{l} t_0 := \frac{-x}{s}\\ \mathbf{if}\;t_0 \leq 1:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 11
Accuracy46.8%
Cost228
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9999999494757503 \cdot 10^{-5}:\\ \;\;\;\;s \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 12
Accuracy48.1%
Cost228
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9999999494757503 \cdot 10^{-5}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 13
Accuracy46.8%
Cost164
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9999999494757503 \cdot 10^{-5}:\\ \;\;\;\;\frac{s}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 14
Accuracy35.7%
Cost32
\[0.5 \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (x s)
  :name "Logistic function"
  :precision binary32
  :pre (and (<= 0.0 s) (<= s 1.0651631))
  (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))