softplus函数(softplus function):ζ(x)=ln(1+exp(x)).

softplus函数可以用来产生正态分布的β和σ参数,因为它的范围是(0,∞)。当处理包含sigmoid函数的表达式时它也经常出现。softplus函数名字来源于它是另外一个函数的平滑(或”软化”)形式,这个函数是x+=max(0,x)。softplus 是对 ReLU 的平滑逼近的解析函数形式。

softplus函数别设计成正部函数(positive part function)的平滑版本,这个正部函数是指x+=max{0,x}。与正部函数相对的是负部函数(negative part function)x-=max{0, -x}。为了获得类似负部函数的一个平滑函数,我们可以使用ζ(-x)。就像x可以用它的正部和负部通过等式x+-x-=x恢复一样,我们也可以用同样的方式对ζ(x)和ζ(-x)进行操作,就像下式中那样:ζ(x) -ζ(-x)=x.

Rectifier:In the context of artificial neural networks, the rectifier is an activation function defined as:

f(x)=max(0,x)

where x is the input to a neuron. This activation function was first introduced to a dynamical network by Hahnloser et al. in a 2000 paper in Nature. It has been used in convolutional networks more effectively than the widely used logistic sigmoid (which is inspired by probability theory; see logistic regression) and its more practical counterpart, the hyperbolic tangent. The rectifier is, as of 2015, the most popular activation function for deep neural networks.

A unit employing the rectifier is also called a rectified linear unit (ReLU).

A smooth approximation to the rectifier is the analytic function: f(x)=ln(1+ex), which is called the softplus function. The derivative of softplus is: f’(x)=ex/(ex+1)=1/(1+e-x), i.e. the logistic function.

Rectified linear units(ReLU) find applications in computer vision and speech recognition  using deep neural nets.

Noisy ReLUs: Rectified linear units can be extended to include Gaussian noise, making them noisy ReLUs, giving: f(x)=max(0, x+Y), with Y∽N(0, σ(x)). Noisy ReLUs have been used with some success in restricted Boltzmann machines for computer vision tasks.

Leaky ReLUs:allow a small, non-zero gradient when the unit is not active:

Parametric ReLUs take this idea further by making the coefficient of leakage into a parameter that is learned along with the other neural network parameters:

Note that for a≤1, this is equivalent to: f(x)=max(x, ax), and thus has a relation to "maxout" networks.

ELUs:Exponential linear units try to make the mean activations closer to zero which speeds up learning. It has been shown that ELUs can obtain higher classification accuracy than ReLUs:

a is a hyper-parameter to be tuned and a≥0 is a constraint.

以上内容摘自: 《深度学习中文版》和 维基百科

以下是C++测试code:

#include "funset.hpp"
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include "common.hpp"

// ========================= Activation Function: ELUs ========================
template<typename _Tp>
int activation_function_ELUs(const _Tp* src, _Tp* dst, int length, _Tp a = 1.)
{
	if (a < 0) {
		fprintf(stderr, "a is a hyper-parameter to be tuned and a>=0 is a constraint\n");
		return -1;
	}

	for (int i = 0; i < length; ++i) {
		dst[i] = src[i] >= (_Tp)0. ? src[i] : (a * (exp(src[i]) - (_Tp)1.));
	}

	return 0;
}

// ========================= Activation Function: Leaky_ReLUs =================
template<typename _Tp>
int activation_function_Leaky_ReLUs(const _Tp* src, _Tp* dst, int length)
{
	for (int i = 0; i < length; ++i) {
		dst[i] = src[i] > (_Tp)0. ? src[i] : (_Tp)0.01 * src[i];
	}

	return 0;
}

// ========================= Activation Function: ReLU =======================
template<typename _Tp>
int activation_function_ReLU(const _Tp* src, _Tp* dst, int length)
{
	for (int i = 0; i < length; ++i) {
		dst[i] = std::max((_Tp)0., src[i]);
	}

	return 0;
}

// ========================= Activation Function: softplus ===================
template<typename _Tp>
int activation_function_softplus(const _Tp* src, _Tp* dst, int length)
{
	for (int i = 0; i < length; ++i) {
		dst[i] = log((_Tp)1. + exp(src[i]));
	}

	return 0;
}

int test_activation_function()
{
	std::vector<double> src{ 1.23f, 4.14f, -3.23f, -1.23f, 5.21f, 0.234f, -0.78f, 6.23f };
	int length = src.size();
	std::vector<double> dst(length);

	fprintf(stderr, "source vector: \n");
	fbc::print_matrix(src);
	fprintf(stderr, "calculate activation function:\n");
	fprintf(stderr, "type: sigmoid result: \n");
	fbc::activation_function_sigmoid(src.data(), dst.data(), length);
	fbc::print_matrix(dst);
	fprintf(stderr, "type: sigmoid fast result: \n");
	fbc::activation_function_sigmoid_fast(src.data(), dst.data(), length);
	fbc::print_matrix(dst);
	fprintf(stderr, "type: softplus result: \n");
	fbc::activation_function_softplus(src.data(), dst.data(), length);
	fbc::print_matrix(dst);
	fprintf(stderr, "type: ReLU result: \n");
	fbc::activation_function_ReLU(src.data(), dst.data(), length);
	fbc::print_matrix(dst);
	fprintf(stderr, "type: Leaky ReLUs result: \n");
	fbc::activation_function_Leaky_ReLUs(src.data(), dst.data(), length);
	fbc::print_matrix(dst);
	fprintf(stderr, "type: Leaky ELUs result: \n");
	fbc::activation_function_ELUs(src.data(), dst.data(), length);
	fbc::print_matrix(dst);

	return 0;
}

