# 设置初始值
import numpy as np
def identity_function(x):
return x
def step_function(x):
return np.array(x > 0, dtype=int)
# 逻辑回归
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# 损失函数
def relu(x):
return np.maximum(0, x)
# 1层神经网络
a = np.array([1,2])
print(a)
b = np.array([[5,6],[7,8]])
print("------------")
print(np.dot(a,b))
print("------------")
X = np.array([1.0, 0.5])
print(X)
W1 = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]])
print(W1)
B1 = np.array([0.1, 0.2, 0.3])
print(np.dot(X, W1))
A1 = np.dot(X, W1) + B1
Z1 = sigmoid(A1)
# 2层神经网络
W2 = np.array([[0.1, 0.4], [0.2, 0.5], [0.3, 0.6]])
B2 = np.array([0.1, 0.2])
print(Z1.shape) # (3,)
print(W2.shape) # (3, 2)
print(B2.shape) # (2,)
A2 = np.dot(Z1, W2) + B2
Z2 = sigmoid(A2)
print(Z2)
# 3层神经网络
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)
三层神经网络的基本定义
最新推荐文章于 2024-05-17 11:02:18 发布