class_docstr: Defines the conditional probability distribution table (CPD table)
  
  Parameters
  ----------
  variable: int, string (any hashable python object)
      The variable whose CPD is defined.
  
  variable_card: integer
      Cardinality/no. of states of `variable`
  
  values: 2D array, 2D list or 2D tuple
      Values for the CPD table. Please refer the example for the
      exact format needed.
  
  evidence: array-like
      List of variables in evidences(if any) w.r.t. which CPD is defined.
  
  evidence_card: array-like
      cardinality/no. of states of variables in `evidence`(if any)
  
  Examples
  --------
  For a distribution of P(grade|diff, intel)
  
  +---------+-------------------------+------------------------+
  |diff:    |          easy           |         hard           |
  +---------+------+--------+---------+------+--------+--------+
  |aptitude:| low  | medium |  high   | low  | medium |  high  |
  +---------+------+--------+---------+------+--------+--------+
  |gradeA   | 0.1  | 0.1    |   0.1   |  0.1 |  0.1   |   0.1  |
  +---------+------+--------+---------+------+--------+--------+
  |gradeB   | 0.1  | 0.1    |   0.1   |  0.1 |  0.1   |   0.1  |
  +---------+------+--------+---------+------+--------+--------+
  |gradeC   | 0.8  | 0.8    |   0.8   |  0.8 |  0.8   |   0.8  |
  +---------+------+--------+---------+------+--------+--------+
  
  values should be
  [[0.1,0.1,0.1,0.1,0.1,0.1],
  [0.1,0.1,0.1,0.1,0.1,0.1],
  [0.8,0.8,0.8,0.8,0.8,0.8]]
  
  >>> cpd = TabularCPD('grade',3,[[0.1,0.1,0.1,0.1,0.1,0.1],
  ...                             [0.1,0.1,0.1,0.1,0.1,0.1],
  ...                             [0.8,0.8,0.8,0.8,0.8,0.8]],
  ...                             evidence=['diff', 'intel'], evidence_card=[2,3])
  >>> print(cpd)
  +---------+---------+---------+---------+---------+---------+---------+
  | diff    | diff_0  | diff_0  | diff_0  | diff_1  | diff_1  | diff_1  |
  +---------+---------+---------+---------+---------+---------+---------+
  | intel   | intel_0 | intel_1 | intel_2 | intel_0 | intel_1 | intel_2 |
  +---------+---------+---------+---------+---------+---------+---------+
  | grade_0 | 0.1     | 0.1     | 0.1     | 0.1     | 0.1     | 0.1     |
  +---------+---------+---------+---------+---------+---------+---------+
  | grade_1 | 0.1     | 0.1     | 0.1     | 0.1     | 0.1     | 0.1     |
  +---------+---------+---------+---------+---------+---------+---------+
  | grade_2 | 0.8     | 0.8     | 0.8     | 0.8     | 0.8     | 0.8     |
  +---------+---------+---------+---------+---------+---------+---------+
  >>> cpd.values
  array([[[ 0.1,  0.1,  0.1],
          [ 0.1,  0.1,  0.1]],
         [[ 0.1,  0.1,  0.1],
          [ 0.1,  0.1,  0.1]],
         [[ 0.8,  0.8,  0.8],
          [ 0.8,  0.8,  0.8]]])
  >>> cpd.variables
  ['grade', 'diff', 'intel']
  >>> cpd.cardinality
  array([3, 2, 3])
  >>> cpd.variable
  'grade'
  >>> cpd.variable_card
  3
