(self, x, y)
| 398 | return all_norms |
| 399 | |
| 400 | def rel(self, x, y): |
| 401 | num_examples = x.size()[0] |
| 402 | |
| 403 | diff_norms = torch.norm(x.reshape(num_examples,-1) - y.reshape(num_examples,-1), self.p, 1) |
| 404 | y_norms = torch.norm(y.reshape(num_examples,-1), self.p, 1) |
| 405 | |
| 406 | if self.reduction: |
| 407 | if self.size_average: |
| 408 | return torch.mean(diff_norms/y_norms) |
| 409 | else: |
| 410 | return torch.sum(diff_norms/y_norms) |
| 411 | |
| 412 | return diff_norms/y_norms |
| 413 | |
| 414 | def __call__(self, x, y): |
| 415 | return self.rel(x, y) |