激活函数实现--3 Tanh函数实现
1.TANH函数的定义
2. TANH函数的导数
3.TANH函数的实现
Tanh主要是通过类Tanh来实现的,该类继承自AbstrcactActivation类,主要实现Activating接口和Derivating接口。
Tanh类的定义如下:
<span style="font-size:24px;">#ifndef TANH_H
#define TANH_H#include "abstractactivationfunction.h"/**
* @brief The tanh class used to calculate the tanh activation function.
*
* @author sheng
* @date 2014-07-18
* @version 0.1
*
* @history
* <author> <date> <version> <description>
* sheng 2014-07-18 0.1 build the class
*
*/
class Tanh : public AbstractActivationFunction
{public:Tanh();cv::Mat Activating(const cv::Mat &InputMat);cv::Mat Derivating(const cv::Mat &InputMat);
};#endif // TANH_H
</span>
函数的定义如下:
<span style="font-size:24px;">#include "tanh.h"/**
* @brief The default constructor.
*
* @author sheng
* @version 0.1
* @date 2014-07-18
*
* @history
* <author> <date> <version> <description>
* sheng 2014-07-18 0.1 build the function
*
*
*/
Tanh::Tanh()
{
}/**
* @brief Calculating the tanh of the inputmat.
* @param InputMat The input mat
* @return the result of tanh(inputmat), whose size is the same of the
* InputMat.
*
*
* @author sheng
* @version 0.1
* @date 2014-07-18
*
* @history
* <author> <date> <version> <description>
* sheng 2014-07-18 0.1 build the function
*
*
*
*/
cv::Mat Tanh::Activating(const cv::Mat &InputMat)
{// convert the inputmat to the float matcv::Mat Floatmat = ConvertToFloatMat(InputMat);// calculating the exp(x)cv::Mat EXP_X;cv::exp(Floatmat, EXP_X);// calculating the exp(-x)cv::Mat EXP_X_;cv::exp(-Floatmat, EXP_X_);// calculating the tanh(x)cv::Mat Result = (EXP_X - EXP_X_) / (EXP_X + EXP_X_);return Result;
}/**
* @brief Calculating the derivative of the tanh.
* @param InputMat The input mat
* @return the result of the derivative of the tanh, whose size is the same of
* the InputMat.
*
*
* @author sheng
* @version 0.1
* @date 2014-07-18
*
* @history
* <author> <date> <version> <description>
* sheng 2014-07-18 0.1 build the function
*
*
*
*/
cv::Mat Tanh::Derivating(const cv::Mat &InputMat)
{// convert the inputmat to float matcv::Mat FloatMat = ConvertToFloatMat(InputMat);// calculating the tanh(x)cv::Mat TanhX = Activating(FloatMat);// calculting the tanh(x) * tanh(x)cv::Mat SquareTanhX = TanhX.mul(TanhX);// calculating the derivative of the tanhcv::Mat Result = 1 - SquareTanhX;return Result;
}</span>
激活函数实现--3 Tanh函数实现相关推荐
- 机器学习入门(03)— 激活函数分类(阶跃函数和 sigmoid 函数的理论、实现、显示以及区别、非线性函数、ReLU 函数、tanh 函数)
各种激活函数介绍,请参考下面链接: https://en.wikipedia.org/wiki/Activation_function 1. 阶跃函数 1.1 理论 式(3.3)表示的激活函数以阈值为 ...
- 激活函数(4)tanh函数
tanh函数 双曲正切激活函数,函数解析式: tanh函数及其导数的几何图像如下图: tanh读作Hyperbolic Tangent,它解决了Sigmoid函数的不是zero-centered输出问 ...
- 人工神经网络之激活函数 -tanh函数
tanh函数 tanh(x)=e2x−1e2x+1tanh′(x)=1−tanh(x)2 证明 ∂tanh(x)∂x=(1−2e2x+1)′=2⋅2e2x(e2x+1)2=4e2x(e2x+1)2=( ...
- 神经网络常用的三大激活函数sigmoid函数、tanh函数、relu函数对比讲解
在我们学习神经网络的时候经常要用到激活函数,但是我们对于为什么要使用这一个,它们之间的区别和优缺点各是什么不太了解.下面,我们来详细说一说这三个激活函数. - sigmoid函数 sigmoid函数也 ...
- 【深度学习】——神经网络中常用的激活函数:sigmoid、Relu、Tanh函数
激活函数 实际中的很多事情并不能简单的用线性关系的组合来描述.在神经网络中,如果没有激活函数,那么就相当于很多线性分类器的组合,当我们要求解的关系中存在非线性关系时,无论多么复杂的网络都会产生欠拟 ...
- 神经网络激活函数sigmoid、tanh、Relu、LeakyRelu、Elu、PRelu、MaxOut的java实现
神经网络常用激活函数包括sigmoid.tanh.Relu.LeakyRelu.Elu.PRelu和MaxOut.对每一种函数采用java进行实现.前面四种激活函数是固定形式,后面三种激活函数部分参数 ...
- 激活函数(sigmoid、Tanh、ReLU、Leaky ReLU、ELU、Maxout)
sigmoid函数 公式: 图像: sigmoid可以将数据压缩到[0,1]范围内,可看作神经元的饱和放电率.在历史上,sigmoid函数非常有用,这是因为它对神经元的激活频率有很好的解释:从完全不激 ...
- 激活函数总结sigmoid,tanh,relu,Leaky ReLU,RRelu,ELU,PRelu,SELU,swish
本文总结深度学习的损失函数及其优缺点. 激活函数是深度学习模型的重要成分,目的是将线性输入转换为非线性.常见的激活函数有sigmoid,tanh,ReLU等 1.sigmoid Sigmoid 非线性 ...
- 深度学习网络各种激活函数 Sigmoid、Tanh、ReLU、Leaky_ReLU、SiLU、Mish
激活函数的目的就是为网络提供非线性化 梯度消失:梯度为0, 无法反向传播,导致参数得不到更新 梯度饱和:随着数据的变化,梯度没有明显变化 梯度爆炸:梯度越来越大,无法收敛 梯度消失问题: 1.反向传播 ...
最新文章
- 某程序媛哀叹:北京好几套房,家庭收入200多万,但孩子是渣娃,人生没意义了!...
- 【 MATLAB 】程序流程控制语句格式简记
- 074_html5音频
- 用C++写的 Levenshtein 算法实现
- 提取pfx证书公钥和私钥
- Centos7 安装 Elasticsearch7.10(不错可以试试)
- swoole+redis(websocket聊天室demo)
- 梯度下降和随机梯度下降_梯度下降和链链接系统
- mysql插入时间区间_mybatis插入数据时返回主键以及MySQL根据时间区间查询问题总结...
- virtual void addChild(Node * child, int localZOrder)中ZOreder参数设置
- 电子元件 —— 二极管
- [codility]Equi-leader
- 记录一次众测平台邀请码获取
- 小企业会计准则 ——主要账务处理和财务报表(1)
- ES选举:Elasticsearch中Master选举完全解读
- 2018-10-20-C#-从零开始写-SharpDx-应用-初始化dx修改颜色
- RunC漏洞导致容器逃逸(CVE-2021-30465)
- Iog4j2漏洞相关技术分析
- 基于Android的电子影院系统
- 本科论文答辩开题报告ppt模板