pytorch(十二):激活函数与loss函数的梯度

一、代码引入

import torch
import matplotlib.pyplot as plt
import numpy as np
from torch.nn import functional as F

二、sigmoid

1、函数与梯度公式

 

 2、代码与图像

def sigmoid(x):
    return (1/(1 + np.exp(-x)))

x = np.linspace(-3,3,100)
y = [sigmoid(i) for i in x]
plt.plot(x,y,c='b',label = 'sigmoid')
plt.title('$Sigmoid$')
plt.legend()

 

 三、tanh

1、代码和图像

 

 四、ReLU

 

 五、MSE

1、公式

 

 2、代码

 

 

 六、softmax

 

posted @ 2020-11-23 19:02  jasonzhangxianrong  阅读(202)  评论(0编辑  收藏  举报