docstr: Reduces the factor to the context of the given variable values.
  
  Parameters
  ----------
  values: list, array-like
      A list of tuples of the form (variable_name, variable_value).
  
  inplace: boolean
      If inplace=True it will modify the factor itself, else would return
      a new CustomDistribution object.
  
  Returns
  -------
  CustomDistribution or None:
              if inplace=True (default) returns None
              if inplace=False returns a new CustomDistribution instance.
  
  Examples
  --------
  >>> import numpy as np
  >>> from scipy.special import beta
  >>> from pgmpy.factors.distributions import CustomDistribution
  >>> def custom_pdf(x, y, z):
  ...     return z*(np.power(x, 1) * np.power(y, 2)) / beta(x, y)
  >>> custom_dist = CustomDistribution(['x', 'y', 'z'], custom_pdf)
  >>> custom_dist.variables
  ['x', 'y', 'z']
  >>> custom_dist.assignment(1, 2, 3)
  24.0
  
  >>> custom_dist.reduce([('y', 2)])
  >>> custom_dist.variables
  ['x', 'z']
  >>> custom_dist.assignment(1, 3)
  24.0
docstr_tok: ["Reduces","the","factor","to","the","context","of","the","given","variable","values",".","Parameters","--","--","--","--","--","values",":","list",",","array-like","A","list","of","tuples","of","the","form","(","variable_name",",","variable_value",")",".","inplace",":","boolean","If","inplace=True","it","will","modify","the","factor","itself",",","else","would","return","a","new","CustomDistribution","object",".","Returns","--","--","--","-","CustomDistribution","or","None",":","if","inplace=True","(","default",")","returns","None","if","inplace=False","returns","a","new","CustomDistribution","instance",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","scipy.special","import","beta",">",">",">","from","pgmpy.factors.distributions","import","CustomDistribution",">",">",">","def","custom_pdf","(","x",",","y",",","z",")",":","...","return","z","*","(","np.power","(","x",",","1",")","*","np.power","(","y",",","2",")",")","\/","beta","(","x",",","y",")",">",">",">","custom_dist","=","CustomDistribution","(","[","'","x","'",",","'","y","'",",","'","z","'","]",",","custom_pdf",")",">",">",">","custom_dist.variables","[","'","x","'",",","'","y","'",",","'","z","'","]",">",">",">","custom_dist.assignment","(","1",",","2",",","3",")","24.0",">",">",">","custom_dist.reduce","(","[","(","'","y","'",",","2",")","]",")",">",">",">","custom_dist.variables","[","'","x","'",",","'","z","'","]",">",">",">","custom_dist.assignment","(","1",",","3",")","24.0"]
code: def reduce(self, values, inplace=True):
      """
      Reduces the factor to the context of the given variable values.
  
      Parameters
      ----------
      values: list, array-like
          A list of tuples of the form (variable_name, variable_value).
  
      inplace: boolean
          If inplace=True it will modify the factor itself, else would return
          a new CustomDistribution object.
  
      Returns
      -------
      CustomDistribution or None:
                  if inplace=True (default) returns None
                  if inplace=False returns a new CustomDistribution instance.
  
      Examples
      --------
      >>> import numpy as np
      >>> from scipy.special import beta
      >>> from pgmpy.factors.distributions import CustomDistribution
      >>> def custom_pdf(x, y, z):
      ...     return z*(np.power(x, 1) * np.power(y, 2)) / beta(x, y)
      >>> custom_dist = CustomDistribution(['x', 'y', 'z'], custom_pdf)
      >>> custom_dist.variables
      ['x', 'y', 'z']
      >>> custom_dist.assignment(1, 2, 3)
      24.0
  
      >>> custom_dist.reduce([('y', 2)])
      >>> custom_dist.variables
      ['x', 'z']
      >>> custom_dist.assignment(1, 3)
      24.0
      """
      if not isinstance(values, (list, tuple, np.ndarray)):
          raise TypeError(
              f"variables: Expected type: iterable, got: {type(values)}"
          )
  
      for var, value in values:
          if var not in self.variables:
              raise ValueError(f"{var} not in scope.")
  
      phi = self if inplace else self.copy()
  
      var_to_remove = [var for var, value in values]
      var_to_keep = [
          var for var in self.variables if var not in var_to_remove
      ]
  
      reduced_var_index = [
          (self.variables.index(var), value) for var, value in values
      ]
      pdf = self.pdf
  
      def reduced_pdf(*args, **kwargs):
          reduced_args = list(args)
          reduced_kwargs = kwargs.copy()
  
          if reduced_args:
              for index, val in reduced_var_index:
                  reduced_args.insert(index, val)
          if reduced_kwargs:
              for variable, val in values:
                  reduced_kwargs[variable] = val
          if reduced_args and reduced_kwargs:
              reduced_args = [
                  arg
                  for arg in reduced_args
                  if arg not in reduced_kwargs.values()
              ]
  
          return pdf(*reduced_args, **reduced_kwargs)
  
      phi.variables = var_to_keep
      phi._pdf = reduced_pdf
  
      if not inplace:
          return phi
  
imports: import numpy
  from scipy import integrate
  from pgmpy.factors.distributions import BaseDistribution
label_desc: Use image node_id 9 for calling the CustomDistribution obj's underlying member method code with example usage: obj.reduce(values, inplace) and returns: pdf, phi