import numpy as np
sigmoid = lambda x:1/(1 + np.exp(-x))
relu = lambda x:(x>0).astype(float)*x
weights = np.array([[1,4],[4,1]])
activation = sigmoid(np.array([1,0.01]))
print("Activations")
activations = list()
for iter in range(10):
activation = sigmoid(activation.dot(weights))
activations.append(activation)
print(activation)
print("\nGradients")
gradient = np.ones_like(activation)
for activation in reversed(activations):
gradient = (activation * (1 - activation) * gradient)
gradient = gradient.dot(weights.transpose())
print(gradient)
print("Relu Activations")
activations = list()
for iter in range(10):
activation = relu(activation.dot(weights))
activations.append(activation)
print(activation)
print("\nRelu Gradients")
gradient = np.ones_like(activation)
for activation in reversed(activations):
gradient = ((activation > 0) * gradient).dot(weights.transpose())
print(gradient)
'''
Activations
[0.93940638 0.96852968]
[0.9919462 0.99121735]
[0.99301385 0.99302901]
[0.9930713 0.99307098]
[0.99307285 0.99307285]
[0.99307291 0.99307291]
[0.99307291 0.99307291]
[0.99307291 0.99307291]
[0.99307291 0.99307291]
[0.99307291 0.99307291]
Gradients
[0.03439552 0.03439552]
[0.00118305 0.00118305]
[4.06916726e-05 4.06916726e-05]
[1.39961115e-06 1.39961115e-06]
[4.81403643e-08 4.81403637e-08]
[1.65582672e-09 1.65582765e-09]
[5.69682675e-11 5.69667160e-11]
[1.97259346e-12 1.97517920e-12]
[8.45387597e-14 8.02306381e-14]
[1.45938177e-14 2.16938983e-14]
Relu Activations
[4.8135251 4.72615519]
[23.71814585 23.98025559]
[119.63916823 118.852839 ]
[595.05052421 597.40951192]
[2984.68857188 2977.61160877]
[14895.13500696 14916.36589628]
[74560.59859209 74496.90592414]
[372548.22228863 372739.30029248]
[1863505.42345854 1862932.18944699]
[9315234.18124649 9316953.88328115]
Relu Gradients
[5. 5.]
[25. 25.]
[125. 125.]
[625. 625.]
[3125. 3125.]
[15625. 15625.]
[78125. 78125.]
[390625. 390625.]
[1953125. 1953125.]
[9765625. 9765625.]
'''
54、深度学习-自学之路-自己搭建深度学习框架-15、解释梯度消失和梯度爆炸的问题。
小宇爱2025-03-03 2:02
相关推荐
机器人零零壹19 分钟前
技术白皮书:iRobotCAM如何解决机器人激光切割应用中的核心难点,从CAD离线编程到双目视觉定位与轨迹自适应提升复杂空间曲线切割的精度、效率与柔性化水平电子元件小说家1 小时前
2026年四季度电感市场观察:AI算力与汽车电子驱动下的选型与验证建议智能硬件网易CodeWave-小码哥1 小时前
支持多模块 Java 微服务导入|CodeWave SDD V4.5.10 上线AI你一生一世2 小时前
不止于时序存储:DolphinDB 如何成为 AI 时代的工业智能底座belldeep2 小时前
python:genesis-world, Genesis-Embodied-AI怕浪猫2 小时前
小程序成长计划上新:10 亿 Token 现在能调 DeepSeek-v4.1-flash了ss2732 小时前
为什么PostgreSQL适合AI场景?七牛云行业应用3 小时前
DeepSeek Super-agent 与 Grok Bot:开源 Agent 架构和聊天助手有何区别维克兜率天3 小时前
【维克】趋势型CTA:期货市场的“追涨杀跌“u1301303 小时前
GitHub 热榜项目:日榜(2026-11-03)