2026a
# mse
均方误差
函数库: TyDeepLearning
# 语法
loss = mse(Y, targets)
# 说明
loss = mse(Y, targets) 计算预测值和目标值之间的均方差MSE(Mean Squared Error)。示例
计算输入
其中, n 为 batch size。
# 示例
计算均方误差损失
随机生成预测数据和真实数据。
using TyDeepLearning
using Random
set_backend(:mindspore)
inputsize = [6, 6]
batch = 1
channel = 1
Random.seed!(1234)
Y = rand(Float32, (batch, channel, inputsize[1], inputsize[2]))
target = ones(Float32, (batch, channel, inputsize[1], inputsize[2]))
计算均方误差损失并输出。
output = mse(Y, target)
print(output)
0.28759724
# 输入参数
Y - 预测值数组
输入的预测值。
数据类型: Float16 | Float32 | Float64 | Int64
targets - 目标值向量
目标值。目标的每个维度的大小必须与 Y 的相应维度的大小匹配。
数据类型: Float16 | Float32 | Float64 | Int64
# 输出参数
loss - MSE损失数组
MSE 损失,输出损失是一个数组,其基础数据类型与 shape 输入 Y 相同。
数据类型: Float16 | Float32 | Float64 | Int64
# 另请参阅
crossentropy | huber | Learning Phrase Representations using RNN Encoder–Decoder for Statistical Machine Translation (opens new window)