TensorFlow - 激活函数

TensorFlow - 激活函数

flyfish

激活函数(Activation function)目标是为神经网络引入非线性。

评价某个激活函数是否有用时,可考虑下列为数不多的几个主要因素。
1)该函数应是单调的,这样输出便会随着输入的增长而增长,从而使利用梯度下降法寻找局部极值点成为可能。
2)该函数应是可微分的,以保证该函数定义域内的任意一点上导数都存在,从而使得梯度下降法能够正常使用来自这类激活函数的输出。

任何满足这些条件的函数都可用作激活函数。

TensorFlow提供的多种激活函数

1.tf.nn.relu

2.tf.sigmoid

3. tf.tanh

4. softplus
log(exp(features)+1)

import tensorflow as tf

features  = tf.constant([-10, 12.0])
with tf.Session() as sess:
    rt = tf.nn.softplus(features )
    print(sess.run(rt))

输出
[ 4.54177061e-05 1.20000057e+01]

5.tf.nn.dropout

依据某个可配置的概率将输出设为0.0。

dropout

n. 中途退学;辍学学生

import tensorflow as tf
features = tf.constant([-20.0,-10.0,10.0,20.0])

sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)

dp = tf.nn.dropout(features,keep_prob=0.5)
rt=sess.run([features,dp])
print(rt)

[array([-20., -10., 10., 20.], dtype=float32), array([-40., -0., 20., 40.], dtype=float32)]

tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None)
keep_prob : float类型,每个元素被保留下来的概率
noise_shape : 一个1维的int32张量,代表了随机产生“保留/丢弃”标志的shape。

不保留元素为0,当元素被保留下来时,该元素的输出值将被放大到原来的1/keep_prob倍

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西笑生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值