Returns the model's average precision for each class

        Return:
            ap (FloatTensor): 1xK tensor, with avg precision for each class k
760437
def value(self):
        

        if self.scores.numel() == 0:
            return 0
        ap = torch.zeros(self.scores.size(1))
        if hasattr(torch, "arange"):
            rg = torch.arange(1, self.scores.size(0) + 1).float()
        else:
            rg = torch.range(1, self.scores.size(0)).float()
        if self.weights.numel() > 0:
            weight = self.weights.new(self.weights.size())
            weighted_truth = self.weights.new(self.weights.size())

        # compute average precision for each class
        for k in range(self.scores.size(1)):
            # sort scores
            scores = self.scores[:, k]
            targets = self.targets[:, k]
            _, sortind = torch.sort(scores, 0, True)
            truth = targets[sortind]
            if self.weights.numel() > 0:
                weight = self.weights[sortind]
                weighted_truth = truth.float() * weight
                rg = weight.cumsum(0)

            # compute true positive sums
            if self.weights.numel() > 0:
                tp = weighted_truth.cumsum(0)
            else:
                tp = truth.float().cumsum(0)

            # compute precision curve
            precision = tp.div(rg)

            # compute average precision
            ap[k] = precision[truth.byte()].sum() / max(float(truth.sum()), 1)
        return ap
651968
def get_global_gradient_norm(self) -> float:
        
        # average norm across executors:
        exec_norms = [global_norm([arr for arr in exe.grad_arrays if arr is not None]) for exe in self.executors]
        norm_val = sum(exec_norms) / float(len(exec_norms))
        norm_val *= self.optimizer.rescale_grad
        return norm_val
337989
def results_class_wise_average_metrics(self):
        

        class_wise_results = self.results_class_wise_metrics()

        class_wise_eer = []
        class_wise_fmeasure = []
        class_wise_precision = []
        class_wise_recall = []

        for class_label in class_wise_results:
            if class_wise_results[class_label]['eer']['eer'] is not None:
                class_wise_eer.append(class_wise_results[class_label]['eer']['eer'])

            if class_wise_results[class_label]['f_measure']['f_measure'] is not None:
                class_wise_fmeasure.append(class_wise_results[class_label]['f_measure']['f_measure'])
                class_wise_precision.append(class_wise_results[class_label]['f_measure']['precision'])
                class_wise_recall.append(class_wise_results[class_label]['f_measure']['recall'])

        if class_wise_eer:
            eer = float(numpy.nanmean(class_wise_eer))

        else:
            eer = None

        if class_wise_fmeasure:
            f_measure = float(numpy.nanmean(class_wise_fmeasure))

        else:
            f_measure = None

        if class_wise_precision:
            precision = float(numpy.nanmean(class_wise_precision))

        else:
            precision = None

        if class_wise_recall:
            recall = float(numpy.nanmean(class_wise_recall))

        else:
            recall = None

        return {
            'eer': {
                'eer': eer
            },
            'f_measure': {
                'f_measure': f_measure,
                'precision': precision,
                'recall': recall,
            }
        }
586094
def avg(self, vars_list: List[str]) -> 'TensorFluent':
        '''
        '''
        operand = self
        if operand.dtype == tf.bool:
            operand = operand.cast(tf.float32)
        return self._aggregation_op(tf.reduce_mean, operand, vars_list)
1090697
def accuracy(self):
        
        sub_observed = np.array([self.observed.metadata[i] for i in self.observed.arr])
        return float((self.model_predictions() == sub_observed).sum()) / self.data_size
664184
def overall_accuracy_calc(TP, POP):
    
    try:
        overall_accuracy = sum(TP.values()) / POP
        return overall_accuracy
    except Exception:
        return "None"
