np expzmax will overflow 1 0 np expzmin will overflow naive implementation of np log1 np expzmax will overflow naive implementation of z np log1 1 np expzmin will throw zerodivisionerror np exp z_max will overflow 1 0 np exp z_min will overflow naive implementation of np log 1 np exp z_max will overflow naive implementation of z np log 1 1 np exp z_min will throw zerodivisionerror
import sys

import numpy as np

from mla.neuralnet.activations import *


def test_softplus():
    
    z_max = np.log(sys.float_info.max) + 1.0e10
    
    z_min = np.log(sys.float_info.min) - 1.0e10
    inputs = np.array([0.0, 1.0, -1.0, z_min, z_max])
    
    
    
    outputs = np.array([np.log(2.0), np.log1p(np.exp(1.0)), np.log1p(np.exp(-1.0)), 0.0, z_max])

    assert np.allclose(outputs, softplus(inputs))