class_docstr_tok: ["Defines","the","conditional","probability","distribution","table","(","CPD","table",")","Parameters","--","--","--","--","--","variable",":","int",",","string","(","any","hashable","python","object",")","The","variable","whose","CPD","is","defined",".","variable_card",":","integer","Cardinality\/no",".","of","states","of","`","variable","`","values",":","2D","array",",","2D","list","or","2D","tuple","Values","for","the","CPD","table",".","Please","refer","the","example","for","the","exact","format","needed",".","evidence",":","array-like","List","of","variables","in","evidences","(","if","any",")","w.r.t",".","which","CPD","is","defined",".","evidence_card",":","array-like","cardinality\/no",".","of","states","of","variables","in","`","evidence","`","(","if","any",")","Examples","--","--","--","--","For","a","distribution","of","P","(","grade|diff",",","intel",")","+","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","-+","--","--","--","--","--","--","--","--","--","--","--","--","+","|diff",":","|","easy","|","hard","|","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","+","|aptitude",":","|","low","|","medium","|","high","|","low","|","medium","|","high","|","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","+","|gradeA","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","+","|gradeB","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","+","|gradeC","|","0.8","|","0.8","|","0.8","|","0.8","|","0.8","|","0.8","|","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","-+","--","--","--","+","--","--","--","--","+","--","--","--","--","+","values","should","be","[","[","0.1,0.1,0.1,0.1,0.1,0.1","]",",","[","0.1,0.1,0.1,0.1,0.1,0.1","]",",","[","0.8,0.8,0.8,0.8,0.8,0.8","]","]",">",">",">","cpd","=","TabularCPD","(","'grade',3",",","[","[","0.1,0.1,0.1,0.1,0.1,0.1","]",",","...","[","0.1,0.1,0.1,0.1,0.1,0.1","]",",","...","[","0.8,0.8,0.8,0.8,0.8,0.8","]","]",",","...","evidence=","[","'diff","'",",","'intel","'","]",",","evidence_card=","[","2,3","]",")",">",">",">","print","(","cpd",")","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","|","diff","|","diff_0","|","diff_0","|","diff_0","|","diff_1","|","diff_1","|","diff_1","|","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","|","intel","|","intel_0","|","intel_1","|","intel_2","|","intel_0","|","intel_1","|","intel_2","|","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","|","grade_0","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","|","grade_1","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","0.1","|","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","|","grade_2","|","0.8","|","0.8","|","0.8","|","0.8","|","0.8","|","0.8","|","+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+","--","--","--","--","-+",">",">",">","cpd.values","array","(","[","[","[","0.1",",","0.1",",","0.1","]",",","[","0.1",",","0.1",",","0.1","]","]",",","[","[","0.1",",","0.1",",","0.1","]",",","[","0.1",",","0.1",",","0.1","]","]",",","[","[","0.8",",","0.8",",","0.8","]",",","[","0.8",",","0.8",",","0.8","]","]","]",")",">",">",">","cpd.variables","[","'grade","'",",","'diff","'",",","'intel","'","]",">",">",">","cpd.cardinality","array","(","[","3",",","2",",","3","]",")",">",">",">","cpd.variable","'grade'",">",">",">","cpd.variable_card","3"]
docstr: Returns a new cpd table according to provided parent/evidence order.
  
  Parameters
  ----------
  new_order: list
      list of new ordering of variables
  
  inplace: boolean
      If inplace == True it will modify the CPD itself
      otherwise new value will be returned without affecting old values
  
  Examples
  --------
  
  Consider a CPD P(grade| diff, intel)
  
  >>> cpd = TabularCPD('grade',3,[[0.1,0.1,0.0,0.4,0.2,0.1],
  ...                             [0.3,0.2,0.1,0.4,0.3,0.2],
  ...                             [0.6,0.7,0.9,0.2,0.5,0.7]],
  ...                  evidence=['diff', 'intel'], evidence_card=[2,3])
  >>> print(cpd)
  +----------+----------+----------+----------+----------+----------+----------+
  | diff     | diff(0)  | diff(0)  | diff(0)  | diff(1)  | diff(1)  | diff(1)  |
  +----------+----------+----------+----------+----------+----------+----------+
  | intel    | intel(0) | intel(1) | intel(2) | intel(0) | intel(1) | intel(2) |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(0) | 0.1      | 0.1      | 0.0      | 0.4      | 0.2      | 0.1      |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(1) | 0.3      | 0.2      | 0.1      | 0.4      | 0.3      | 0.2      |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(2) | 0.6      | 0.7      | 0.9      | 0.2      | 0.5      | 0.7      |
  +----------+----------+----------+----------+----------+----------+----------+
  >>> cpd.values
  array([[[ 0.1,  0.1,  0. ],
          [ 0.4,  0.2,  0.1]],
         [[ 0.3,  0.2,  0.1],
          [ 0.4,  0.3,  0.2]],
         [[ 0.6,  0.7,  0.9],
          [ 0.2,  0.5,  0.7]]])
  >>> cpd.variables
  ['grade', 'diff', 'intel']
  >>> cpd.cardinality
  array([3, 2, 3])
  >>> cpd.variable
  'grade'
  >>> cpd.variable_card
  3
  >>> cpd.reorder_parents(['intel', 'diff'])
  array([[0.1, 0.4, 0.1, 0.2, 0. , 0.1],
         [0.3, 0.4, 0.2, 0.3, 0.1, 0.2],
         [0.6, 0.2, 0.7, 0.5, 0.9, 0.7]])
  >>> print(cpd)
  +----------+----------+----------+----------+----------+----------+----------+
  | intel    | intel(0) | intel(0) | intel(1) | intel(1) | intel(2) | intel(2) |
  +----------+----------+----------+----------+----------+----------+----------+
  | diff     | diff(0)  | diff(1)  | diff(0)  | diff(1)  | diff(0)  | diff(1)  |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(0) | 0.1      | 0.4      | 0.1      | 0.2      | 0.0      | 0.1      |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(1) | 0.3      | 0.4      | 0.2      | 0.3      | 0.1      | 0.2      |
  +----------+----------+----------+----------+----------+----------+----------+
  | grade(2) | 0.6      | 0.2      | 0.7      | 0.5      | 0.9      | 0.7      |
  +----------+----------+----------+----------+----------+----------+----------+
  >>> cpd.values
  array([[[0.1, 0.4],
          [0.1, 0.2],
          [0. , 0.1]],
         [[0.3, 0.4],
          [0.2, 0.3],
          [0.1, 0.2]],
         [[0.6, 0.2],
          [0.7, 0.5],
          [0.9, 0.7]]])
  >>> cpd.variables
  ['grade', 'intel', 'diff']
  >>> cpd.cardinality
  array([3, 3, 2])
  >>> cpd.variable
  'grade'
  >>> cpd.variable_card
  3
