Torch-nn学习: Simpley Layer

本文深入探讨Torch-nn库中的Simple Layer,重点介绍Linear层的工作原理,即线性变换y = Ax + b。通过这个基本的数学公式,解释如何在神经网络中进行特征线性组合和偏置添加。
摘要由CSDN通过智能技术生成

1.Linear:y = Ax + b

module = nn.Linear(inputDimension, outputDimension, [bias = true])
 module = nn.Linear(10, 5)  -- 10 inputs, 5 outputs
 print(module.weight)	//W
 print(module.bias)	//b
 
  
 print(module.gradWeight)
 print(module.gradBias)
2.SparseLinear: y = Ax + b
module = nn.SparseLinear(10000, 2)  -- 10000 inputs, 2 outputs
x = torch.Tensor({ {
     1, 0.1}, {
     2, 0.3}, {
     10, 0.3}, {
     31, 0.2} })	//dim not larger than 10000


3.Bilinear: forall k: y_k = x_1 A_k x_2 + b
module = nn.Bilinear(inputDimension1, inputDimension2, outputDimension, [bias = true])



4.Dropout:前向跟后向作用于相同位置,缩放了1/(1 - P)
module = nn.Dropout(p)
> module:forward(x)
  0   4   0   0
 10  12   0  16
[torch.DoubleTensor of dimension 2x4]

> module:backward(x, x:clone():fill(1))
 0  2  0  0
 2  2  0  2
[torch.DoubleTensor of dimension 2x4]


5.SpatialDropout:

module = nn.SpatialDropout(p)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值