【发布时间】:2016-11-16 13:01:46
【问题描述】:
我有例如100 个样本(100 个输出)。我想为每个样本编写带有“权重”的自定义损失函数:
(target[j] - prediction[j])**2 + f(j),
其中 f 是自定义数值函数(例如 j**2)。我怎样才能做到这一点
现在我只能创建“通用”损失函数(没有“权重”):
def customloss(target,prediction):
return (target - prediction)**2
问题是我无法获取索引 (j)。
【问题讨论】:
-
为什么不添加一个额外的参数
weight?每个样本的权重向量。 -
问题是 AFAIK 权重只能乘以结果,所以我会得到这样的结果: (target[j] - prediction[j])**2 * f(j) 我想添加“权重”而不是乘以它们