1 Star 2 Fork 0

李波/LearnPython

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Activators.py 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
李波 提交于 2020-08-24 14:25 +08:00 . partialfullstack
# 1. 当为array的时候,默认d*f就是对应元素的乘积,multiply也是对应元素的乘积,dot(d,f)会转化为矩阵的乘积, dot点乘意味着相加,而multiply只是对应元素相乘,不相加
# 2. 当为mat的时候,默认d*f就是矩阵的乘积,multiply转化为对应元素的乘积,dot(d,f)为矩阵的乘积
import numpy as np
# Relu激活器
class ReluActivator(object):
def forward(self, weighted_input): # 前向计算,计算输出
return max(0, weighted_input)
def backward(self, output): # 后向计算,计算导数
if output > 0:
return 1
else:
return 0
# IdentityActivator激活器.f(x)=x
class IdentityActivator(object):
def forward(self, weighted_input): # 前向计算,计算输出
return weighted_input
def backward(self, output): # 后向计算,计算导数
return 1
# sigmoid激活器
class SigmoidActivator(object):
def forward(self, weighted_input):
return 1.0 / (1.0 + np.exp(-weighted_input))
def backward(self, output):
# return output * (1 - output)
return np.multiply(output, (1 - output)) # 对应元素相乘
# tanh激活器
class TanhActivator(object):
def forward(self, weighted_input):
return 2.0 / (1.0 + np.exp(-2 * weighted_input)) - 1.0
def backward(self, output):
return 1 - output * output
# # softmax激活器
# class SoftmaxActivator(object):
# def forward(self, weighted_input): # 前向计算,计算输出
# return max(0, weighted_input)
#
# def backward(self, output): # 后向计算,计算导数
# return 1 if output > 0 else 0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/libo-sober/learn-python.git
git@gitee.com:libo-sober/learn-python.git
libo-sober
learn-python
LearnPython
master

搜索帮助