class_docstr: Attacks a model with word substiutitions using a genetic algorithm.
  
  Args:
      pop_size (int): The population size. Defaults to 20.
      max_iters (int): The maximum number of iterations to use. Defaults to 50.
      temp (float): Temperature for softmax function used to normalize probability dist when sampling parents.
          Higher temperature increases the sensitivity to lower probability candidates.
      give_up_if_no_improvement (bool): If True, stop the search early if no candidate that improves the score is found.
      post_crossover_check (bool): If True, check if child produced from crossover step passes the constraints.
      max_crossover_retries (int): Maximum number of crossover retries if resulting child fails to pass the constraints.
          Applied only when `post_crossover_check` is set to `True`.
          Setting it to 0 means we immediately take one of the parents at random as the child upon failure.
      max_replace_times_per_index (int):  The maximum times words at the same index can be replaced in improved genetic algorithm.
docstr: Initialize a population of size `pop_size` with `initial_result`
  Args:
      initial_result (GoalFunctionResult): Original text
      pop_size (int): size of population
  Returns:
      population as `list[PopulationMember]`
code: def _initialize_population(self, initial_result, pop_size):
      """
      Initialize a population of size `pop_size` with `initial_result`
      Args:
          initial_result (GoalFunctionResult): Original text
          pop_size (int): size of population
      Returns:
          population as `list[PopulationMember]`
      """
      words = initial_result.attacked_text.words
      # For IGA, `num_replacements_left` represents the number of times the word at each index can be modified
      num_replacements_left = np.array(
          [self.max_replace_times_per_index] * len(words)
      )
      population = []
  
      # IGA initializes the first population by replacing each word by its optimal synonym
      for idx in range(len(words)):
          pop_member = PopulationMember(
              initial_result.attacked_text,
              initial_result,
              attributes={
                  "num_replacements_left": np.copy(
                      num_replacements_left
                  )
              },
          )
          pop_member = self._perturb(
              pop_member, initial_result, index=idx
          )
          population.append(pop_member)
  
      return population[:pop_size]
  
file_path: TextAttack/textattack/search_methods/improved_genetic_algorithm.py
imports: import numpy
  from textattack.search_methods import GeneticAlgorithm, PopulationMember
label_desc: Use image node_id 5 for calling the ImprovedGeneticAlgorithm obj's underlying member method code with example usage: obj._initialize_population(initial_result, pop_size) and returns: population