2025年sigmoid 函数(sigmoid函数和tanh函数)

sigmoid 函数(sigmoid函数和tanh函数)以下是使用 Python 绘制 5 种常见激活函数 的图的代码 import numpy as np import matplotlib pyplot as plt em Sigmoid em em 激活函数 em def em sigmoid em x return 1 1 np

大家好,我是讯享网,很高兴认识大家。

以下是使用Python绘制5种常见激活函数的图的代码:


讯享网

import numpy as np import matplotlib.pyplot as plt # <em>Sigmoid</em> <em>激活函数</em> def <em>sigmoid</em>(x): return 1 / (1 + np.exp(-x)) # <em>tanh</em> <em>激活函数</em> def <em>tanh</em>(x): return np.<em>tanh</em>(x) # Re<em>LU</em> <em>激活函数</em> def re<em>lu</em>(x): return np.maximum(0, x) # Leaky Re<em>LU</em> <em>激活函数</em> def leaky_re<em>lu</em>(x, alpha=0.01): return np.maximum(alpha * x, x) # E<em>LU</em> <em>激活函数</em> def e<em>lu</em>(x, alpha=1.0): return np.where(x &gt; 0, x, alpha * (np.exp(x) - 1)) # 生成 x 值 x = np.linspace(-10, 10, 100) # 绘制<em>激活函数</em>图像 plt.figure(figsize=(10, 6)) plt.plot(x, <em>sigmoid</em>(x), label=&#39;<em>Sigmoid</em>&#39;) plt.plot(x, <em>tanh</em>(x), label=&#39;<em>tanh</em>&#39;) plt.plot(x, re<em>lu</em>(x), label=&#39;Re<em>LU</em>&#39;) plt.plot(x, leaky_re<em>lu</em>(x), label=&#39;Leaky Re<em>LU</em>&#39;) plt.plot(x, e<em>lu</em>(x), label=&#39;E<em>LU</em>&#39;) plt.xlabel(&#39;x&#39;) plt.ylabel(&#39;Activation&#39;) plt.title(&#39;Activation Functions&#39;) plt.legend() plt.grid(True) plt.show() 

讯享网

希望这个代码可以帮助你绘制出Sigmoidtanh、ReLU、Leaky ReLU和ELU激活函数的图像。

小讯
上一篇 2025-06-05 18:23
下一篇 2025-05-31 23:28

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/139686.html