def compute(self): check_non_zero_sample_size(self._n) val = self._squared_error / self._n try: return val.item() except: return val
def compute(self): check_non_zero_sample_size(len(self._target)) target = torch.cat(self._target, dim=0) pred = torch.cat(self._pred, dim=0) # if pred.shape[1]!=1: # import pdb # pdb.set_trace() target_rank_idx = target.argsort(dim=0, descending=True) pred_rank_idx = pred.argsort(dim=0, descending=True) # TODO: find better way, very inefficient for col in range(target.shape[1]): for count, idx in enumerate(target_rank_idx[:, col]): target[idx, col] = count + 1 for count, idx in enumerate(pred_rank_idx[:, col]): pred[idx, col] = count + 1 # TODO: take care of tied ranks target_mean = target.mean(dim=0, keepdim=True) pred_mean = pred.mean(dim=0, keepdim=True) val1 = ((target - target_mean) * (pred - pred_mean)).sum(dim=0) val2 = torch.pow(target - target_mean, 2.0).sum(dim=0).sqrt() val3 = torch.pow(pred - pred_mean, 2.0).sum(dim=0).sqrt() val = val1 / (val2 * val3) try: return val.item() # scalar except: return val # tensor
def compute(self): check_non_zero_sample_size(self._n) val = self._num_correct / self._n try: return val.item() except: return val
def compute(self): check_non_zero_sample_size(self._n) val = self._logarithmic_error / self._n try: return val.item() except: return val
def compute(self): check_non_zero_sample_size(self._n) val = self._dot_xy / (self._norm_x.sqrt() * self._norm_y.sqrt()) try: return val.item() except: return val
def compute(self): check_non_zero_sample_size(len(self._target)) target = torch.cat(self._target, dim=0) pred = torch.cat(self._pred, dim=0) ss_res = torch.pow(target - pred, 2.0).sum(dim=0) ss_tot = torch.pow(target - target.mean(dim=0), 2.0).sum(dim=0) return 1 - ss_res / ss_tot
def compute(self): check_non_zero_sample_size(len(self._target)) target = torch.cat(self._target, dim=0) pred = torch.cat(self._pred, dim=0) val = 1 - (target - pred).var(dim=0) / target.var(dim=0) try: return val.item() except: return val
def compute(self): check_non_zero_sample_size(len(self._target)) target = torch.cat(self._target, dim=0) pred = torch.cat(self._pred, dim=0) target_mean = target.mean(dim=0, keepdim=True) pred_mean = pred.mean(dim=0, keepdim=True) val1 = ((target - target_mean) * (pred - pred_mean)).sum(dim=0) val2 = torch.pow(target - target_mean, 2.0).sum(dim=0).sqrt() val3 = torch.pow(pred - pred_mean, 2.0).sum(dim=0).sqrt() val = val1 / (val2 * val3) try: return val.item() # scalar except: return val # tensor