class_docstr: Base class for Joint Probability Distribution
class_docstr_tok: ["Base","class","for","Joint","Probability","Distribution"]
docstr: Returns the marginal distribution over variables.
  
  Parameters
  ----------
  variables: string, list, tuple, set, dict
          Variable or list of variables over which marginal distribution needs
          to be calculated
  inplace: Boolean (default True)
          If False return a new instance of JointProbabilityDistribution
  
  Examples
  --------
  >>> import numpy as np
  >>> from pgmpy.factors.discrete import JointProbabilityDistribution
  >>> values = np.random.rand(12)
  >>> prob = JointProbabilityDistribution(['x1', 'x2', 'x3'], [2, 3, 2], values/np.sum(values))
  >>> prob.marginal_distribution(['x1', 'x2'])
  >>> print(prob)
  x1    x2      P(x1,x2)
  ----  ----  ----------
  x1_0  x2_0      0.1502
  x1_0  x2_1      0.1626
  x1_0  x2_2      0.1197
  x1_1  x2_0      0.2339
  x1_1  x2_1      0.1996
  x1_1  x2_2      0.1340
docstr_tok: ["Returns","the","marginal","distribution","over","variables",".","Parameters","--","--","--","--","--","variables",":","string",",","list",",","tuple",",","set",",","dict","Variable","or","list","of","variables","over","which","marginal","distribution","needs","to","be","calculated","inplace",":","Boolean","(","default","True",")","If","False","return","a","new","instance","of","JointProbabilityDistribution","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","pgmpy.factors.discrete","import","JointProbabilityDistribution",">",">",">","values","=","np.random.rand","(","12",")",">",">",">","prob","=","JointProbabilityDistribution","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","3",",","2","]",",","values\/np.sum","(","values",")",")",">",">",">","prob.marginal_distribution","(","[","'x1","'",",","'x2","'","]",")",">",">",">","print","(","prob",")","x1","x2","P","(","x1",",","x2",")","--","--","--","--","--","--","--","--","--","x1_0","x2_0","0.1502","x1_0","x2_1","0.1626","x1_0","x2_2","0.1197","x1_1","x2_0","0.2339","x1_1","x2_1","0.1996","x1_1","x2_2","0.1340"]
code: def marginal_distribution(self, variables, inplace=True):
      """
      Returns the marginal distribution over variables.
  
      Parameters
      ----------
      variables: string, list, tuple, set, dict
              Variable or list of variables over which marginal distribution needs
              to be calculated
      inplace: Boolean (default True)
              If False return a new instance of JointProbabilityDistribution
  
      Examples
      --------
      >>> import numpy as np
      >>> from pgmpy.factors.discrete import JointProbabilityDistribution
      >>> values = np.random.rand(12)
      >>> prob = JointProbabilityDistribution(['x1', 'x2', 'x3'], [2, 3, 2], values/np.sum(values))
      >>> prob.marginal_distribution(['x1', 'x2'])
      >>> print(prob)
      x1    x2      P(x1,x2)
      ----  ----  ----------
      x1_0  x2_0      0.1502
      x1_0  x2_1      0.1626
      x1_0  x2_2      0.1197
      x1_1  x2_0      0.2339
      x1_1  x2_1      0.1996
      x1_1  x2_2      0.1340
      """
      return self.marginalize(
          list(
              set(list(self.variables))
              - set(
                  variables
                  if isinstance(variables, (list, set, dict, tuple))
                  else [variables]
              )
          ),
          inplace=inplace,
      )
  
file_path: pgmpy/pgmpy/factors/discrete/JointProbabilityDistribution.py
imports: import itertools
  from functools import reduce
  from operator import mul
  import numpy
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.independencies import Independencies
label_desc: Use image node_id 4 for calling the JointProbabilityDistribution obj's underlying member method code with example usage: obj.marginal_distribution(variables, inplace) and returns: self