v9.1.1
Menu

Sigmoid Function

easyFREEClassificationMachine Learning 1

Implement the sigmoid (logistic) function that maps any real number to the range (0,1)(0, 1).

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}

Given a list of values, apply the sigmoid function to each and return the results.

To avoid overflow for large negative values, use the identity: for z<0z < 0, compute σ(z)=ez1+ez\sigma(z) = \frac{e^z}{1 + e^z}.

Round each result to 4 decimal places.

Example

Input
z = [0, 2, -2]
Output
[0.5, 0.8808, 0.1192]
Reasoning
  • Input: z is a list of real numbers (logits): here [0, 2, -2]. Each value is squashed independently, so the output has the same length, 3.
  • z=0z = 0: e0=1e^{0} = 1, so σ(0)=11+1=0.5\sigma(0) = \frac{1}{1 + 1} = 0.5, exactly halfway. A logit of zero means "no preference either way".
  • z=2z = 2: e−2≈0.13534e^{-2} \approx 0.13534, so σ(2)=11.13534≈0.880797\sigma(2) = \frac{1}{1.13534} \approx 0.880797, which rounds to 0.88080.8808 at 4 decimal places.
  • z=−2z = -2: using the overflow-safe form from the description, σ(−2)=e−21+e−2=0.135341.13534≈0.119203\sigma(-2) = \frac{e^{-2}}{1 + e^{-2}} = \frac{0.13534}{1.13534} \approx 0.119203, giving 0.11920.1192.
  • Output: [0.5, 0.8808, 0.1192], every value strictly between 0 and 1. Notice the symmetry σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z): 0.8808+0.1192=10.8808 + 0.1192 = 1.
  • For huge inputs like ±100\pm 100 the true values sit within 10−4310^{-43} of 0 or 1, so after rounding they appear as 0.00.0 and 1.01.0.

Constraints

  • Input is a list of floats (can be negative, zero, or positive)
  • Return a list of sigmoid values, each rounded to 4 decimal places
  • Handle large positive/negative inputs without overflow

Learn this in

More from Machine Learning 1

solution.py

Test results

Sign in to run your code against the test cases.