HBU深度学习实验5-前馈神经网络(1)

净活性值

活性值和净活性值

什么是活性值?

神经网络中每个神经元在接收输入后计算得到的输出值。

什么是净活性值?

在激活函数应用之前,神经元接收到的加权输入的总和,净活性值在经过激活函数后,会得到活性值。

使用pytorch计算一组输入的净活性值z,净活性值z经过一个非线性函数f(·)后,得到神经元的活性值a

import torch

# 2个特征数为5的样本
X = torch.rand(2, 5)

# 含有5个参数的权重向量
w = torch.rand(5, 1)
# 偏置项
b = torch.rand(1, 1)


z = torch.matmul(X, w) + b
print("input X:", X)
print("weight w:", w, "\nbias b:", b)
print("output z:", z)

torch.nn.Linear()

import torch
import torch.nn as nn

# 定义输入特征数和输出特征数
features_in = 5
features_out = 1

# 创建线性层(不使用偏置)
linear_layer = nn.Linear(features_in, features_out, bias=False)

# 2个特征数为5的样本
X = torch.rand(2, features_in)

# 使用线性层进行前向传播
z = linear_layer(X)

print("input X:", X)
print("weight w:", linear_layer.weight.data)  # 获取权重
print("output z:", z)

 

features_in:

含义: 输入特征的数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值