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: Given an instantiation (partial or complete) of the variables of the model,
  compute the probability of observing it over multiple windows in a given sample.
  
  If 'sample' is not passed as an argument, generate the statistic by sampling from the
  Markov Chain, starting with a random initial state.
  
  Examples
  --------
  >>> from pgmpy.models.MarkovChain import MarkovChain as MC
  >>> from pgmpy.factors.discrete import State
  >>> model = MC(['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: {2: 0.5, 1:0.5}}
  >>> 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.prob_from_sample([State('diff', 0)])
  array([ 0.27,  0.4 ,  0.18,  0.23, ..., 0.29])
docstr_tok: ["Given","an","instantiation","(","partial","or","complete",")","of","the","variables","of","the","model",",","compute","the","probability","of","observing","it","over","multiple","windows","in","a","given","sample",".","If","'sample","'","is","not","passed","as","an","argument",",","generate","the","statistic","by","sampling","from","the","Markov","Chain",",","starting","with","a","random","initial","state",".","Examples","--","--","--","--",">",">",">","from","pgmpy.models.MarkovChain","import","MarkovChain","as","MC",">",">",">","from","pgmpy.factors.discrete","import","State",">",">",">","model","=","MC","(","[","'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",":","{","2",":","0.5",",","1:0.5","}","}",">",">",">","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.prob_from_sample","(","[","State","(","'diff","'",",","0",")","]",")","array","(","[","0.27",",","0.4",",","0.18",",","0.23",",","...",",","0.29","]",")"]
code: def prob_from_sample(self, state, sample=None, window_size=None):
      """
      Given an instantiation (partial or complete) of the variables of the model,
      compute the probability of observing it over multiple windows in a given sample.
  
      If 'sample' is not passed as an argument, generate the statistic by sampling from the
      Markov Chain, starting with a random initial state.
  
      Examples
      --------
      >>> from pgmpy.models.MarkovChain import MarkovChain as MC
      >>> from pgmpy.factors.discrete import State
      >>> model = MC(['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: {2: 0.5, 1:0.5}}
      >>> 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.prob_from_sample([State('diff', 0)])
      array([ 0.27,  0.4 ,  0.18,  0.23, ..., 0.29])
      """
      if sample is None:
          # generate sample of size 10000
          sample = self.sample(self.random_state(), size=10000)
      if window_size is None:
          window_size = len(sample) // 100  # default window size is 100
      windows = len(sample) // window_size
      probabilities = np.zeros(windows)
  
      for i in range(windows):
          for j in range(window_size):
              ind = i * window_size + j
              state_eq = [sample.loc[ind, v] == s for v, s in state]
              if all(state_eq):
                  probabilities[i] += 1
  
      return probabilities / window_size
  
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 8 for calling the MarkovChain obj's underlying member method code with example usage: obj.prob_from_sample(state, sample, window_size) and returns: unknown