Example #1
0
 def _precision(self):
     prec = torch.diag(self.cm) / self.cm.sum(dim=0)
     prec[prec != prec] = 0  # removing potential "nan"s
     if self.average is None: return prec
     else:
         weights = self._weights(avg=self.average)
         return (prec * weights).sum()
Example #2
0
 def _recall(self):
     rec = torch.diag(self.cm) / self.cm.sum(dim=1)
     rec[rec != rec] = 0  # removing potential "nan"s
     if self.average is None: return rec
     else:
         if self.average == "micro": weights = self._weights(avg="weighted")
         else: weights = self._weights(avg=self.average)
         return (rec * weights).sum()
Example #3
0
 def _get_style_vals(self, tensor):
     mean, cov = self._calc_2_moments(tensor)
     if mean is None:
         return None, None, None
     eigvals, eigvects = torch.symeig(cov, eigenvectors=True)
     eigroot_mat = torch.diag(torch.sqrt(eigvals.clamp(min=0)))
     root_cov = torch.mm(torch.mm(eigvects, eigroot_mat), eigvects.t())
     tr_cov = eigvals.clamp(min=0).sum()
     return mean, tr_cov, root_cov