GitHubhttps://github.com/fengbingchun/NN_Test

激活函数之ReLU/softplus介绍及C++实现的更多相关文章

  1. Mish:一个新的SOTA激活函数,ReLU的继任者

    Mish:一个新的SOTA激活函数,ReLU的继任者 CVer 昨天   以下文章来源于AI公园 ,作者ronghuaiyang AI公园 专注分享干货的AI公众号,图像处理,NLP,深度学习,机器学 ...

  2. 激活函数(relu,prelu,elu,+BN)对比on cifar10

    激活函数(relu,prelu,elu,+BN)对比on cifar10   可参考上一篇: 激活函数 ReLU.LReLU.PReLU.CReLU.ELU.SELU  的定义和区别   一.理论基础 ...

  3. 神经网络中的激活函数tanh sigmoid RELU softplus softmatx

    所谓激活函数,就是在神经网络的神经元上运行的函数,负责将神经元的输入映射到输出端.常见的激活函数包括Sigmoid.TanHyperbolic(tanh).ReLu. softplus以及softma ...

  4. 神经网络激活函数sigmoid relu tanh 为什么sigmoid 容易梯度消失

    https://blog.csdn.net/danyhgc/article/details/73850546 什么是激活函数 为什么要用 都有什么 sigmoid ,ReLU, softmax 的比较 ...

  5. Tensorflow 2.0 深度学习实战 —— 详细介绍损失函数、优化器、激活函数、多层感知机的实现原理

    前言 AI 人工智能包含了机器学习与深度学习,在前几篇文章曾经介绍过机器学习的基础知识,包括了监督学习和无监督学习,有兴趣的朋友可以阅读< Python 机器学习实战 >.而深度学习开始只 ...

  6. 激活函数(ReLU, Swish, Maxout)

    神经网络中使用激活函数来加入非线性因素,提高模型的表达能力. ReLU(Rectified Linear Unit,修正线性单元) 形式如下: \[ \begin{equation} f(x)= \b ...

  7. 【机器学习】激活函数(ReLU, Swish, Maxout)

    https://blog.csdn.net/ChenVast/article/details/81382939 神经网络中使用激活函数来加入非线性因素,提高模型的表达能力. ReLU(Rectifie ...

  8. ReLU激活函数:简单之美

    出自 http://blog.csdn.net/cherrylvlei/article/details/53149381 导语 在深度神经网络中,通常使用一种叫修正线性单元(Rectified lin ...

  9. TensorFlow神经网络中的激活函数

    激活函数是人工神经网络的一个极其重要的特征.它决定一个神经元是否应该被激活,激活代表神经元接收的信息与给定的信息有关. 激活函数对输入信息进行非线性变换. 然后将变换后的输出信息作为输入信息传给下一层 ...

随机推荐

  1. 发布mvc3 遇到的HTTP错误 403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    今天在发布别人提供的MVC3的程序,正常部署后浏览报错,错误内容如图: 根据IIS提供的解决办法,启用目录浏览,刷新页面发现确实不报错了,但页面是以目录显示的,如图 虽然解决了报错问题,但不是正常的效 ...

  2. cdoj1329卿学姐与魔法

    地址:http://acm.uestc.edu.cn/#/problem/show/1329 题目: 卿学姐与魔法 Time Limit: 1200/800MS (Java/Others)     M ...

  3. 阿里云服务器: centos7 ftp安装

    阿里云服务器: centos7 ftp安装 ftp需要您参考下面链接和附件开放安全组20.21.1024-65535 后查看是否正常. 配置步骤如下, 1, 如果没有安装ftp,需要先安装 yum - ...

  4. C++类中成员变量的初始化总结

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  5. 关于PropertyGrid控件的排序问题

    前些天,由于在项目中需要用到PropertyGrid这个控件,展现其所在控件的某些属性,由于有些控件的属性较多,不易浏览,而且PropertyGrid的排序默认的按照字母的顺序排列的,这样导致在在某些 ...

  6. 初涉Rx套餐 之RxBinding(让你的事件流程更清晰)

    转载请注明出处:王亟亟的大牛之路 最近下班回家都在WOW,周末就爆肝,感觉人都要GO DIE了,昨天下午看了看RxBinding相关的功能感觉还是蛮强大的,所提供的API也是相当丰富(基本Rx套餐都是 ...

  7. MySQL数据库中tinyint类型字段读取数据为true和false (MySQL的boolean和tinyint(1))

    数据库一个表中有一个tinyint类型的字段,值为0或者1,如果取出来的话,0会变成false,1会变成true. MySQL保存boolean值时用1代表TRUE,0代表FALSE.boolean在 ...

  8. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  9. [SHOI2013]发微博

    Description 刚开通的SH微博共有n个用户(1..n标号),在短短一个月的时间内,用户们活动频繁,共有m条按时间顺序的记录: ​ ! x 表示用户x发了一条微博: ​ + x y 表示用户x ...

  10. Sqoop-将Hive ORC表导出到MySQL

    Sqoop-将Hive ORC表导出到MySQL sqoop export --connect jdbc:mysql://localhost:3306/test --username root --p ...