栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

三层神经网络的基本定义

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

三层神经网络的基本定义

# 设置初始值
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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/740719.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号