当前位置:   article > 正文

latex学习笔记——tikz画图 激活函数图像_latex画函数图像

latex画函数图像
  • (1)latex画图需要加入宏包
  1. %画图
  2. \usepackage{pgfplots}
  3. \usepackage{tikz}
  • (2)带坐标轴代码「sigmold函数为示例」,可直接当图片/表格插入.tex文档中
  • \operatorname{sigmoid}(\mathbf{x})=\frac{1}{1+e^{-\mathbf{x}}}
  •  

  1. %sigmold
  2. \begin{tikzpicture}[global scale = 0.5] //[global scale = 0.5]为整体缩放
  3. \begin{axis}[ //坐标轴属性设置
  4. axis lines=middle,
  5. samples=200, //切分格大小
  6. % grid,
  7. thick,
  8. domain=-8:8, //函数范围
  9. legend pos=outer north east,
  10. smooth,
  11. ]
  12. \addplot+[no marks]{{1/(1+(e^(-1*(\x))))}}; //画函数[]中为属性设置,{}中为函数
  13. \end{axis}
  14. \end{tikzpicture}
  • (3)整体缩放「在(2)之前加上描述」
  1. \tikzset{global scale/.style={
  2. scale=#1,
  3. every node/.append style={scale=#1}
  4. }
  5. }
  • (4)sigmold函数生成图

  • (5)其他激活函数代码和对应图像

5.1 ReLu

\operatorname{ReLU}(\mathbf{x})=\max (\mathbf{x}, 0)

  1. %ReLu
  2. \begin{tikzpicture}[global scale = 0.5]
  3. \begin{axis}[
  4. axis lines=middle,
  5. samples=200,
  6. % grid,
  7. thick,
  8. domain=-8:8,
  9. legend pos=outer north east,
  10. smooth,
  11. ]
  12. \addplot+[no marks]{max(\x,0)};
  13. \end{axis}
  14. \end{tikzpicture}

5.2 ​​​​​​tanh

\tanh (\mathbf{x})=\frac{e^{\mathbf{x}}-e^{-\mathbf{x}}}{e^{\mathbf{x}}+e^{-\mathbf{x}}}

  1. %tanh
  2. \begin{tikzpicture}[global scale = 0.5]
  3. \begin{axis}[
  4. axis lines=middle,
  5. samples=200,
  6. % grid,
  7. thick,
  8. domain=-8:8,
  9. legend pos=outer north east,
  10. smooth,
  11. ]
  12. \addplot+[no marks]{((e^(1*(\x)))-(e^(-1*(\x))))/((e^(1*(\x)))+(e^(-1*(\x))))};
  13. \end{axis}
  14. \end{tikzpicture}

5.3 SELU

\operatorname{SELU}(\mathbf{x})=\lambda\left\{\begin{array}{ll} \mathbf{x}, & \text { if } \mathbf{x}>0 \\ \alpha e^{\mathbf{x}}-\alpha, & \text { if } \mathbf{x} \leq 0 \end{array}\right.

  1. %SELU
  2. \begin{tikzpicture}[global scale = 0.5]
  3. \begin{axis}[
  4. axis lines=middle,
  5. samples=200,
  6. % grid,
  7. thick,
  8. domain=-8:8,
  9. legend pos=outer north east,
  10. smooth,
  11. ]
  12. \addplot[domain=-8:0,blue,thick,] % 设置函数的定义域
  13. {1*(e^(1*(\x)))-1}; % 输入显式函数
  14. \addplot[domain=0:8,blue,thick,] % 设置函数的定义域
  15. {x}; % 输入显式函数
  16. \end{axis}
  17. \end{tikzpicture}

5.4 softmax

\operatorname{softmax}\left(\mathbf{x}_{i}\right)=\frac{e^{\mathbf{x}_{i}}}{\sum_{j=0}^{k} e^{\mathbf{x}_{k}}}

  1. %softmax
  2. \begin{tikzpicture}[global scale = 0.5]
  3. \begin{axis}[
  4. axis lines=middle,
  5. samples=200,
  6. % grid,
  7. thick,
  8. domain=-8:8,
  9. legend pos=outer north east,
  10. smooth,
  11. ]
  12. \addplot+[no marks]{((e^(0.1*(\x)))-(e^(-1*(\x))))/((e^(0.1*(\x)))+(e^(-1*(\x))))};
  13. \end{axis}
  14. \end{tikzpicture}

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/238135
推荐阅读
相关标签
  

闽ICP备14008679号