对于输入层和隐藏层都需要补上一个值为1的偏置x0,权重由随机数生成
代码:
import numpy as np
def sigmoid(x):
return 1/(1+np.exp(-x))
def net(X):
theta1 = np.random.uniform(size=(3, 4))
print(theta1)
hidden_input = sigmoid(np.matmul(theta1,X))
print('hidden_input\n',hidden_input)
hidden_input = np.insert(hidden_input, 0, [1], axis=0)
print('hidden_input\n',hidden_input)
output = None
theta2 = np.random.uniform(size=(1, 4))
print(theta2)
output = sigmoid(np.matmul(theta2, hidden_input))
print(output)
return output
例子: 做了若干次尝试,都发现output稳定在0.6-0.8中间,这是什么原理呢?
|