class_docstr: Base class for Joint Probability Distribution
class_docstr_tok: ["Base","class","for","Joint","Probability","Distribution"]
docstr: Initialize a Joint Probability Distribution class.
  
  Defined above, we have the following mapping from variable
  assignments to the index of the row vector in the value field:
  
  +-----+-----+-----+-------------------------+
  |  x1 |  x2 |  x3 |    P(x1, x2, x2)        |
  +-----+-----+-----+-------------------------+
  | x1_0| x2_0| x3_0|    P(x1_0, x2_0, x3_0)  |
  +-----+-----+-----+-------------------------+
  | x1_1| x2_0| x3_0|    P(x1_1, x2_0, x3_0)  |
  +-----+-----+-----+-------------------------+
  | x1_0| x2_1| x3_0|    P(x1_0, x2_1, x3_0)  |
  +-----+-----+-----+-------------------------+
  | x1_1| x2_1| x3_0|    P(x1_1, x2_1, x3_0)  |
  +-----+-----+-----+-------------------------+
  | x1_0| x2_0| x3_1|    P(x1_0, x2_0, x3_1)  |
  +-----+-----+-----+-------------------------+
  | x1_1| x2_0| x3_1|    P(x1_1, x2_0, x3_1)  |
  +-----+-----+-----+-------------------------+
  | x1_0| x2_1| x3_1|    P(x1_0, x2_1, x3_1)  |
  +-----+-----+-----+-------------------------+
  | x1_1| x2_1| x3_1|    P(x1_1, x2_1, x3_1)  |
  +-----+-----+-----+-------------------------+
  
  Parameters
  ----------
  variables: list
      List of scope of Joint Probability Distribution.
  cardinality: list, array_like
      List of cardinality of each variable
  value: list, array_like
      List or array of values of factor.
      A Joint Probability Distribution's values are stored in a row
      vector in the value using an ordering such that the left-most
      variables as defined in the variable field cycle through their
      values the fastest.
  
  Examples
  --------
  >>> import numpy as np
  >>> from pgmpy.factors.discrete import JointProbabilityDistribution
  >>> prob = JointProbabilityDistribution(['x1', 'x2', 'x3'], [2, 2, 2], np.ones(8)/8)
  >>> print(prob)
  x1    x2    x3      P(x1,x2,x3)
  ----  ----  ----  -------------
  x1_0  x2_0  x3_0         0.1250
  x1_0  x2_0  x3_1         0.1250
  x1_0  x2_1  x3_0         0.1250
  x1_0  x2_1  x3_1         0.1250
  x1_1  x2_0  x3_0         0.1250
  x1_1  x2_0  x3_1         0.1250
  x1_1  x2_1  x3_0         0.1250
  x1_1  x2_1  x3_1         0.1250
