1.Rectified Linear函数的定义
2.Rectified Linear函数的导数
3.Rectified Linear函数的实现
Rectified linear主要是通过类RectifiedLinear来实现的,该类继承自AbstrcactActivation类,主要实现Activating接口和Derivating接口。
RectifiedLinear类的定义如下:
#ifndef RECTIFIEDLINEAR_H #define RECTIFIEDLINEAR_H #include "abstractactivationfunction.h" /** * @brief The RectifiedLinear class used to calculate the rectified linear * activation function. * * @author sheng * @date 2014-07-23 * @version 0.1 * * @history * <author> <date> <version> <description> * sheng 2014-07-23 0.1 build the class * */ class RectifiedLinear : public AbstractActivationFunction { public: RectifiedLinear(); cv::Mat Activating(const cv::Mat &InputMat); cv::Mat Derivating(const cv::Mat &InputMat); }; #endif // RECTIFIEDLINEAR_H
函数的定义如下:
#include "rectifiedlinear.h" /** * @brief The default constructor. * * @author sheng * @version 0.1 * @date 2014-07-23 * * @history * <author> <date> <version> <description> * sheng 2014-07-23 0.1 build the function */ RectifiedLinear::RectifiedLinear() { } /** * @brief Calculating the rectified linear of the inputmat. * @param InputMat The input mat * @return the result of rectifiedlinear(inputmat), whose size is the same of the * InputMat. * * * @author sheng * @version 0.1 * @date 2014-07-23 * * @history * <author> <date> <version> <description> * sheng 2014-07-23 0.1 build the function * */ cv::Mat RectifiedLinear::Activating(const cv::Mat &InputMat) { // convert to float mat cv::Mat FloatMat = ConvertToFloatMat(InputMat); // calculate the rectified linear cv::Mat Result; cv::threshold(FloatMat, Result, 0.0, 255, cv::THRESH_TOZERO); return Result; } /** * @brief Calculating the derivative of the rectifiedlinear. * @param InputMat The input mat * @return the result of the derivative of the rectifiedlinear, whose size is * the same of the InputMat. * * * @author sheng * @version 0.1 * @date 2014-07-23 * * @history * <author> <date> <version> <description> * sheng 2014-07-23 0.1 build the function * */ cv::Mat RectifiedLinear::Derivating(const cv::Mat &InputMat) { // convert to float mat cv::Mat FloatMat = ConvertToFloatMat(InputMat); // calculate which element of the mat is bigger or equal to zero. cv::Mat TmpResult = FloatMat >= 0.0; // calculate the derivate of the rectified linear cv::Mat Result = TmpResult & 1; return Result; }