code: def gen_attack_score(output, target, targeted=False, buffer=1e-5):
      """
      Fitness used for GenAttack
      """
      n_class = output.shape[-1]
      y_onehot = F.one_hot(target, num_classes=n_class)
  
      pos_score = torch.log(
          (y_onehot[:, None, :] * output + buffer).sum(-1)
      )
      neg_score = torch.log(
          (1 - y_onehot)[:, None, :] * output + buffer
      ).sum(-1)
      score = pos_score - neg_score
  
      if not targeted:
          score = -score
  
      return score
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from typing import Optional
  from math import inf
  import torch
  import torch.nn.functional
  from advertorch.attacks.base import Attack
  from advertorch.attacks.base import LabelMixin
  from .utils import _check_param, _flatten, _make_projector
label_desc: Use image node_id 1 for calling a global function with example usage: gen_attack_score(output, target, targeted, buffer) and returns: score