easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_pai.py [588:649]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    weights_tiled = array_ops.tile(
        array_ops.reshape(weights, [1, -1]), [num_thresholds, 1])
    thresh_tiled.get_shape().assert_is_compatible_with(
        weights_tiled.get_shape())
  else:
    weights_tiled = None

  values = {}
  update_ops = {}

  if 'tp' in includes:
    true_p = metric_variable([num_thresholds],
                             dtypes.float32,
                             name='true_positives')
    is_true_positive = math_ops.cast(
        math_ops.logical_and(label_is_pos, pred_is_pos), dtypes.float32)
    if weights_tiled is not None:
      is_true_positive *= weights_tiled
    update_ops['tp'] = state_ops.assign_add(
        true_p, math_ops.reduce_sum(is_true_positive, 1), use_locking=True)
    values['tp'] = true_p

  if 'fn' in includes:
    false_n = metric_variable([num_thresholds],
                              dtypes.float32,
                              name='false_negatives')
    is_false_negative = math_ops.cast(
        math_ops.logical_and(label_is_pos, pred_is_neg), dtypes.float32)
    if weights_tiled is not None:
      is_false_negative *= weights_tiled
    update_ops['fn'] = state_ops.assign_add(
        false_n, math_ops.reduce_sum(is_false_negative, 1), use_locking=True)
    values['fn'] = false_n

  if 'tn' in includes:
    true_n = metric_variable([num_thresholds],
                             dtypes.float32,
                             name='true_negatives')
    is_true_negative = math_ops.cast(
        math_ops.logical_and(label_is_neg, pred_is_neg), dtypes.float32)
    if weights_tiled is not None:
      is_true_negative *= weights_tiled
    update_ops['tn'] = state_ops.assign_add(
        true_n, math_ops.reduce_sum(is_true_negative, 1), use_locking=True)
    values['tn'] = true_n

  if 'fp' in includes:
    false_p = metric_variable([num_thresholds],
                              dtypes.float32,
                              name='false_positives')
    is_false_positive = math_ops.cast(
        math_ops.logical_and(label_is_neg, pred_is_pos), dtypes.float32)
    if weights_tiled is not None:
      is_false_positive *= weights_tiled
    update_ops['fp'] = state_ops.assign_add(
        false_p, math_ops.reduce_sum(is_false_positive, 1), use_locking=True)
    values['fp'] = false_p

  return values, update_ops


def _aggregate_variable(v, collections):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_tf.py [570:631]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    weights_tiled = array_ops.tile(
        array_ops.reshape(weights, [1, -1]), [num_thresholds, 1])
    thresh_tiled.get_shape().assert_is_compatible_with(
        weights_tiled.get_shape())
  else:
    weights_tiled = None

  values = {}
  update_ops = {}

  if 'tp' in includes:
    true_p = metric_variable([num_thresholds],
                             dtypes.float32,
                             name='true_positives')
    is_true_positive = math_ops.cast(
        math_ops.logical_and(label_is_pos, pred_is_pos), dtypes.float32)
    if weights_tiled is not None:
      is_true_positive *= weights_tiled
    update_ops['tp'] = state_ops.assign_add(
        true_p, math_ops.reduce_sum(is_true_positive, 1), use_locking=True)
    values['tp'] = true_p

  if 'fn' in includes:
    false_n = metric_variable([num_thresholds],
                              dtypes.float32,
                              name='false_negatives')
    is_false_negative = math_ops.cast(
        math_ops.logical_and(label_is_pos, pred_is_neg), dtypes.float32)
    if weights_tiled is not None:
      is_false_negative *= weights_tiled
    update_ops['fn'] = state_ops.assign_add(
        false_n, math_ops.reduce_sum(is_false_negative, 1), use_locking=True)
    values['fn'] = false_n

  if 'tn' in includes:
    true_n = metric_variable([num_thresholds],
                             dtypes.float32,
                             name='true_negatives')
    is_true_negative = math_ops.cast(
        math_ops.logical_and(label_is_neg, pred_is_neg), dtypes.float32)
    if weights_tiled is not None:
      is_true_negative *= weights_tiled
    update_ops['tn'] = state_ops.assign_add(
        true_n, math_ops.reduce_sum(is_true_negative, 1), use_locking=True)
    values['tn'] = true_n

  if 'fp' in includes:
    false_p = metric_variable([num_thresholds],
                              dtypes.float32,
                              name='false_positives')
    is_false_positive = math_ops.cast(
        math_ops.logical_and(label_is_neg, pred_is_pos), dtypes.float32)
    if weights_tiled is not None:
      is_false_positive *= weights_tiled
    update_ops['fp'] = state_ops.assign_add(
        false_p, math_ops.reduce_sum(is_false_positive, 1), use_locking=True)
    values['fp'] = false_p

  return values, update_ops


def _aggregate_variable(v, collections):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