docstr_tok: ["Returns","a","new","cpd","table","according","to","provided","parent\/evidence","order",".","Parameters","--","--","--","--","--","new_order",":","list","list","of","new","ordering","of","variables","inplace",":","boolean","If","inplace","==","True","it","will","modify","the","CPD","itself","otherwise","new","value","will","be","returned","without","affecting","old","values","Examples","--","--","--","--","Consider","a","CPD","P","(","grade|","diff",",","intel",")",">",">",">","cpd","=","TabularCPD","(","'grade',3",",","[","[","0.1,0.1,0.0,0.4,0.2,0.1","]",",","...","[","0.3,0.2,0.1,0.4,0.3,0.2","]",",","...","[","0.6,0.7,0.9,0.2,0.5,0.7","]","]",",","...","evidence=","[","'diff","'",",","'intel","'","]",",","evidence_card=","[","2,3","]",")",">",">",">","print","(","cpd",")","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","diff","|","diff","(","0",")","|","diff","(","0",")","|","diff","(","0",")","|","diff","(","1",")","|","diff","(","1",")","|","diff","(","1",")","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","intel","|","intel","(","0",")","|","intel","(","1",")","|","intel","(","2",")","|","intel","(","0",")","|","intel","(","1",")","|","intel","(","2",")","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","0",")","|","0.1","|","0.1","|","0.0","|","0.4","|","0.2","|","0.1","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","1",")","|","0.3","|","0.2","|","0.1","|","0.4","|","0.3","|","0.2","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","2",")","|","0.6","|","0.7","|","0.9","|","0.2","|","0.5","|","0.7","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+",">",">",">","cpd.values","array","(","[","[","[","0.1",",","0.1",",","0",".","]",",","[","0.4",",","0.2",",","0.1","]","]",",","[","[","0.3",",","0.2",",","0.1","]",",","[","0.4",",","0.3",",","0.2","]","]",",","[","[","0.6",",","0.7",",","0.9","]",",","[","0.2",",","0.5",",","0.7","]","]","]",")",">",">",">","cpd.variables","[","'grade","'",",","'diff","'",",","'intel","'","]",">",">",">","cpd.cardinality","array","(","[","3",",","2",",","3","]",")",">",">",">","cpd.variable","'grade'",">",">",">","cpd.variable_card","3",">",">",">","cpd.reorder_parents","(","[","'intel","'",",","'diff","'","]",")","array","(","[","[","0.1",",","0.4",",","0.1",",","0.2",",","0.",",","0.1","]",",","[","0.3",",","0.4",",","0.2",",","0.3",",","0.1",",","0.2","]",",","[","0.6",",","0.2",",","0.7",",","0.5",",","0.9",",","0.7","]","]",")",">",">",">","print","(","cpd",")","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","intel","|","intel","(","0",")","|","intel","(","0",")","|","intel","(","1",")","|","intel","(","1",")","|","intel","(","2",")","|","intel","(","2",")","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","diff","|","diff","(","0",")","|","diff","(","1",")","|","diff","(","0",")","|","diff","(","1",")","|","diff","(","0",")","|","diff","(","1",")","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","0",")","|","0.1","|","0.4","|","0.1","|","0.2","|","0.0","|","0.1","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","1",")","|","0.3","|","0.4","|","0.2","|","0.3","|","0.1","|","0.2","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","|","grade","(","2",")","|","0.6","|","0.2","|","0.7","|","0.5","|","0.9","|","0.7","|","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+","--","--","--","--","--","+",">",">",">","cpd.values","array","(","[","[","[","0.1",",","0.4","]",",","[","0.1",",","0.2","]",",","[","0.",",","0.1","]","]",",","[","[","0.3",",","0.4","]",",","[","0.2",",","0.3","]",",","[","0.1",",","0.2","]","]",",","[","[","0.6",",","0.2","]",",","[","0.7",",","0.5","]",",","[","0.9",",","0.7","]","]","]",")",">",">",">","cpd.variables","[","'grade","'",",","'intel","'",",","'diff","'","]",">",">",">","cpd.cardinality","array","(","[","3",",","3",",","2","]",")",">",">",">","cpd.variable","'grade'",">",">",">","cpd.variable_card","3"]
code: def reorder_parents(self, new_order, inplace=True):
      """
      Returns a new cpd table according to provided parent/evidence order.
  
      Parameters
      ----------
      new_order: list
          list of new ordering of variables
  
      inplace: boolean
          If inplace == True it will modify the CPD itself
          otherwise new value will be returned without affecting old values
  
      Examples
      --------
  
      Consider a CPD P(grade| diff, intel)
  
      >>> cpd = TabularCPD('grade',3,[[0.1,0.1,0.0,0.4,0.2,0.1],
      ...                             [0.3,0.2,0.1,0.4,0.3,0.2],
      ...                             [0.6,0.7,0.9,0.2,0.5,0.7]],
      ...                  evidence=['diff', 'intel'], evidence_card=[2,3])
      >>> print(cpd)
      +----------+----------+----------+----------+----------+----------+----------+
      | diff     | diff(0)  | diff(0)  | diff(0)  | diff(1)  | diff(1)  | diff(1)  |
      +----------+----------+----------+----------+----------+----------+----------+
      | intel    | intel(0) | intel(1) | intel(2) | intel(0) | intel(1) | intel(2) |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(0) | 0.1      | 0.1      | 0.0      | 0.4      | 0.2      | 0.1      |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(1) | 0.3      | 0.2      | 0.1      | 0.4      | 0.3      | 0.2      |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(2) | 0.6      | 0.7      | 0.9      | 0.2      | 0.5      | 0.7      |
      +----------+----------+----------+----------+----------+----------+----------+
      >>> cpd.values
      array([[[ 0.1,  0.1,  0. ],
              [ 0.4,  0.2,  0.1]],
             [[ 0.3,  0.2,  0.1],
              [ 0.4,  0.3,  0.2]],
             [[ 0.6,  0.7,  0.9],
              [ 0.2,  0.5,  0.7]]])
      >>> cpd.variables
      ['grade', 'diff', 'intel']
      >>> cpd.cardinality
      array([3, 2, 3])
      >>> cpd.variable
      'grade'
      >>> cpd.variable_card
      3
      >>> cpd.reorder_parents(['intel', 'diff'])
      array([[0.1, 0.4, 0.1, 0.2, 0. , 0.1],
             [0.3, 0.4, 0.2, 0.3, 0.1, 0.2],
             [0.6, 0.2, 0.7, 0.5, 0.9, 0.7]])
      >>> print(cpd)
      +----------+----------+----------+----------+----------+----------+----------+
      | intel    | intel(0) | intel(0) | intel(1) | intel(1) | intel(2) | intel(2) |
      +----------+----------+----------+----------+----------+----------+----------+
      | diff     | diff(0)  | diff(1)  | diff(0)  | diff(1)  | diff(0)  | diff(1)  |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(0) | 0.1      | 0.4      | 0.1      | 0.2      | 0.0      | 0.1      |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(1) | 0.3      | 0.4      | 0.2      | 0.3      | 0.1      | 0.2      |
      +----------+----------+----------+----------+----------+----------+----------+
      | grade(2) | 0.6      | 0.2      | 0.7      | 0.5      | 0.9      | 0.7      |
      +----------+----------+----------+----------+----------+----------+----------+
      >>> cpd.values
      array([[[0.1, 0.4],
              [0.1, 0.2],
              [0. , 0.1]],
             [[0.3, 0.4],
              [0.2, 0.3],
              [0.1, 0.2]],
             [[0.6, 0.2],
              [0.7, 0.5],
              [0.9, 0.7]]])
      >>> cpd.variables
      ['grade', 'intel', 'diff']
      >>> cpd.cardinality
      array([3, 3, 2])
      >>> cpd.variable
      'grade'
      >>> cpd.variable_card
      3
      """
      if (
          len(self.variables) <= 1
          or (set(new_order) - set(self.variables))
          or (set(self.variables[1:]) - set(new_order))
      ):
          raise ValueError(
              "New order either has missing or extra arguments"
          )
      else:
          if new_order != self.variables[1:]:
              evidence = self.variables[1:]
              evidence_card = self.cardinality[1:]
              card_map = dict(zip(evidence, evidence_card))
              old_pos_map = dict(zip(evidence, range(len(evidence))))
              trans_ord = [0] + [
                  (old_pos_map[letter] + 1) for letter in new_order
              ]
              new_values = compat_fns.transpose(
                  self.values, tuple(trans_ord)
              )
  
              if inplace:
                  variables = [self.variables[0]] + new_order
                  cardinality = [self.variable_card] + [
                      card_map[var] for var in new_order
                  ]
                  super(TabularCPD, self).__init__(
                      variables, cardinality, new_values.flatten()
                  )
                  return self.get_values()
              else:
                  return new_values.reshape(
                      tuple(
                          [
                              self.cardinality[0],
                              np.prod(
                                  [card_map[var] for var in new_order]
                              ),
                          ]
                      )
                  )
          else:
              warn("Same ordering provided as current")
              return self.get_values()
  
imports: import csv
  import numbers
  from itertools import chain, product
  from shutil import get_terminal_size
  from warnings import warn
  import numpy
  import torch
  from pgmpy import config
  from pgmpy.extern import tabulate
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 14 for calling the TabularCPD obj's underlying member method code with example usage: obj.reorder_parents(new_order, inplace) and returns: self, self, new_values