class_docstr: Initialize a `DiscreteFactor` 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 |    phi(x1, x2, x3)|
  +-----+-----+-----+-------------------+
  | x1_0| x2_0| x3_0|     phi.value(0)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_0| x3_1|     phi.value(1)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_1| x3_0|     phi.value(2)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_1| x3_1|     phi.value(3)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_0| x3_0|     phi.value(4)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_0| x3_1|     phi.value(5)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_1| x3_0|     phi.value(6)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_1| x3_1|     phi.value(7)  |
  +-----+-----+-----+-------------------+
  
  Parameters
  ----------
  variables: list, array-like
      List of variables on which the factor is to be defined i.e. scope of the factor.
  
  cardinality: list, array_like
      List of cardinalities/no.of states of each variable. `cardinality`
      array must have a value corresponding to each variable in
      `variables`.
  
  values: list, array_like
      List of values of factor.
      A DiscreteFactor's values are stored in a row vector in the value
      using an ordering such that the left-most variables as defined in
      `variables` cycle through their values the fastest. Please refer
      to examples for usage examples.
  
  Examples
  --------
  >>> import numpy as np
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 2, 2], np.ones(8))
  >>> phi
  <DiscreteFactor representing phi(x1:2, x2:2, x3:2) at 0x7f8188fcaa90>
  >>> print(phi)
  +------+------+------+-----------------+
  | x1   | x2   | x3   |   phi(x1,x2,x3) |
  |------+------+------+-----------------|
  | x1_0 | x2_0 | x3_0 |          1.0000 |
  | x1_0 | x2_0 | x3_1 |          1.0000 |
  | x1_0 | x2_1 | x3_0 |          1.0000 |
  | x1_0 | x2_1 | x3_1 |          1.0000 |
  | x1_1 | x2_0 | x3_0 |          1.0000 |
  | x1_1 | x2_0 | x3_1 |          1.0000 |
  | x1_1 | x2_1 | x3_0 |          1.0000 |
  | x1_1 | x2_1 | x3_1 |          1.0000 |
  +------+------+------+-----------------+
class_docstr_tok: ["Initialize","a","`","DiscreteFactor","`","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","|","phi","(","x1",",","x2",",","x3",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_0|","phi.value","(","0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_1|","phi.value","(","1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_0|","phi.value","(","2",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_1|","phi.value","(","3",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_0|","phi.value","(","4",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_1|","phi.value","(","5",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_0|","phi.value","(","6",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_1|","phi.value","(","7",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","Parameters","--","--","--","--","--","variables",":","list",",","array-like","List","of","variables","on","which","the","factor","is","to","be","defined","i.e",".","scope","of","the","factor",".","cardinality",":","list",",","array_like","List","of","cardinalities\/no.of","states","of","each","variable",".","`","cardinality","`","array","must","have","a","value","corresponding","to","each","variable","in","`","variables","`",".","values",":","list",",","array_like","List","of","values","of","factor",".","A","DiscreteFactor","'s","values","are","stored","in","a","row","vector","in","the","value","using","an","ordering","such","that","the","left-most","variables","as","defined","in","`","variables","`","cycle","through","their","values","the","fastest",".","Please","refer","to","examples","for","usage","examples",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","phi","=","DiscreteFactor","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","2",",","2","]",",","np.ones","(","8",")",")",">",">",">","phi","<","DiscreteFactor","representing","phi","(","x1:2",",","x2:2",",","x3:2",")","at","0x7f8188fcaa90",">",">",">",">","print","(","phi",")","+","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-+","|","x1","|","x2","|","x3","|","phi","(","x1",",","x2",",","x3",")","|","|","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-|","|","x1_0","|","x2_0","|","x3_0","|","1.0000","|","|","x1_0","|","x2_0","|","x3_1","|","1.0000","|","|","x1_0","|","x2_1","|","x3_0","|","1.0000","|","|","x1_0","|","x2_1","|","x3_1","|","1.0000","|","|","x1_1","|","x2_0","|","x3_0","|","1.0000","|","|","x1_1","|","x2_0","|","x3_1","|","1.0000","|","|","x1_1","|","x2_1","|","x3_0","|","1.0000","|","|","x1_1","|","x2_1","|","x3_1","|","1.0000","|","+","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-+"]
docstr: Returns the identity factor.
  
  Def: The identity factor of a factor has the same scope and cardinality as the original factor,
       but the values for all the assignments is 1. When the identity factor is multiplied with
       the factor it returns the factor itself.
  
  Returns
  -------
  Identity factor: pgmpy.factors.discrete.DiscreteFactor.
      Returns a factor with all values set to 1.
  
  Examples
  --------
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
  >>> phi_identity = phi.identity_factor()
  >>> phi_identity.variables
  ['x1', 'x2', 'x3']
  >>> phi_identity.values
  array([[[ 1.,  1.],
          [ 1.,  1.],
          [ 1.,  1.]],
         [[ 1.,  1.],
          [ 1.,  1.],
          [ 1.,  1.]]])
docstr_tok: ["Returns","the","identity","factor",".","Def",":","The","identity","factor","of","a","factor","has","the","same","scope","and","cardinality","as","the","original","factor",",","but","the","values","for","all","the","assignments","is","1",".","When","the","identity","factor","is","multiplied","with","the","factor","it","returns","the","factor","itself",".","Returns","--","--","--","-","Identity","factor",":","pgmpy.factors.discrete.DiscreteFactor",".","Returns","a","factor","with","all","values","set","to","1",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","phi","=","DiscreteFactor","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","3",",","2","]",",","range","(","12",")",")",">",">",">","phi_identity","=","phi.identity_factor","(",")",">",">",">","phi_identity.variables","[","'x1","'",",","'x2","'",",","'x3","'","]",">",">",">","phi_identity.values","array","(","[","[","[","1.",",","1",".","]",",","[","1.",",","1",".","]",",","[","1.",",","1",".","]","]",",","[","[","1.",",","1",".","]",",","[","1.",",","1",".","]",",","[","1.",",","1",".","]","]","]",")"]
code: def identity_factor(self):
      """
      Returns the identity factor.
  
      Def: The identity factor of a factor has the same scope and cardinality as the original factor,
           but the values for all the assignments is 1. When the identity factor is multiplied with
           the factor it returns the factor itself.
  
      Returns
      -------
      Identity factor: pgmpy.factors.discrete.DiscreteFactor.
          Returns a factor with all values set to 1.
  
      Examples
      --------
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
      >>> phi_identity = phi.identity_factor()
      >>> phi_identity.variables
      ['x1', 'x2', 'x3']
      >>> phi_identity.values
      array([[[ 1.,  1.],
              [ 1.,  1.],
              [ 1.,  1.]],
             [[ 1.,  1.],
              [ 1.,  1.],
              [ 1.,  1.]]])
      """
      return DiscreteFactor(
          variables=self.variables,
          cardinality=self.cardinality,
          values=compat_fns.ones(compat_fns.size(self.values)),
          state_names=self.state_names,
      )
  
imports: from collections import namedtuple
  from itertools import product
  import numpy
  import pandas
  import torch
  from pgmpy import config
  from pgmpy.extern import tabulate
  from pgmpy.factors.base import BaseFactor
  from pgmpy.global_vars import logger
  from pgmpy.utils import StateNameMixin, compat_fns
label_desc: Use image node_id 7 for calling the DiscreteFactor obj's underlying member method code with example usage: obj.identity_factor() and returns: DiscreteFactor