docstr_tok: ["Initialize","a","Joint","Probability","Distribution","class",".","Defined","above",",","we","have","the","following","mapping","from","variable","assignments","to","the","index","of","the","row","vector","in","the","value","field",":","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1","|","x2","|","x3","|","P","(","x1",",","x2",",","x2",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_0|","P","(","x1_0",",","x2_0",",","x3_0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_0|","P","(","x1_1",",","x2_0",",","x3_0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_0|","P","(","x1_0",",","x2_1",",","x3_0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_0|","P","(","x1_1",",","x2_1",",","x3_0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_1|","P","(","x1_0",",","x2_0",",","x3_1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_1|","P","(","x1_1",",","x2_0",",","x3_1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_1|","P","(","x1_0",",","x2_1",",","x3_1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_1|","P","(","x1_1",",","x2_1",",","x3_1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","Parameters","--","--","--","--","--","variables",":","list","List","of","scope","of","Joint","Probability","Distribution",".","cardinality",":","list",",","array_like","List","of","cardinality","of","each","variable","value",":","list",",","array_like","List","or","array","of","values","of","factor",".","A","Joint","Probability","Distribution","'s","values","are","stored","in","a","row","vector","in","the","value","using","an","ordering","such","that","the","left-most","variables","as","defined","in","the","variable","field","cycle","through","their","values","the","fastest",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","pgmpy.factors.discrete","import","JointProbabilityDistribution",">",">",">","prob","=","JointProbabilityDistribution","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","2",",","2","]",",","np.ones","(","8",")","\/8",")",">",">",">","print","(","prob",")","x1","x2","x3","P","(","x1",",","x2",",","x3",")","--","--","--","--","--","--","--","--","--","--","--","--","-","x1_0","x2_0","x3_0","0.1250","x1_0","x2_0","x3_1","0.1250","x1_0","x2_1","x3_0","0.1250","x1_0","x2_1","x3_1","0.1250","x1_1","x2_0","x3_0","0.1250","x1_1","x2_0","x3_1","0.1250","x1_1","x2_1","x3_0","0.1250","x1_1","x2_1","x3_1","0.1250"]
code: def __init__(self, variables, cardinality, values):
      """
      Initialize a Joint Probability Distribution class.
  
      Defined above, we have the following mapping from variable
      assignments to the index of the row vector in the value field:
  
      +-----+-----+-----+-------------------------+
      |  x1 |  x2 |  x3 |    P(x1, x2, x2)        |
      +-----+-----+-----+-------------------------+
      | x1_0| x2_0| x3_0|    P(x1_0, x2_0, x3_0)  |
      +-----+-----+-----+-------------------------+
      | x1_1| x2_0| x3_0|    P(x1_1, x2_0, x3_0)  |
      +-----+-----+-----+-------------------------+
      | x1_0| x2_1| x3_0|    P(x1_0, x2_1, x3_0)  |
      +-----+-----+-----+-------------------------+
      | x1_1| x2_1| x3_0|    P(x1_1, x2_1, x3_0)  |
      +-----+-----+-----+-------------------------+
      | x1_0| x2_0| x3_1|    P(x1_0, x2_0, x3_1)  |
      +-----+-----+-----+-------------------------+
      | x1_1| x2_0| x3_1|    P(x1_1, x2_0, x3_1)  |
      +-----+-----+-----+-------------------------+
      | x1_0| x2_1| x3_1|    P(x1_0, x2_1, x3_1)  |
      +-----+-----+-----+-------------------------+
      | x1_1| x2_1| x3_1|    P(x1_1, x2_1, x3_1)  |
      +-----+-----+-----+-------------------------+
  
      Parameters
      ----------
      variables: list
          List of scope of Joint Probability Distribution.
      cardinality: list, array_like
          List of cardinality of each variable
      value: list, array_like
          List or array of values of factor.
          A Joint Probability Distribution's values are stored in a row
          vector in the value using an ordering such that the left-most
          variables as defined in the variable field cycle through their
          values the fastest.
  
      Examples
      --------
      >>> import numpy as np
      >>> from pgmpy.factors.discrete import JointProbabilityDistribution
      >>> prob = JointProbabilityDistribution(['x1', 'x2', 'x3'], [2, 2, 2], np.ones(8)/8)
      >>> print(prob)
      x1    x2    x3      P(x1,x2,x3)
      ----  ----  ----  -------------
      x1_0  x2_0  x3_0         0.1250
      x1_0  x2_0  x3_1         0.1250
      x1_0  x2_1  x3_0         0.1250
      x1_0  x2_1  x3_1         0.1250
      x1_1  x2_0  x3_0         0.1250
      x1_1  x2_0  x3_1         0.1250
      x1_1  x2_1  x3_0         0.1250
      x1_1  x2_1  x3_1         0.1250
      """
      if np.isclose(np.sum(values), 1):
          super(JointProbabilityDistribution, self).__init__(
              variables, cardinality, values
          )
      else:
          raise ValueError("The probability values doesn't sum to 1.")
  
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 1 to create a new JointProbabilityDistribution object from inherited base classes: DiscreteFactor with example: obj = JointProbabilityDistribution(variables, cardinality, values)