import numpy as np# MSE Lossdef mse(y, t):return 0.5*np.sum((y-t)**2)t=[0,1,1,0,0]y=[0,0.4,0.73,0.04,0.25]print(mse(y,t))# Cross Entropy Lossdef CELoss(y, t):# 防止传入 log 的输入为0delta = 1e - 7return -np.sum(t*np.log(y+delta))# mini batch版本def CELoss(y, t):if y.dim == 1:# 转为二维t = t.reshape(1, t.size)y = y.reshape(1, y.size)batch_size = y.shape[0]return -np.sum(t*np.log(y+1e-7))/batch_size
