def test_sigmoid_2_backward(self): print('\n==================================') print(' Test sigmoid backward ') print('==================================') np.random.seed(123) x = np.random.randn(5, 5) sigmoid = Sigmoid() out = sigmoid.forward(x) dx = sigmoid.backward(x, 0.0) correct_dx = [ [-0.2048748, 0.19633044, 0.06934706, -0.22376078, -0.13318844], [0.22297909, -0.18096644, -0.10244393, 0.21720183, -0.18059114], [-0.15157559, -0.02362423, 0.2236528, -0.14447372, -0.10570044], [-0.10362309, 0.1971545, 0.1984592, 0.19703887, 0.09303448], [0.16139223, 0.22364718, -0.18937883, 0.21188431, -0.21658554] ] e = rel_error(correct_dx, dx) print('Relative difference:', e) self.assertTrue(e <= 1e-7)
def test_sigmoid_1_forward(self): print('\n==================================') print(' Test sigmoid forward ') print('==================================') x = np.linspace(-1.5, 1.5, num=30).reshape(6, 5) sigmoid = Sigmoid() out = sigmoid.forward(x) correct_out = [ [0.18242552, 0.19836387, 0.21532798, 0.23332061, 0.25233322], [0.27234476, 0.29332071, 0.31521239, 0.33795656, 0.36147556], [0.3856778, 0.41045882, 0.4357028, 0.46128455, 0.48707185], [0.51292815, 0.53871545, 0.5642972, 0.58954118, 0.6143222], [0.63852444, 0.66204344, 0.68478761, 0.70667929, 0.72765524], [0.74766678, 0.76667939, 0.78467202, 0.80163613, 0.81757448] ] e = rel_error(correct_out, out) print('Relative difference:', e) self.assertTrue(e <= 5e-8)
The results should be exactly same as below: 결과는 아래와 일치해야 합니다: Forward: [[0.26894142 0.88079708 0.62245933] [0.5 0.47502081 0.52497919]] Backward: [[0. 0.10499359 0. ] [0.25 0. 0.24937604]] """ sigmoid = Sigmoid() temp4 = np.array([[-1, 2, 0.5], [0.0, -0.1, 0.1]]) temp5 = np.array([[0, 1, 0], [1, 0, 1]]) print('Forward: \n', sigmoid.forward(temp4)) print('Backward: \n', sigmoid.backward(temp5)) print() print('===== InputLayer Check =====') """ The results should be exactly same as below: 결과는 아래와 일치해야 합니다: Forward: [[1.69405863 0. ] [1.41846232 0. ]] dW: [[ 1. 0.] [-3. 0.] [-2. 0.]]