def predict_identity(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 = identity_function(a1) a2 = np.dot(z1, w2) + b2 z2 = identity_function(a2) a3 = np.dot(z2, w3) + b3 y = softmax(a3) return y
def forword(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) return y
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) return y
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 #利用点积进行从输入层到第1层的信号传递 z1 = sigmoid(a1) #使用激活函数转换第1层的输出 a2 = np.dot(z1, W2) + b2 #同上 z2 = sigmoid(a2) #同上 a3 = np.dot(z2, W3) + b3 y = identity_function(a3) #这里使用恒等函数,只是为了和上面保持格式一致 return y #返回网络的计算结果
sys.path.append(os.curdir) import numpy as np from common.functions import sigmoid, identity_function X = np.array([1.0, 0.5]) W1 = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]]) B1 = np.array([0.1, 0.2, 0.3]) A1 = np.dot(X, W1) + B1 Z1 = sigmoid(A1) print(A1) print(Z1) W2 = np.array([[0.1, 0.4], [0.2, 0.5], [0.3, 0.6]]) B2 = np.array([0.1, 0.2]) A2 = np.dot(Z1, W2) + B2 Z2 = sigmoid(A2) W3 = np.array([[0.1, 0.3], [0.2, 0.4]]) B3 = np.array([0.1, 0.2]) A3 = np.dot(Z2, W3) + B3 Y = identity_function(A3) print(Y)