激活函数实现--2 Sigmoid函数实现
2014-07-18 16:28
232 查看
1.Sigmoid函数的定义
2.Sigmoid函数的导数
3.SIGMOID激活的实现过程
Sigmoid主要是通过类Sigmoid来实现的,该类继承自AbstrcactActivation类,主要实现Activating接口和Derivating接口。Sigmoid类的定义如下:
<span style="font-size:24px;">#ifndef SIGMOID_H #define SIGMOID_H #include "abstractactivationfunction.h" /** * @brief The Sigmoid class used to calculate the sigmoid 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 Sigmoid : public AbstractActivationFunction { public: Sigmoid(); cv::Mat Activating(const cv::Mat& InputMat); cv::Mat Derivating(const cv::Mat& InputMat); }; #endif // SIGMOID_H </span>
函数的实现如下:
<span style="font-size:24px;">#include "sigmoid.h" #include <iostream> /** * @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 * * */ Sigmoid::Sigmoid() { } /** * @brief Calculating the sigmoid of the inputmat. * @param InputMat The input mat * @return the result of sigmoid(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 Sigmoid::Activating(const cv::Mat& InputMat) { // convert the mat to be float cv::Mat FloatInput = ConvertToFloatMat(InputMat); // calculate the exp(-x) cv::Mat TmpExp; cv::exp(-FloatInput, TmpExp); // calculate the sigmoid cv::Mat ResultMat = 1.0 / (1.0 + TmpExp); return ResultMat; } /** * @brief Calculating the derivating of the sigmoid function. * @param InputMat The input mat. * @return The result of the derivative of the sigmoid function, whose size is * the same of the input mat. * * @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 Sigmoid::Derivating(const cv::Mat &InputMat) { // calculating the sigmoid cv::Mat TmpMat = Activating(InputMat); // calculating the derivate of sigmoid function cv::Mat ResultMat = TmpMat.mul(1.0 - TmpMat); return ResultMat; }</span>
相关文章推荐
- 激活函数之logistic sigmoid函数介绍及C++实现
- 深度学习笔记7:激活函数层的实现
- 用sigmoid函数作为神经元的激活函数时,最好使用交叉熵代价函数,以避免训练过程太慢
- 激活函数实现--3 Tanh函数实现
- 包含激活函数的多层神经元网络及matlab实现
- 常用的激活函数总结(Sigmoid函数、Tanh函数、ReLu函数、Softmax函数)
- 深度神经网络及TensorFlow实现1-激活函数(Activation Function)2
- 机器学习09--神经网络的激活函数(Activation Function)及python代码实现
- 神经网络之激活函数 dropout原理解读 BatchNormalization 代码实现
- 深度神经网络及TensorFlow实现1-激活函数(Activation Function)
- caffe中五种层的实现与参数配置(3)------激活函数层
- 激活函数之softmax介绍及C++实现
- 交叉熵代价函数——当我们用sigmoid函数作为神经元的激活函数时,最好使用交叉熵代价函数来替代方差代价函数,以避免训练过程太慢
- 激活函数实现--4 Rectified linear函数实现
- 深度学习中的激活函数SoftMax函数的FPGA设计与实现(二)(CORDIC)
- 深度学习中的激活函数SoftMax函数的FPGA设计与实现 (一)
- 用java实现DB2的自定义函数
- 利用一组宏定义实现类成员函数的回调
- CodeProject - 使用特性(attributes)和激活机制来实现工厂模式
- 如何实现参数个数可变的函数