class_docstr: Base class of *DiscreteFactor Sets*.
  
  A factor set provides a compact representation of  higher dimensional factor
  :math:`\phi_1\cdot\phi_2\cdots\phi_n`
  
  For example the factor set corresponding to factor :math:`\phi_1\cdot\phi_2` would be the union of the factors
  :math:`\phi_1` and :math:`\phi_2` i.e. factor set :math:`\vec\phi = \phi_1 \cup \phi_2`.
class_docstr_tok: ["Base","class","of","*","DiscreteFactor","Sets","*",".","A","factor","set","provides","a","compact","representation","of","higher","dimensional","factor",":","math",":","`","\\phi_1\\cdot\\phi_2\\cdots\\phi_n","`","For","example","the","factor","set","corresponding","to","factor",":","math",":","`","\\phi_1\\cdot\\phi_2","`","would","be","the","union","of","the","factors",":","math",":","`","\\phi_1","`","and",":","math",":","`","\\phi_2","`","i.e",".","factor","set",":","math",":","`","\\vec\\phi","=","\\phi_1","\\cup","\\phi_2","`","."]
docstr: Marginalizes the factors present in the factor sets with respect to the given variables.
  
  Parameters
  ----------
  variables: list, array-like
      List of the variables to be marginalized.
  
  inplace: boolean (Default value True)
      If inplace=True it will modify the factor set itself, would create a new factor set
  
  Returns
  -------
  If inplace = False, will return a new marginalized FactorSet object.
  
  Examples
  --------
  >>> from pgmpy.factors import FactorSet
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> phi1 = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
  >>> phi2 = DiscreteFactor(['x3', 'x4', 'x1'], [2, 2, 2], range(8))
  >>> factor_set1 = FactorSet(phi1, phi2)
  >>> factor_set1.marginalize('x1')
  >>> print(factor_set1)
  set([<DiscreteFactor representing phi(x2:3, x3:2) at 0x7f8e32b4cc10>,
       <DiscreteFactor representing phi(x3:2, x4:2) at 0x7f8e32b4cf90>])
docstr_tok: ["Marginalizes","the","factors","present","in","the","factor","sets","with","respect","to","the","given","variables",".","Parameters","--","--","--","--","--","variables",":","list",",","array-like","List","of","the","variables","to","be","marginalized",".","inplace",":","boolean","(","Default","value","True",")","If","inplace=True","it","will","modify","the","factor","set","itself",",","would","create","a","new","factor","set","Returns","--","--","--","-","If","inplace","=","False",",","will","return","a","new","marginalized","FactorSet","object",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors","import","FactorSet",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","phi1","=","DiscreteFactor","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","3",",","2","]",",","range","(","12",")",")",">",">",">","phi2","=","DiscreteFactor","(","[","'x3","'",",","'x4","'",",","'x1","'","]",",","[","2",",","2",",","2","]",",","range","(","8",")",")",">",">",">","factor_set1","=","FactorSet","(","phi1",",","phi2",")",">",">",">","factor_set1.marginalize","(","'x1","'",")",">",">",">","print","(","factor_set1",")","set","(","[","<","DiscreteFactor","representing","phi","(","x2:3",",","x3:2",")","at","0x7f8e32b4cc10",">",",","<","DiscreteFactor","representing","phi","(","x3:2",",","x4:2",")","at","0x7f8e32b4cf90",">","]",")"]
code: def marginalize(self, variables, inplace=True):
      """
      Marginalizes the factors present in the factor sets with respect to the given variables.
  
      Parameters
      ----------
      variables: list, array-like
          List of the variables to be marginalized.
  
      inplace: boolean (Default value True)
          If inplace=True it will modify the factor set itself, would create a new factor set
  
      Returns
      -------
      If inplace = False, will return a new marginalized FactorSet object.
  
      Examples
      --------
      >>> from pgmpy.factors import FactorSet
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> phi1 = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
      >>> phi2 = DiscreteFactor(['x3', 'x4', 'x1'], [2, 2, 2], range(8))
      >>> factor_set1 = FactorSet(phi1, phi2)
      >>> factor_set1.marginalize('x1')
      >>> print(factor_set1)
      set([<DiscreteFactor representing phi(x2:3, x3:2) at 0x7f8e32b4cc10>,
           <DiscreteFactor representing phi(x3:2, x4:2) at 0x7f8e32b4cf90>])
      """
      if isinstance(variables, str):
          raise TypeError(
              "Expected list or array-like type got type str"
          )
  
      factor_set = self if inplace else self.copy()
  
      factors_to_be_marginalized = set(
          filter(
              lambda x: set(x.scope()).intersection(variables),
              factor_set.factors,
          )
      )
  
      for factor in factors_to_be_marginalized:
          variables_to_be_marginalized = list(
              set(factor.scope()).intersection(variables)
          )
          if inplace:
              factor.marginalize(
                  variables_to_be_marginalized, inplace=True
              )
          else:
              factor_set.remove_factors(factor)
              factor_set.add_factors(
                  factor.marginalize(
                      variables_to_be_marginalized, inplace=False
                  )
              )
  
      if not inplace:
          return factor_set
  
file_path: pgmpy/pgmpy/factors/FactorSet.py
imports: from functools import reduce
  from pgmpy.factors.base import BaseFactor
label_desc: Use image node_id 7 for calling the FactorSet obj's underlying member method code with example usage: obj.marginalize(variables, inplace) and returns: factor_set