我想开发一个自定义Keras损失函数,其中y_pred为2张量,此后我将其称为张量A和B。
A和B的形状是(batch_size,时间步长,矢量)
我的损失函数是abs(sum(diff(A,intersect(A,B)))-sum(diff(B,intersect(A,B))))
A = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3], [7.1, 7.2, 7.3]]
B = [[1.1, 1.2, 1.3],[5.1, 5.2, 5.3], [6.1, 6.2, 6.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3]]
C = intersect(A, B)
# set operation
# now C should be like [[1.1, 1.2, 1.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3]]
# because it's in A and B
D = diff(A, C)
# set operation A-C
# then D should be like [[2.1, 2.2, 2.3], [7.1, 7.2, 7.3]]]
sum()和abs()的工作方式类似于reduce_sum和普通abs函数
那么,如何计算这样的损失函数?