code: def selection(pop_t, fitness, tau):
      """
      Select individuals in the population according to their fitness.
      These individuals become parents, which produce children via crossover.
      """
      n_batch, nb_samples, n_dim = pop_t.shape
  
      probs = F.softmax(fitness / tau, dim=1)
      cum_probs = probs.cumsum(-1)
      # Edge case, u1 or u2 is greater than max(cum_probs)
      cum_probs[:, -1] = 1.0 + 1e-7
  
      # parents: instead of selecting one elite, select two, and generate
      # a new child to create a population around
      # do this multiple times, for each N
  
      # sample parent 1 from pop_t according to probs (multinomial)
      # sample parent 2 from pop_t according to probs (multinomial)
      u1, u2 = torch.rand(2, n_batch, nb_samples)
  
      # out of the original N samples, we draw another N samples
      # this requires us to compute the following broadcasted comparison
      p1ind = (
          -((cum_probs[:, :, None] > u1[:, None, :]).long()).sum(1)
          + nb_samples
      )
      p2ind = (
          -((cum_probs[:, :, None] > u2[:, None, :]).long()).sum(1)
          + nb_samples
      )
  
      parent1 = torch.gather(
          pop_t, dim=1, index=p1ind[:, :, None].expand(-1, -1, n_dim)
      )
  
      parent2 = torch.gather(
          pop_t, dim=1, index=p2ind[:, :, None].expand(-1, -1, n_dim)
      )
  
      fp1 = torch.gather(fitness, dim=1, index=p1ind)
      fp2 = torch.gather(fitness, dim=1, index=p2ind)
      crossover_prob = fp1 / (fp1 + fp2)
  
      return crossover(parent1, parent2, crossover_prob)
  
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 4 for calling a global function with example usage: selection(pop_t, fitness, tau) and returns: crossover