code: def _adjusted_weights(weights):
      """
      Adjusts the weights such that it sums to 1. When the total weights is less
      than or greater than 1 by 1e-3, add/substracts the difference from the last
      element of weights. If the difference is greater than 1e-3, throws an error.
  
      Parameters
      ----------
      weights: 1-D numpy array
          The array for which to do the adjustment.
  
      Example
      -------
      >>> a = np.array([0.1111111] * 9)
      >>> _adjusted_weights(a)
      array([0.1111111, 0.1111111, 0.1111111, 0.1111111, 0.1111111, 0.1111111,
             0.1111111, 0.1111111, 0.1111112])
      """
      error = 1 - weights.sum()
      if abs(error) > 1e-3:
          raise ValueError("The probability values do not sum to 1.")
      elif error != 0:
          logger.warning(
              f"Probability values don't exactly sum to 1. Differ by: {error}. Adjusting values."
          )
          weights[compat_fns.argmax(weights)] += error
  
      return weights
  
file_path: pgmpy/pgmpy/utils/mathext.py
imports: from collections import namedtuple
  from itertools import chain, combinations
  import numpy
  from pgmpy import config
  from pgmpy.global_vars import logger
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 2 for calling a global function with example usage: _adjusted_weights(weights) and returns: weights