一些函数图像



'''
Author: huajia
Date: 2021-11-22 14:57:01
LastEditors: huajia
LastEditTime: 2021-11-25 09:33:43
Description: 略略略
'''



import numpy as np
import math
import matplotlib.pyplot as plt



x = np.arange(0.01, 1, 0.01)
j = np.arange(-10, 10, 0.1)
y = []
y2 = []
y3 = []
y4 = []
x_1 = []
x_2 = []
x_3 = []
yy = 1
res = 0
for t in x:
    y_1 = yy*math.log2(round(t, 2))+(1-yy)*math.log2(1-round(t, 2))
    y_1 *= -1
    y_2 = math.pow((yy-t), 2)
    x_1.append(yy*(1-round(t, 2))+(1-yy)*(round(t, 2)))
    x_2.append(yy-t)
    y.append(y_1)
    y2.append(y_2)

for jj in j:
    y_3 = 1.0/(1+math.exp(-jj))
    y3.append(y_3)
    y_4 = (math.exp(jj)-math.exp(-jj))/(math.exp(jj)+math.exp(-jj))
    y4.append(y_4)

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(8, 8))
plt.subplot(2, 2, 1)
plt.xlabel("x")
plt.ylabel("y")
plt.plot(x, y, label="2为底的log交叉熵")
plt.plot(x, x_1, color='red', linewidth=1, linestyle='--')
plt.legend()
plt.subplot(2, 2, 2)
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(0, 7)
plt.plot(x, y2, label="均方差")
plt.plot(x, x_2, color='red', linewidth=1, linestyle='--')
plt.legend()
plt.subplot(2, 2, 3)
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(0, 1)
plt.plot(j, y3, label="sigmoid")
plt.plot([0,0], [0,1], color='red', linewidth=1, linestyle='--')
plt.plot([-10,10], [.5,.5], color='red', linewidth=1, linestyle='--')
plt.legend()
plt.subplot(2, 2, 4)
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(-1, 1)
plt.plot(j, y4, label="tanh")
plt.plot([0,0], [1,-1], color='red', linewidth=1, linestyle='--')
plt.plot([-10,10], [0,0], color='red', linewidth=1, linestyle='--')
plt.legend()
plt.show()