class_docstr: Base class for Dynamic Bayesian Network
  
  This is a time variant model of the static Bayesian model, where each
  time-slice has some static nodes and is then replicated over a certain
  time period.
  
  The nodes can be any hashable python objects.
  
  Parameters
  ----------
  ebunch: Data to initialize graph.  If data=None (default) an empty
        graph is created.  The data can be an edge list, or any NetworkX
        graph object
  
  Examples
  --------
  Create an empty Dynamic Bayesian Network with no nodes and no edges:
  >>> from pgmpy.models import DynamicBayesianNetwork as DBN
  >>> dbn = DBN()
  
  Adding nodes and edges inside the Dynamic Bayesian Network. A single
  node can be added using the method below. For adding edges we need to
  specify the time slice since edges can be across different time slices.
  
  For example for a network as [image](http://s8.postimg.org/aaybw4x2t/Blank_Flowchart_New_Page_1.png),
  we will need to add all the edges in the 2-TBN as:
  
  >>> dbn.add_edges_from([(('D', 0), ('G', 0)), (('I', 0), ('G', 0)),
  ...                     (('G', 0), ('L', 0)), (('D', 0), ('D', 1)),
  ...                     (('I', 0), ('I', 1)), (('G', 0), ('G', 1)),
  ...                     (('G', 0), ('L', 1)), (('L', 0), ('L', 1))])
  
  We can query the edges and nodes in the network as:
  >>> dbn.nodes()
  ['G', 'D', 'I', 'L']
  >>> dbn.edges()
  [(('D', 1), ('G', 1)), (('I', 0), ('G', 0)), (('I', 0), ('I', 1)),
   (('I', 1), ('G', 1)), (('G', 0), ('L', 0)), (('G', 0), ('G', 1)),
   (('G', 0), ('L', 1)), (('D', 0), ('G', 0)), (('D', 0), ('D', 1)),
   (('L', 0), ('L', 1)), (('G', 1), ('L', 1))]
  
  If any variable is not present in the network while adding an edge,
  pgmpy will automatically add that variable to the network.
  
  But for adding nodes to the model we don't need to specify the time
  slice as it is common in all the time slices. And therefore pgmpy
  automatically replicated it all the time slices. For example, for
  adding a new variable `S` in the above network we can simply do:
  >>> dbn.add_node('S')
  >>> dbn.nodes()
  ['S', 'G', 'D', 'I', 'L']
  
  Public Methods
  --------------
  add_node
  add_nodes_from
  add_edges
  add_edges_from
  add_cpds
  initialize_initial_state
  inter_slice
  intra_slice
  copy
class_docstr_tok: ["Base","class","for","Dynamic","Bayesian","Network","This","is","a","time","variant","model","of","the","static","Bayesian","model",",","where","each","time-slice","has","some","static","nodes","and","is","then","replicated","over","a","certain","time","period",".","The","nodes","can","be","any","hashable","python","objects",".","Parameters","--","--","--","--","--","ebunch",":","Data","to","initialize","graph",".","If","data=None","(","default",")","an","empty","graph","is","created",".","The","data","can","be","an","edge","list",",","or","any","NetworkX","graph","object","Examples","--","--","--","--","Create","an","empty","Dynamic","Bayesian","Network","with","no","nodes","and","no","edges",":",">",">",">","from","pgmpy.models","import","DynamicBayesianNetwork","as","DBN",">",">",">","dbn","=","DBN","(",")","Adding","nodes","and","edges","inside","the","Dynamic","Bayesian","Network",".","A","single","node","can","be","added","using","the","method","below",".","For","adding","edges","we","need","to","specify","the","time","slice","since","edges","can","be","across","different","time","slices",".","For","example","for","a","network","as","[","image","]","(","http",":","\/\/s8.postimg.org\/aaybw4x2t\/Blank_Flowchart_New_Page_1.png",")",",","we","will","need","to","add","all","the","edges","in","the","2-TBN","as",":",">",">",">","dbn.add_edges_from","(","[","(","(","'D","'",",","0",")",",","(","'","G","'",",","0",")",")",",","(","(","'","I","'",",","0",")",",","(","'","G","'",",","0",")",")",",","...","(","(","'","G","'",",","0",")",",","(","'","L","'",",","0",")",")",",","(","(","'D","'",",","0",")",",","(","'D","'",",","1",")",")",",","...","(","(","'","I","'",",","0",")",",","(","'","I","'",",","1",")",")",",","(","(","'","G","'",",","0",")",",","(","'","G","'",",","1",")",")",",","...","(","(","'","G","'",",","0",")",",","(","'","L","'",",","1",")",")",",","(","(","'","L","'",",","0",")",",","(","'","L","'",",","1",")",")","]",")","We","can","query","the","edges","and","nodes","in","the","network","as",":",">",">",">","dbn.nodes","(",")","[","'","G","'",",","'D","'",",","'","I","'",",","'","L","'","]",">",">",">","dbn.edges","(",")","[","(","(","'D","'",",","1",")",",","(","'","G","'",",","1",")",")",",","(","(","'","I","'",",","0",")",",","(","'","G","'",",","0",")",")",",","(","(","'","I","'",",","0",")",",","(","'","I","'",",","1",")",")",",","(","(","'","I","'",",","1",")",",","(","'","G","'",",","1",")",")",",","(","(","'","G","'",",","0",")",",","(","'","L","'",",","0",")",")",",","(","(","'","G","'",",","0",")",",","(","'","G","'",",","1",")",")",",","(","(","'","G","'",",","0",")",",","(","'","L","'",",","1",")",")",",","(","(","'D","'",",","0",")",",","(","'","G","'",",","0",")",")",",","(","(","'D","'",",","0",")",",","(","'D","'",",","1",")",")",",","(","(","'","L","'",",","0",")",",","(","'","L","'",",","1",")",")",",","(","(","'","G","'",",","1",")",",","(","'","L","'",",","1",")",")","]","If","any","variable","is","not","present","in","the","network","while","adding","an","edge",",","pgmpy","will","automatically","add","that","variable","to","the","network",".","But","for","adding","nodes","to","the","model","we","do","n't","need","to","specify","the","time","slice","as","it","is","common","in","all","the","time","slices",".","And","therefore","pgmpy","automatically","replicated","it","all","the","time","slices",".","For","example",",","for","adding","a","new","variable","`","S","`","in","the","above","network","we","can","simply","do",":",">",">",">","dbn.add_node","(","'S","'",")",">",">",">","dbn.nodes","(",")","[","'S","'",",","'","G","'",",","'D","'",",","'","I","'",",","'","L","'","]","Public","Methods","--","--","--","--","--","--","--","add_node","add_nodes_from","add_edges","add_edges_from","add_cpds","initialize_initial_state","inter_slice","intra_slice","copy"]
docstr: Simulates time-series data from the specified model.
  
  Parameters
  ----------
  n_samples: int
      The number of data samples to simulate from the model.
  
  n_time_slices: int
      The number of time slices for which to simulate the data.
  
  do: dict
      The interventions to apply to the model. dict should be of the form
      {(variable_name, time_slice): state}
  
  evidence: dict
      Observed evidence to apply to the model. dict should be of the form
      {(variable_name, time_slice): state}
  
  virtual_evidence: list
      Probabilistically apply evidence to the model. `virtual_evidence` should
      be a list of `pgmpy.factors.discrete.TabularCPD` objects specifying the
      virtual probabilities.
  
  virtual_intervention: list
      Also known as soft intervention. `virtual_intervention` should be a list
      of `pgmpy.factors.discrete.TabularCPD` objects specifying the virtual/soft
      intervention probabilities.
  
  include_latents: boolean (default: False)
      Whether to include the latent variable values in the generated samples.
  
  seed: int (default: None)
      If a value is provided, sets the seed for numpy.random.
  
  show_progress: bool
      If True, shows a progress bar when generating samples.
  
  Returns
  -------
  pandas.DataFrame: A dataframe with the simulated data.
  
  Examples
  --------
  >>> from pgmpy.models import DynamicBayesianNetwork as DBN
  >>> from pgmpy.factors.discrete import TabularCPD
  >>> dbn = DBN([(("D", 0), ("G", 0)), (("I", 0), ("G", 0)),
  ...            (("D", 0), ("D", 1)), (("I", 0), ("I", 1)),])
  >>> diff_cpd = TabularCPD(("D", 0), 2, [[0.6], [0.4]])
  >>> grade_cpd = TabularCPD(variable=("G", 0), variable_card=3,
  ...                        values=[[0.3, 0.05, 0.9, 0.5],
  ...                                [0.4, 0.25, 0.08, 0.3],
  ...                                [0.3, 0.7, 0.02, 0.2]],
  ...                        evidence=[("I", 0), ("D", 0)],
  ...                        evidence_card=[2, 2])
  >>> d_i_cpd = TabularCPD(variable=("D", 1), variable_card=2,
  ...                      values=[[0.6, 0.3], [0.4, 0.7]],
  ...                      evidence=[("D", 0)],
  ...                      evidence_card=[2])
  >>> intel_cpd = TabularCPD(("I", 0), 2, [[0.7], [0.3]])
  >>> i_i_cpd = TabularCPD(variable=("I", 1), variable_card=2,
  ...                      values=[[0.5, 0.4], [0.5, 0.6]],
  ...                      evidence=[("I", 0)],
  ...                      evidence_card=[2])
  >>> g_i_cpd = TabularCPD(variable=("G", 1), variable_card=3,
  ...                      values=[[0.3, 0.05, 0.9, 0.5],
  ...                              [0.4, 0.25, 0.08, 0.3],
  ...                              [0.3, 0.7, 0.02, 0.2]],
  ...                      evidence=[("I", 1), ("D", 1)],
  ...                      evidence_card=[2, 2])
  >>> dbn.add_cpds(diff_cpd, grade_cpd, d_i_cpd, intel_cpd, i_i_cpd, g_i_cpd)
  
  Normal simulation from the model.
  
  >>> dbn.simulate(n_time_slices=4, n_samples=2)
     (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
  0       0       2       0       0       0       1       0       2       0       2       0       0
  1       0       1       0       0       0       1       1       0       1       2       1       0
  
  Simulation with evidence.
  
  >>> dbn.simulate(n_time_slices=4, n_samples=2, evidence={('D', 0): 1, ('D', 2): 0})
     (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
  0       1       1       1       1       2       0       0       2       1       1       0       1
  1       1       2       1       1       2       0       0       1       1       0       0       1
  
  Simulation with virtual/soft evidence.
  
  >>> dbn.simulate(n_time_slices=4, n_samples=2, virtual_evidence=[TabularCPD(('D', 2), 2, [[0.7], [0.3]])])
     (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
  0       0       1       0       0       1       0       0       0       1       0       1       1
  1       0       1       0       0       0       1       0       0       0       0       1       1
  
  Simulation with intervention.
  
  >>> dbn.simulate(n_time_slices=4, n_samples=2, do={('D', 0): 1, ('D', 2): 0})
     (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
  0       1       0       1       1       0       1       0       2       0       0       0       1
  1       1       1       0       1       2       1       0       0       1       1       1       1
  
  Simulation with virtual/soft intervention.
  
  >>> dbn.simulate(n_time_slices=4, n_samples=2, virtual_intervention=[TabularCPD(('D', 2), 2, [[0.7], [0.3]])])
     (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
  0       0       0       0       1       2       0       1       2       1       1       0       1
  1       0       1       1       1       2       0       1       2       1       1       0       0
docstr_tok: ["Simulates","time-series","data","from","the","specified","model",".","Parameters","--","--","--","--","--","n_samples",":","int","The","number","of","data","samples","to","simulate","from","the","model",".","n_time_slices",":","int","The","number","of","time","slices","for","which","to","simulate","the","data",".","do",":","dict","The","interventions","to","apply","to","the","model",".","dict","should","be","of","the","form","{","(","variable_name",",","time_slice",")",":","state","}","evidence",":","dict","Observed","evidence","to","apply","to","the","model",".","dict","should","be","of","the","form","{","(","variable_name",",","time_slice",")",":","state","}","virtual_evidence",":","list","Probabilistically","apply","evidence","to","the","model",".","`","virtual_evidence","`","should","be","a","list","of","`","pgmpy.factors.discrete.TabularCPD","`","objects","specifying","the","virtual","probabilities",".","virtual_intervention",":","list","Also","known","as","soft","intervention",".","`","virtual_intervention","`","should","be","a","list","of","`","pgmpy.factors.discrete.TabularCPD","`","objects","specifying","the","virtual\/soft","intervention","probabilities",".","include_latents",":","boolean","(","default",":","False",")","Whether","to","include","the","latent","variable","values","in","the","generated","samples",".","seed",":","int","(","default",":","None",")","If","a","value","is","provided",",","sets","the","seed","for","numpy.random",".","show_progress",":","bool","If","True",",","shows","a","progress","bar","when","generating","samples",".","Returns","--","--","--","-","pandas.DataFrame",":","A","dataframe","with","the","simulated","data",".","Examples","--","--","--","--",">",">",">","from","pgmpy.models","import","DynamicBayesianNetwork","as","DBN",">",">",">","from","pgmpy.factors.discrete","import","TabularCPD",">",">",">","dbn","=","DBN","(","[","(","(","``","D","''",",","0",")",",","(","``","G","''",",","0",")",")",",","(","(","``","I","''",",","0",")",",","(","``","G","''",",","0",")",")",",","...","(","(","``","D","''",",","0",")",",","(","``","D","''",",","1",")",")",",","(","(","``","I","''",",","0",")",",","(","``","I","''",",","1",")",")",",","]",")",">",">",">","diff_cpd","=","TabularCPD","(","(","``","D","''",",","0",")",",","2",",","[","[","0.6","]",",","[","0.4","]","]",")",">",">",">","grade_cpd","=","TabularCPD","(","variable=","(","``","G","''",",","0",")",",","variable_card=3",",","...","values=","[","[","0.3",",","0.05",",","0.9",",","0.5","]",",","...","[","0.4",",","0.25",",","0.08",",","0.3","]",",","...","[","0.3",",","0.7",",","0.02",",","0.2","]","]",",","...","evidence=","[","(","``","I","''",",","0",")",",","(","``","D","''",",","0",")","]",",","...","evidence_card=","[","2",",","2","]",")",">",">",">","d_i_cpd","=","TabularCPD","(","variable=","(","``","D","''",",","1",")",",","variable_card=2",",","...","values=","[","[","0.6",",","0.3","]",",","[","0.4",",","0.7","]","]",",","...","evidence=","[","(","``","D","''",",","0",")","]",",","...","evidence_card=","[","2","]",")",">",">",">","intel_cpd","=","TabularCPD","(","(","``","I","''",",","0",")",",","2",",","[","[","0.7","]",",","[","0.3","]","]",")",">",">",">","i_i_cpd","=","TabularCPD","(","variable=","(","``","I","''",",","1",")",",","variable_card=2",",","...","values=","[","[","0.5",",","0.4","]",",","[","0.5",",","0.6","]","]",",","...","evidence=","[","(","``","I","''",",","0",")","]",",","...","evidence_card=","[","2","]",")",">",">",">","g_i_cpd","=","TabularCPD","(","variable=","(","``","G","''",",","1",")",",","variable_card=3",",","...","values=","[","[","0.3",",","0.05",",","0.9",",","0.5","]",",","...","[","0.4",",","0.25",",","0.08",",","0.3","]",",","...","[","0.3",",","0.7",",","0.02",",","0.2","]","]",",","...","evidence=","[","(","``","I","''",",","1",")",",","(","``","D","''",",","1",")","]",",","...","evidence_card=","[","2",",","2","]",")",">",">",">","dbn.add_cpds","(","diff_cpd",",","grade_cpd",",","d_i_cpd",",","intel_cpd",",","i_i_cpd",",","g_i_cpd",")","Normal","simulation","from","the","model",".",">",">",">","dbn.simulate","(","n_time_slices=4",",","n_samples=2",")","(","D",",","0",")","(","G",",","0",")","(","I",",","0",")","(","D",",","1",")","(","G",",","1",")","(","I",",","1",")","(","D",",","2",")","(","G",",","2",")","(","D",",","3",")","(","G",",","3",")","(","I",",","2",")","(","I",",","3",")","0","0","2","0","0","0","1","0","2","0","2","0","0","1","0","1","0","0","0","1","1","0","1","2","1","0","Simulation","with","evidence",".",">",">",">","dbn.simulate","(","n_time_slices=4",",","n_samples=2",",","evidence=","{","(","'D","'",",","0",")",":","1",",","(","'D","'",",","2",")",":","0","}",")","(","D",",","0",")","(","G",",","0",")","(","I",",","0",")","(","D",",","1",")","(","G",",","1",")","(","I",",","1",")","(","D",",","2",")","(","G",",","2",")","(","D",",","3",")","(","G",",","3",")","(","I",",","2",")","(","I",",","3",")","0","1","1","1","1","2","0","0","2","1","1","0","1","1","1","2","1","1","2","0","0","1","1","0","0","1","Simulation","with","virtual\/soft","evidence",".",">",">",">","dbn.simulate","(","n_time_slices=4",",","n_samples=2",",","virtual_evidence=","[","TabularCPD","(","(","'D","'",",","2",")",",","2",",","[","[","0.7","]",",","[","0.3","]","]",")","]",")","(","D",",","0",")","(","G",",","0",")","(","I",",","0",")","(","D",",","1",")","(","G",",","1",")","(","I",",","1",")","(","D",",","2",")","(","G",",","2",")","(","D",",","3",")","(","G",",","3",")","(","I",",","2",")","(","I",",","3",")","0","0","1","0","0","1","0","0","0","1","0","1","1","1","0","1","0","0","0","1","0","0","0","0","1","1","Simulation","with","intervention",".",">",">",">","dbn.simulate","(","n_time_slices=4",",","n_samples=2",",","do=","{","(","'D","'",",","0",")",":","1",",","(","'D","'",",","2",")",":","0","}",")","(","D",",","0",")","(","G",",","0",")","(","I",",","0",")","(","D",",","1",")","(","G",",","1",")","(","I",",","1",")","(","D",",","2",")","(","G",",","2",")","(","D",",","3",")","(","G",",","3",")","(","I",",","2",")","(","I",",","3",")","0","1","0","1","1","0","1","0","2","0","0","0","1","1","1","1","0","1","2","1","0","0","1","1","1","1","Simulation","with","virtual\/soft","intervention",".",">",">",">","dbn.simulate","(","n_time_slices=4",",","n_samples=2",",","virtual_intervention=","[","TabularCPD","(","(","'D","'",",","2",")",",","2",",","[","[","0.7","]",",","[","0.3","]","]",")","]",")","(","D",",","0",")","(","G",",","0",")","(","I",",","0",")","(","D",",","1",")","(","G",",","1",")","(","I",",","1",")","(","D",",","2",")","(","G",",","2",")","(","D",",","3",")","(","G",",","3",")","(","I",",","2",")","(","I",",","3",")","0","0","0","0","1","2","0","1","2","1","1","0","1","1","0","1","1","1","2","0","1","2","1","1","0","0"]
code: def simulate(
      self,
      n_samples=10,
      n_time_slices=2,
      do=None,
      evidence=None,
      virtual_evidence=None,
      virtual_intervention=None,
      include_latents=False,
      seed=None,
      show_progress=True,
  ):
      """
      Simulates time-series data from the specified model.
  
      Parameters
      ----------
      n_samples: int
          The number of data samples to simulate from the model.
  
      n_time_slices: int
          The number of time slices for which to simulate the data.
  
      do: dict
          The interventions to apply to the model. dict should be of the form
          {(variable_name, time_slice): state}
  
      evidence: dict
          Observed evidence to apply to the model. dict should be of the form
          {(variable_name, time_slice): state}
  
      virtual_evidence: list
          Probabilistically apply evidence to the model. `virtual_evidence` should
          be a list of `pgmpy.factors.discrete.TabularCPD` objects specifying the
          virtual probabilities.
  
      virtual_intervention: list
          Also known as soft intervention. `virtual_intervention` should be a list
          of `pgmpy.factors.discrete.TabularCPD` objects specifying the virtual/soft
          intervention probabilities.
  
      include_latents: boolean (default: False)
          Whether to include the latent variable values in the generated samples.
  
      seed: int (default: None)
          If a value is provided, sets the seed for numpy.random.
  
      show_progress: bool
          If True, shows a progress bar when generating samples.
  
      Returns
      -------
      pandas.DataFrame: A dataframe with the simulated data.
  
      Examples
      --------
      >>> from pgmpy.models import DynamicBayesianNetwork as DBN
      >>> from pgmpy.factors.discrete import TabularCPD
      >>> dbn = DBN([(("D", 0), ("G", 0)), (("I", 0), ("G", 0)),
      ...            (("D", 0), ("D", 1)), (("I", 0), ("I", 1)),])
      >>> diff_cpd = TabularCPD(("D", 0), 2, [[0.6], [0.4]])
      >>> grade_cpd = TabularCPD(variable=("G", 0), variable_card=3,
      ...                        values=[[0.3, 0.05, 0.9, 0.5],
      ...                                [0.4, 0.25, 0.08, 0.3],
      ...                                [0.3, 0.7, 0.02, 0.2]],
      ...                        evidence=[("I", 0), ("D", 0)],
      ...                        evidence_card=[2, 2])
      >>> d_i_cpd = TabularCPD(variable=("D", 1), variable_card=2,
      ...                      values=[[0.6, 0.3], [0.4, 0.7]],
      ...                      evidence=[("D", 0)],
      ...                      evidence_card=[2])
      >>> intel_cpd = TabularCPD(("I", 0), 2, [[0.7], [0.3]])
      >>> i_i_cpd = TabularCPD(variable=("I", 1), variable_card=2,
      ...                      values=[[0.5, 0.4], [0.5, 0.6]],
      ...                      evidence=[("I", 0)],
      ...                      evidence_card=[2])
      >>> g_i_cpd = TabularCPD(variable=("G", 1), variable_card=3,
      ...                      values=[[0.3, 0.05, 0.9, 0.5],
      ...                              [0.4, 0.25, 0.08, 0.3],
      ...                              [0.3, 0.7, 0.02, 0.2]],
      ...                      evidence=[("I", 1), ("D", 1)],
      ...                      evidence_card=[2, 2])
      >>> dbn.add_cpds(diff_cpd, grade_cpd, d_i_cpd, intel_cpd, i_i_cpd, g_i_cpd)
  
      Normal simulation from the model.
  
      >>> dbn.simulate(n_time_slices=4, n_samples=2)
         (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
      0       0       2       0       0       0       1       0       2       0       2       0       0
      1       0       1       0       0       0       1       1       0       1       2       1       0
  
      Simulation with evidence.
  
      >>> dbn.simulate(n_time_slices=4, n_samples=2, evidence={('D', 0): 1, ('D', 2): 0})
         (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
      0       1       1       1       1       2       0       0       2       1       1       0       1
      1       1       2       1       1       2       0       0       1       1       0       0       1
  
      Simulation with virtual/soft evidence.
  
      >>> dbn.simulate(n_time_slices=4, n_samples=2, virtual_evidence=[TabularCPD(('D', 2), 2, [[0.7], [0.3]])])
         (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
      0       0       1       0       0       1       0       0       0       1       0       1       1
      1       0       1       0       0       0       1       0       0       0       0       1       1
  
      Simulation with intervention.
  
      >>> dbn.simulate(n_time_slices=4, n_samples=2, do={('D', 0): 1, ('D', 2): 0})
         (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
      0       1       0       1       1       0       1       0       2       0       0       0       1
      1       1       1       0       1       2       1       0       0       1       1       1       1
  
      Simulation with virtual/soft intervention.
  
      >>> dbn.simulate(n_time_slices=4, n_samples=2, virtual_intervention=[TabularCPD(('D', 2), 2, [[0.7], [0.3]])])
         (D, 0)  (G, 0)  (I, 0)  (D, 1)  (G, 1)  (I, 1)  (D, 2)  (G, 2)  (D, 3)  (G, 3)  (I, 2)  (I, 3)
      0       0       0       0       1       2       0       1       2       1       1       0       1
      1       0       1       1       1       2       0       1       2       1       1       0       0
      """
      from pgmpy.sampling import BayesianModelSampling
  
      if show_progress and config.SHOW_PROGRESS:
          pbar = tqdm(total=n_time_slices * len(self._nodes()))
  
      # Step 1: Create some data structures for easily accessing values
      do = {} if do is None else do
      evidence = {} if evidence is None else evidence
      virtual_intervention = (
          [] if virtual_intervention is None else virtual_intervention
      )
      virtual_evidence = (
          [] if virtual_evidence is None else virtual_evidence
      )
  
      do_dict = defaultdict(dict)
      evidence_dict = defaultdict(dict)
      virtual_inter_dict = defaultdict(list)
      virtual_evi_dict = defaultdict(list)
  
      for var, state in do.items():
          do_dict[var[1]][str(var[0]) + "_" + str(var[1])] = state
      for var, state in evidence.items():
          evidence_dict[var[1]][str(var[0]) + "_" + str(var[1])] = state
      for cpd in virtual_intervention:
          new_vars = [
              str(var[0]) + "_" + str(var[1]) for var in cpd.variables
          ]
          new_cpd = TabularCPD(
              variable=new_vars[0],
              variable_card=cpd.cardinality[0],
              values=cpd.get_values(),
              evidence=new_vars[1:],
              evidence_card=cpd.cardinality[1:],
          )
          virtual_inter_dict[cpd.variables[0][1]].append(new_cpd)
      for cpd in virtual_evidence:
          new_vars = [
              str(var[0]) + "_" + str(var[1]) for var in cpd.variables
          ]
          new_cpd = TabularCPD(
              variable=new_vars[0],
              variable_card=cpd.cardinality[0],
              values=cpd.get_values(),
              evidence=new_vars[1:],
              evidence_card=cpd.cardinality[1:],
          )
          virtual_evi_dict[cpd.variables[0][1]].append(new_cpd)
  
      # Step 2: Generate first two time samples
      const_bn = self.get_constant_bn(t_slice=0)
      sampled = const_bn.simulate(
          n_samples=n_samples,
          do={**do_dict[0], **do_dict[1]},
          evidence={**evidence_dict[0], **evidence_dict[1]},
          virtual_evidence=[*virtual_evi_dict[0], *virtual_evi_dict[1]],
          virtual_intervention=[
              *virtual_inter_dict[0],
              *virtual_inter_dict[1],
          ],
          include_latents=True,
          seed=seed,
          show_progress=False,
      )
      if n_time_slices == 1:
          sampled = self._postprocess(sampled)
          return sampled.loc[
              :, [col for col in sampled.columns if col[1] == 0]
          ]
      elif n_time_slices == 2:
          sampled = self._postprocess(sampled)
          return sampled
  
      # Step 3: If n_time_slices > 2, iterate over the time slices and generate samples
      for t_slice in range(1, n_time_slices - 1):
          const_bn = self.get_constant_bn(t_slice=t_slice)
          partial_colnames = [
              str(node) + "_" + str(t_slice) for node in self._nodes()
          ]
          partial_df = sampled.loc[:, partial_colnames]
          remaining_df = sampled.loc[
              :, ~sampled.columns.isin(partial_colnames)
          ]
          new_samples = const_bn.simulate(
              n_samples=n_samples,
              do={**do_dict[t_slice], **do_dict[t_slice + 1]},
              evidence={
                  **evidence_dict[t_slice],
                  **evidence_dict[t_slice + 1],
              },
              virtual_evidence=[
                  *virtual_evi_dict[t_slice],
                  *virtual_evi_dict[t_slice + 1],
              ],
              virtual_intervention=[
                  *virtual_inter_dict[t_slice],
                  *virtual_inter_dict[t_slice + 1],
              ],
              include_latents=True,
              partial_samples=partial_df,
              seed=seed,
              show_progress=False,
          )
          sampled = pd.concat((remaining_df, new_samples), axis=1)
      return self._postprocess(sampled)
  
imports: import typing
  from collections import defaultdict
  from dataclasses import dataclass
  from itertools import chain, combinations
  import networkx
  import numpy
  import pandas
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.base import DAG
  from pgmpy.factors.discrete import TabularCPD
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 24 for calling the DynamicBayesianNetwork obj's underlying member method code with example usage: obj.simulate(n_samples, n_time_slices, do, evidence, virtual_evidence, virtual_intervention, include_latents, seed, show_progress) and returns: self, sampled, sampled