Error Using sigmoid Function

Asked 2 years ago, Updated 2 years ago, 36 views

Currently, I am studying Deep learning, and until yesterday I did not get an error when I tried to run it with the code below, but I just wanted to start studying, so I started PC 下記 I ran the code below, and somehow.I don't understand why I was able to do it until yesterday, and suddenly I couldn't.
Please let me know about this phenomenon below.Thank you for your cooperation.

import numpy as np

default_network():
    network={}
    network['W1'] = np.array([0.1, 0.3, 0.5], [0.2, 0.4, 0.6]])
    network ['b1'] = np.array ([0.1, 0.2, 0.3])
    network['W2'] = np.array([0.1, 0.4], [0.2, 0.5], [0.3, 0.6]])
    network['b2'] = np.array([0.1,0.2])
    network ['W3'] = np.array([0.1,0.3], [0.2,0.4]])
    network['b3'] = np.array([0.1,0.2])
    
    return network

def forward (network, x):
    W1, W2, W3 = network ['W1'], network ['W2', network ['W3']
    b1, b2, b3 = network['b1'], network['b2'], network['b3']
    
    a1 = np.dot(x,W1) + b1
    z1 = sigmoid(a1)
    a2 = np.dot(z1,W2) + b2
    z2 = sigmoid(a2)
    a3 = np.dot(z2,W3) + b3
    y = identity_function(a3)
    
    returny

network=init_network()
x = np.array ([1.0, 0.5])
y = forward (network, x)
print(y)
NameError Traceback (most recent call last)
<ipython-input-61-d459db580be1>in<module>
     27 network = init_network()
     28 x = np.array ([1.0, 0.5])
--- > 29y = forward (network, x)
     30 print(y)

<ipython-input-61-d459db580be1>in forward (network, x)
     17 
     18 a1 = np.dot(x, W1) + b1
--- > 19z1 = sigmoid(a1)
     20a2 = np.dot(z1,W2) + b2
     21 z2 = sigmoid(a2)

NameError: name 'sigmoid' is not defined

python python3

2022-09-30 17:12

1 Answers

Based on the output, you may be using the python kernel of Jupiter Notebook, where "yesterday" was used to define the sigmoid function when you ran some cells, and "today" was reset, and when you tried to run the cells from the beginning again, it seemed to be an error.

The Jupiter Notebook (unless otherwise re-runs) takes over the changed state of the cell that it has run so far.Therefore, even if the program looks the same, the results may differ if the initial state is different due to cell content changes or deletions.

If the program listed in the questionnaire is the entire notebook, try defining the sigmoid function first.


2022-09-30 17:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.