class_docstr: Class to represent a Markov Chain with multiple kernels for factored state space,
  along with methods to simulate a run.
  
  Examples
  --------
  
  Create an empty Markov Chain:
  
  >>> from pgmpy.models import MarkovChain as MC
  >>> model = MC()
  
  And then add variables to it
  
  >>> model.add_variables_from(['intel', 'diff'], [2, 3])
  
  Or directly create a Markov Chain from a list of variables and their cardinalities
  
  >>> model = MC(['intel', 'diff'], [2, 3])
  
  Add transition models
  
  >>> intel_tm = {0: {0: 0.25, 1: 0.75}, 1: {0: 0.5, 1: 0.5}}
  >>> model.add_transition_model('intel', intel_tm)
  >>> diff_tm = {0: {0: 0.1, 1: 0.5, 2: 0.4}, 1: {0: 0.2, 1: 0.2, 2: 0.6 }, 2: {0: 0.7, 1: 0.15, 2: 0.15}}
  >>> model.add_transition_model('diff', diff_tm)
  
  Set a start state
  
  >>> from pgmpy.factors.discrete import State
  >>> model.set_start_state([State('intel', 0), State('diff', 2)])
  
  Sample from it
  
  >>> model.sample(size=5)
     intel  diff
  0      0     2
  1      1     0
  2      0     1
  3      1     0
  4      0     2
class_docstr_tok: ["Class","to","represent","a","Markov","Chain","with","multiple","kernels","for","factored","state","space",",","along","with","methods","to","simulate","a","run",".","Examples","--","--","--","--","Create","an","empty","Markov","Chain",":",">",">",">","from","pgmpy.models","import","MarkovChain","as","MC",">",">",">","model","=","MC","(",")","And","then","add","variables","to","it",">",">",">","model.add_variables_from","(","[","'intel","'",",","'diff","'","]",",","[","2",",","3","]",")","Or","directly","create","a","Markov","Chain","from","a","list","of","variables","and","their","cardinalities",">",">",">","model","=","MC","(","[","'intel","'",",","'diff","'","]",",","[","2",",","3","]",")","Add","transition","models",">",">",">","intel_tm","=","{","0",":","{","0",":","0.25",",","1",":","0.75","}",",","1",":","{","0",":","0.5",",","1",":","0.5","}","}",">",">",">","model.add_transition_model","(","'intel","'",",","intel_tm",")",">",">",">","diff_tm","=","{","0",":","{","0",":","0.1",",","1",":","0.5",",","2",":","0.4","}",",","1",":","{","0",":","0.2",",","1",":","0.2",",","2",":","0.6","}",",","2",":","{","0",":","0.7",",","1",":","0.15",",","2",":","0.15","}","}",">",">",">","model.add_transition_model","(","'diff","'",",","diff_tm",")","Set","a","start","state",">",">",">","from","pgmpy.factors.discrete","import","State",">",">",">","model.set_start_state","(","[","State","(","'intel","'",",","0",")",",","State","(","'diff","'",",","2",")","]",")","Sample","from","it",">",">",">","model.sample","(","size=5",")","intel","diff","0","0","2","1","1","0","2","0","1","3","1","0","4","0","2"]
docstr: Checks if the given markov chain is stationary and checks the steady state
  probability values for the state are consistent.
  
  Parameters
  ----------
  tolerance: float
      represents the diff between actual steady state value and the computed value
  sample: [State(i,j)]
      represents the list of state which the markov chain has sampled
  
  Returns
  -------
  Boolean:
      True, if the markov chain converges to steady state distribution within the tolerance
      False, if the markov chain does not converge to steady state distribution within tolerance
  
  Examples
  --------
  >>> from pgmpy.models.MarkovChain import MarkovChain
  >>> from pgmpy.factors.discrete import State
  >>> model = MarkovChain()
  >>> model.add_variables_from(['intel', 'diff'], [3, 2])
  >>> intel_tm = {0: {0: 0.2, 1: 0.4, 2:0.4}, 1: {0: 0, 1: 0.5, 2: 0.5}, 2: {0: 0.3, 1: 0.3, 2: 0.4}}
  >>> model.add_transition_model('intel', intel_tm)
  >>> diff_tm = {0: {0: 0.5, 1: 0.5}, 1: {0: 0.25, 1:0.75}}
  >>> model.add_transition_model('diff', diff_tm)
  >>> model.is_stationarity()
  True
