def _compute_new_divergence_2(compound_counts_1,
                              compound_counts_2,
                              compounds_to_move,
                              original_divergence,
                              coef=0.1):
  """Returns the updated compound divergence if compounds are moved.

  This function calculates the new compound divergence if the specified
  compounds are moved from compound_counts_2 to compound_counts_1.

  Args:
    compound_counts_1: Compound counter for examples_1.
    compound_counts_2: Compound counter for examples_2.
    compounds_to_move: The set of compounds to move from examples_2 to
      examples_1.
    original_divergence: The original compound divergence.
    coef: The coefficient used in _compute_divergence.
  """
  sum_1 = sum(compound_counts_1.values())
  sum_2 = sum(compound_counts_2.values())
  original_denominator = sum_1**coef * sum_2**(1.0 - coef)

  original_similarity = 1.0 - original_divergence
  numerator = original_denominator * original_similarity
  # For each compound moved, we update the numerator of the similarity
  # expression, which is a sum over all compounds.
  for compound in compounds_to_move:
    count_1 = compound_counts_1[compound]
    count_2 = compound_counts_2[compound]

    original_numerator_for_compound = count_1**coef * count_2**(1.0 - coef)
    new_numerator_for_compound = ((count_1 + 1)**coef *
                                  (count_2 - 1)**(1.0 - coef))

    numerator += new_numerator_for_compound - original_numerator_for_compound

  new_denominator = ((sum_1 + len(compounds_to_move))**coef *
                     (sum_2 - len(compounds_to_move))**(1.0 - coef))
  new_similarity = numerator / new_denominator
  return 1.0 - new_similarity
Returns the updated compound divergence if compounds are moved.

  This function calculates the new compound divergence if the specified
  compounds are moved from compound_counts_2 to compound_counts_1.

  Args:
    compound_counts_1: Compound counter for examples_1.
    compound_counts_2: Compound counter for examples_2.
    compounds_to_move: The set of compounds to move from examples_2 to
      examples_1.
    original_divergence: The original compound divergence.
    coef: The coefficient used in _compute_divergence.
  
language/compgen/nqg/tasks/mcd_utils.py