日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

激活函数之logistic sigmoid函数介绍及C++实现

發布時間:2023/11/27 生活经验 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 激活函数之logistic sigmoid函数介绍及C++实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

logistic sigmoid函數:

logistic sigmoid函數通常用來產生Bernoulli分布中的參數?,因為它的范圍是(0,1),處在?的有效取值范圍內。logisitic sigmoid函數在變量取絕對值非常大的正值或負值時會出現飽和(saturate)現象,意味著函數會變得很平,并且對輸入的微小改變會變得不敏感。

logistic sigmoid函數在深度學習中經常用作激活函數。有時為了加快計算速度,也使用稱為fast sigmoid 函數,即:σ(x)=x/(1+|x|)

Logistic function:A logistic function or logistic curve is a common “S” shape(sigmoid curve), with equation:

where, e = the natural logarithm base(also known as Euler’s number); x0 = the x-value of the sigmoid’s midpoint; L = the curve’s maximum value; k = the steepness of the curve. For values of x in the range of real numbers from -∞ to +∞.

The standard logistic function is the logistic function with parameters (k = 1, x0= 0, L = 1) which yields:

The logistic function has the symmetry(對稱) property that: 1-f(x)=f(-x).

以上內容摘自:?《深度學習中文版》和?維基百科

以下是C++測試code:

#include "funset.hpp"
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include "common.hpp"// =============================== 計算 sigmoid函數 ==========================
template<typename _Tp>
int sigmoid_function(const _Tp* src, _Tp* dst, int length)
{for (int i = 0; i < length; ++i) {dst[i] = (_Tp)(1. / (1. + exp(-src[i])));}return 0;
}template<typename _Tp>
int sigmoid_function_fast(const _Tp* src, _Tp* dst, int length)
{for (int i = 0; i < length; ++i) {dst[i] = (_Tp)(src[i] / (1. + fabs(src[i])));}return 0;
}int test_sigmoid_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> dst1(length), dst2(length);fprintf(stderr, "source vector: \n");fbc::print_matrix(src);fprintf(stderr, "calculate sigmoid function:\n");fprintf(stderr, "type: sigmoid functioin, result: \n");fbc::sigmoid_function(src.data(), dst1.data(), length);fbc::print_matrix(dst1);fprintf(stderr, "type: fast sigmoid function, result: \n");fbc::sigmoid_function_fast(src.data(), dst2.data(), length);fbc::print_matrix(dst2);return 0;
}

GitHub: https://github.com/fengbingchun/NN_Test

總結

以上是生活随笔為你收集整理的激活函数之logistic sigmoid函数介绍及C++实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。