All problems
Softplus
Problem
Apply the softplus activation element-wise: softplus(x) = log(1 + exp(x)), computed as max(x, 0) + log1p(exp(-|x|)) so large magnitudes do not overflow.
The signature is softplus(x).
Hint
Softplus is a smooth ReLU; use log1p and the absolute value to stay stable.
Test cases
case 1
in: [[0]]
expected: [0.6931471806]
case 2
in: [[1,-1]]
expected: [1.3132616875,0.3132616875]
case 3
in: [[1000,-1000]]
expected: [1000,0]
case 4
in: [[2,3]]
expected: [2.126928011,3.0485873516]
Starter codePython
import math
def softplus(x):
# Your code here
pass4 test cases · run your code against them in the editor