345471
def class_error(self, input_data, targets, average=True,
                    cache=None, prediction=False):
        

        if cache is not None:
            activations = cache
        else:
            activations = \
              self.feed_forward(input_data, prediction=prediction)

        targets = targets.get().argmax(1)
        class_error = np.sum(activations.get().argmax(1) != targets)

        if average: class_error = float(class_error) / targets.shape[0]
        return class_error
656365
def _fmt_float(cls, x, **kw):
        
        n = kw.get('n')
        return '%.*f' % (n, cls._to_float(x))
434025
def _averageFromList(self, param):
        
        _result = 0.0
        _count = 0

        for _param in param.split(','):
            if _param != '' and float(_param) != 0.0:
                _result = _result + float(_param)
                _count  += 1

        if _count >= 1:
            _result = _result / _count
        return _result
1187674
def apool(self,
              k_height,
              k_width,
              d_height=2,
              d_width=2,
              mode="VALID",
              input_layer=None,
              num_channels_in=None):
        """"""
        return self._pool("apool", pooling_layers.average_pooling2d, k_height,
                          k_width, d_height, d_width, mode, input_layer,
                          num_channels_in)
786992
def accuracy(input:Tensor, targs:Tensor)->Rank0Tensor:
    ""
    n = targs.shape[0]
    input = input.argmax(dim=-1).view(n,-1)
    targs = targs.view(n,-1)
    return (input==targs).float().mean()
784937
def adaptive_avgmax_pool2d(x, pool_type='avg', padding=0, count_include_pad=False):
    
    if pool_type == 'avgmaxc':
        x = torch.cat([
            F.avg_pool2d(
                x, kernel_size=(x.size(2), x.size(3)), padding=padding, count_include_pad=count_include_pad),
            F.max_pool2d(x, kernel_size=(x.size(2), x.size(3)), padding=padding)
        ], dim=1)
    elif pool_type == 'avgmax':
        x_avg = F.avg_pool2d(
                x, kernel_size=(x.size(2), x.size(3)), padding=padding, count_include_pad=count_include_pad)
        x_max = F.max_pool2d(x, kernel_size=(x.size(2), x.size(3)), padding=padding)
        x = 0.5 * (x_avg + x_max)
    elif pool_type == 'max':
        x = F.max_pool2d(x, kernel_size=(x.size(2), x.size(3)), padding=padding)
    else:
        if pool_type != 'avg':
            print('Invalid pool type %s specified. Defaulting to average pooling.' % pool_type)
        x = F.avg_pool2d(
            x, kernel_size=(x.size(2), x.size(3)), padding=padding, count_include_pad=count_include_pad)
    return x
166322
def compute_avg_adj_deg(G):
    
    """
    return np.sum(np.dot(G.A, G.A), axis=1) / (np.sum(G.A, axis=1) + 1.)
489804
def top_k_accuracy(input:Tensor, targs:Tensor, k:int=5)->Rank0Tensor:
    ""
    input = input.topk(k=k, dim=-1)[1]
    targs = targs.unsqueeze(dim=-1).expand_as(input)
    return (input == targs).max(dim=-1)[0].float().mean()
599010
def abs(cls, x: 'TensorFluent') -> 'TensorFluent':
        '''
        '''
        return cls._unary_op(x, tf.abs, tf.float32)
1061697
def get_cv_accuracy(res):
    
    ac_list = [(accuracy["train_acc_final"],
                accuracy["test_acc_final"]
                )
               for accuracy, weights in res]
    ac = np.array(ac_list)

    perf = {
        "mean_train_acc": np.mean(ac[:, 0]),
        "std_train_acc": np.std(ac[:, 0]),
        "mean_test_acc": np.mean(ac[:, 1]),
        "std_test_acc": np.std(ac[:, 1]),

    }
    return perf
754015
public double precision() {
    if(!isBinary())throw new UnsupportedOperationException("precision is only implemented for 2 class problems.");
    double tp = _arr[1][1];
    double fp = _arr[0][1];
    return tp / (tp + fp);
  }