docstr_tok: ["Checks","if","the","given","markov","chain","is","stationary","and","checks","the","steady","state","probability","values","for","the","state","are","consistent",".","Parameters","--","--","--","--","--","tolerance",":","float","represents","the","diff","between","actual","steady","state","value","and","the","computed","value","sample",":","[","State","(","i",",","j",")","]","represents","the","list","of","state","which","the","markov","chain","has","sampled","Returns","--","--","--","-","Boolean",":","True",",","if","the","markov","chain","converges","to","steady","state","distribution","within","the","tolerance","False",",","if","the","markov","chain","does","not","converge","to","steady","state","distribution","within","tolerance","Examples","--","--","--","--",">",">",">","from","pgmpy.models.MarkovChain","import","MarkovChain",">",">",">","from","pgmpy.factors.discrete","import","State",">",">",">","model","=","MarkovChain","(",")",">",">",">","model.add_variables_from","(","[","'intel","'",",","'diff","'","]",",","[","3",",","2","]",")",">",">",">","intel_tm","=","{","0",":","{","0",":","0.2",",","1",":","0.4",",","2:0.4","}",",","1",":","{","0",":","0",",","1",":","0.5",",","2",":","0.5","}",",","2",":","{","0",":","0.3",",","1",":","0.3",",","2",":","0.4","}","}",">",">",">","model.add_transition_model","(","'intel","'",",","intel_tm",")",">",">",">","diff_tm","=","{","0",":","{","0",":","0.5",",","1",":","0.5","}",",","1",":","{","0",":","0.25",",","1:0.75","}","}",">",">",">","model.add_transition_model","(","'diff","'",",","diff_tm",")",">",">",">","model.is_stationarity","(",")","True"]
code: def is_stationarity(self, tolerance=0.2, sample=None):
      """
      Checks if the given markov chain is stationary and checks the steady state
      probability values for the state are consistent.
  
      Parameters
      ----------
      tolerance: float
          represents the diff between actual steady state value and the computed value
      sample: [State(i,j)]
          represents the list of state which the markov chain has sampled
  
      Returns
      -------
      Boolean:
          True, if the markov chain converges to steady state distribution within the tolerance
          False, if the markov chain does not converge to steady state distribution within tolerance
  
      Examples
      --------
      >>> from pgmpy.models.MarkovChain import MarkovChain
      >>> from pgmpy.factors.discrete import State
      >>> model = MarkovChain()
      >>> model.add_variables_from(['intel', 'diff'], [3, 2])
      >>> intel_tm = {0: {0: 0.2, 1: 0.4, 2:0.4}, 1: {0: 0, 1: 0.5, 2: 0.5}, 2: {0: 0.3, 1: 0.3, 2: 0.4}}
      >>> model.add_transition_model('intel', intel_tm)
      >>> diff_tm = {0: {0: 0.5, 1: 0.5}, 1: {0: 0.25, 1:0.75}}
      >>> model.add_transition_model('diff', diff_tm)
      >>> model.is_stationarity()
      True
      """
      keys = self.transition_models.keys()
      return_val = True
      for k in keys:
          # convert dict to numpy matrix
          transition_mat = np.array(
              [
                  np.array(list(self.transition_models[k][i].values()))
                  for i in self.transition_models[k].keys()
              ],
              dtype=float,
          )
          S, U = eig(transition_mat.T)
          stationary = np.array(
              U[:, np.where(np.abs(S - 1.0) < 1e-8)[0][0]].flat
          )
          stationary = (stationary / np.sum(stationary)).real
  
          probabilities = []
          window_size = 10000 if sample is None else len(sample)
          for i in range(0, transition_mat.shape[0]):
              probabilities.extend(
                  self.prob_from_sample(
                      [State(k, i)], window_size=window_size
                  )
              )
          if any(
              np.abs(i) > tolerance
              for i in np.subtract(probabilities, stationary)
          ):
              return_val = return_val and False
          else:
              return_val = return_val and True
  
      return return_val
  
imports: from collections import defaultdict
  import numpy
  from pandas import DataFrame
  from scipy.linalg import eig
  from pgmpy.factors.discrete import State
  from pgmpy.global_vars import logger
  from pgmpy.utils import sample_discrete
label_desc: Use image node_id 10 for calling the MarkovChain obj's underlying member method code with example usage: obj.is_stationarity(tolerance, sample) and returns: return_val