实现sigmoid_激活函数-sigmoid函数(logistic函数)

8fbc02df973b42b85516cc5a623cff15.png

sigmoid函数(sigmoid function)或logistic函数(logistic function)称为logistic函数的原因为该函数是两类别逻辑回归模型的预测表达式

表达式:

0640b43c0904bfec19d375d10d256434.png

导数:

a8ecd36e01cccd26019823e89e9a872a.png

特点:导数由其本身表示,无论是在理论上还是实现上,这个特性都非常有用。

作用:除了作为两类别逻辑回归模型的预测表达式外,常作为神经网络隐藏层、两类别分类输出层的激活函数

图形:

6aa29fbbfa881fe819863ef3088065d4.png

代码:

import theano
import theano.tensor as T
import numpy as np
from matplotlib import pyplot as plt

x = T.dvector('x')
y = T.nnet.sigmoid(x)

J, updates = theano.scan(lambda i, y, x : T.grad(y[i], x), 
sequences=T.arange(y.shape[0]), 
non_sequences=[y, x])
f = theano.function([x], [y, T.sum(J,axis=1)], updates=updates)

x_data = np.arange(-10, 10, 0.01)
y_data, y_differential_data = f(x_data)

plt.figure(figsize=(12, 6))
ax = plt.subplot(2,2,1)
plt.plot(x_data, y_data)
ax.set_title('sigmoid')

ax = plt.subplot(2,2,3)
plt.plot(x_data, y_differential_data)
ax.set_title('differential')

ax = plt.subplot(2,2,2)
plt.plot(x_data, y_data, label='sigmoid')
plt.plot(x_data, y_differential_data, label='sigmoid differential')
plt.axhline(y=0.25,ls=":",c="grey")#添加水平直线
plt.axvline(x=0,ls=":",c="grey")#添加垂直直线
ax.set_title('sigmoid and differential')

plt.show()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值