How to use the uncertainties.sources.utils.util.cummean function in uncertainties

To help you get started, we’ve selected a few uncertainties examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google-research / google-research / uncertainties / sources / postprocessing / metrics.py View on Github external
def brier_score(y, p_tab):
  """Compute the Brier score.

  Brier Score: see
  https://www.stat.washington.edu/raftery/Research/PDF/Gneiting2007jasa.pdf,
  page 363, Example 1

  Args:
    y: one-hot encoding of the true classes, size (?, num_classes)
    p_tab: numpy array, size (?, num_classes, num_samples)
           containing the output predicted probabilities
  Returns:
    bs: Brier score along the iteration, vector of size num_samples.
  """
  p_cummean = util.cummean(p_tab, axis=2)
  y_repeated = np.repeat(y[:, :, np.newaxis], p_tab.shape[2], axis=2)
  bs = np.mean(np.power(p_cummean - y_repeated, 2), axis=(0, 1))
  return bs
github google-research / google-research / uncertainties / sources / postprocessing / metrics.py View on Github external
def negloglikelihood(y, p_tab):
  """Compute the negative log-likelihood.

  Args:
    y: one-hot encoding of the true classes, size (?, num_classes)
    p_tab: numpy array, size (?, num_classes, num_samples)
           containing the output predicted probabilities
  Returns:
    neglog: negative log likelihood, along the iterations
            numpy vector of size num_samples
  """
  p_mean = util.cummean(p_tab[y.astype(np.bool), :], axis=1)
  neglog = - np.mean(np.log(p_mean), axis=0)
  return neglog
github google-research / google-research / uncertainties / sources / postprocessing / metrics.py View on Github external
def accuracy(y, p_tab):
  """Compute the accuracy.

  Args:
    y: one-hot encoding of the true classes, size (?, num_classes)
    p_tab: numpy array, size (?, num_classes, num_samples)
           containing the output predicted probabilities
  Returns:
    acc: accuracy along the iterations, numpy vector of size num_samples
  """
  class_pred = np.argmax(util.cummean(p_tab, axis=2), axis=1)
  argmax_y = np.argmax(y, axis=1)
  acc = np.apply_along_axis(lambda x: np.mean(x == argmax_y),
                            axis=0, arr=class_pred)
  return acc