original_docstring: Perform mutation action to candidates.
  
          For example, randomly change 10% of original sample
  
          Args:
              candidate: List of candidate genes (encodings).
              rate: Percentage of mutation bits
  
          Examples:
              >>> # Genes that represent 3 parameters
              >>> gene1 = np.array([[0, 0, 1], [0, 1], [1, 0]])
              >>> new_gene = _mutation([gene1])
              >>> # new_gene could be the gene1 with the 3rd parameter changed
              >>> #   new_gene[0] = gene1[0]
              >>> #   new_gene[1] = gene1[1]
              >>> #   new_gene[2] = [0, 1] != gene1[2]
  
          Returns:
              New gene (encoding)
          
docstring: Perform mutation action to candidates.
  For example, randomly change 10% of original sample
docstring_tokens: Perform mutation action to candidates . For example randomly change 10% of original sample
code: def _mutation(candidate, rate=0.1):
          """Perform mutation action to candidates.
  
          For example, randomly change 10% of original sample
  
          Args:
              candidate: List of candidate genes (encodings).
              rate: Percentage of mutation bits
  
          Examples:
              >>> # Genes that represent 3 parameters
              >>> gene1 = np.array([[0, 0, 1], [0, 1], [1, 0]])
              >>> new_gene = _mutation([gene1])
              >>> # new_gene could be the gene1 with the 3rd parameter changed
              >>> #   new_gene[0] = gene1[0]
              >>> #   new_gene[1] = gene1[1]
              >>> #   new_gene[2] = [0, 1] != gene1[2]
  
          Returns:
              New gene (encoding)
          """
          sample_index = np.random.choice(len(candidate))
          sample = candidate[sample_index]
          idx_list = []
          for i in range(int(max(len(sample) * rate, 1))):
              idx = np.random.choice(len(sample))
              idx_list.append(idx)
  
              field = sample[idx]  # one-hot encoding
              field[np.argmax(field)] = 0
              bit = np.random.choice(field.shape[0])
              field[bit] = 1
  
          logger.info(LOGGING_PREFIX + "Perform mutation on %sth at index=%s",
                      sample_index, str(idx_list))
          return sample
code_tokens: def _mutation ( candidate , rate = 0.1 ) : sample_index = np . random . choice ( len ( candidate ) ) sample = candidate [ sample_index ] idx_list = [ ] for i in range ( int ( max ( len ( sample ) * rate , 1 ) ) ) : idx = np . random . choice ( len ( sample ) ) idx_list . append ( idx ) field = sample [ idx ] field [ np . argmax ( field ) ] = 0 bit = np . random . choice ( field . shape [ 0 ] ) field [ bit ] = 1 logger . info ( LOGGING_PREFIX + "Perform mutation on %sth at index=%s" , sample_index , str ( idx_list ) ) return sample
short_docstring: Perform mutation action to candidates.
short_docstring_tokens: Perform mutation action to candidates .
comment: """Perform mutation action to candidates.
  
          For example, randomly change 10% of original sample
  
          Args:
              candidate: List of candidate genes (encodings).
              rate: Percentage of mutation bits
  
          Examples:
              >>> # Genes that represent 3 parameters
              >>> gene1 = np.array([[0, 0, 1], [0, 1], [1, 0]])
              >>> new_gene = _mutation([gene1])
              >>> # new_gene could be the gene1 with the 3rd parameter changed
              >>> #   new_gene[0] = gene1[0]
              >>> #   new_gene[1] = gene1[1]
              >>> #   new_gene[2] = [0, 1] != gene1[2]
  
          Returns:
              New gene (encoding)
          """$SEP$# one-hot encoding