import torch criterion = torch.nn.MarginRankingLoss(margin = 0.3,reduction='mean') x1 = torch.Tensor([3,2]) x2 = torch.Tensor([1,4]) y = torch.Tensor([1,2]) loss = criterion(x1,x2,y) print(loss)
结果:
tensor(2.1500)
详解:
验证:
对于第1个点,x1=3, x2 = 1, y=1。 max(-y*(x1-x2), 0) = max(-1*(3-1)+0.3, 0) = max(-1.7, 0) = 0 对于第2个点,x1=2, x2 = 4, y=2。 max(-y*(x1-x2), 0) = max(-2*(2-4), 0) = max(4.3, 0) = 4.3 求平均:2.15
标签:Tensor,nn,max,torch,详解,MarginRankingLoss,x2,x1 From: https://www.cnblogs.com/lusiqi/p/17177566.html