class_docstr: Class for performing Gibbs sampling.
  
  Parameters
  ----------
  model: BayesianNetwork or MarkovNetwork
      Model from which variables are inherited and transition probabilities computed.
  
  Examples
  --------
  Initialization from a BayesianNetwork object:
  
  >>> from pgmpy.factors.discrete import TabularCPD
  >>> from pgmpy.models import BayesianNetwork
  >>> intel_cpd = TabularCPD('intel', 2, [[0.7], [0.3]])
  >>> sat_cpd = TabularCPD('sat', 2, [[0.95, 0.2], [0.05, 0.8]], evidence=['intel'], evidence_card=[2])
  >>> student = BayesianNetwork()
  >>> student.add_nodes_from(['intel', 'sat'])
  >>> student.add_edge('intel', 'sat')
  >>> student.add_cpds(intel_cpd, sat_cpd)
  >>> from pgmpy.sampling import GibbsSampling
  >>> gibbs_chain = GibbsSampling(student)
  >>> gibbs_chain.sample(size=3)
     intel  sat
  0      0    0
  1      0    0
  2      1    1
class_docstr_tok: ["Class","for","performing","Gibbs","sampling",".","Parameters","--","--","--","--","--","model",":","BayesianNetwork","or","MarkovNetwork","Model","from","which","variables","are","inherited","and","transition","probabilities","computed",".","Examples","--","--","--","--","Initialization","from","a","BayesianNetwork","object",":",">",">",">","from","pgmpy.factors.discrete","import","TabularCPD",">",">",">","from","pgmpy.models","import","BayesianNetwork",">",">",">","intel_cpd","=","TabularCPD","(","'intel","'",",","2",",","[","[","0.7","]",",","[","0.3","]","]",")",">",">",">","sat_cpd","=","TabularCPD","(","'sat","'",",","2",",","[","[","0.95",",","0.2","]",",","[","0.05",",","0.8","]","]",",","evidence=","[","'intel","'","]",",","evidence_card=","[","2","]",")",">",">",">","student","=","BayesianNetwork","(",")",">",">",">","student.add_nodes_from","(","[","'intel","'",",","'sat","'","]",")",">",">",">","student.add_edge","(","'intel","'",",","'sat","'",")",">",">",">","student.add_cpds","(","intel_cpd",",","sat_cpd",")",">",">",">","from","pgmpy.sampling","import","GibbsSampling",">",">",">","gibbs_chain","=","GibbsSampling","(","student",")",">",">",">","gibbs_chain.sample","(","size=3",")","intel","sat","0","0","0","1","0","0","2","1","1"]
docstr: Generator version of self.sample
  
  Returns
  -------
  List of State namedtuples, representing the assignment to all variables of the model.
  
  Examples
  --------
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> from pgmpy.sampling import GibbsSampling
  >>> from pgmpy.models import MarkovNetwork
  >>> model = MarkovNetwork([('A', 'B'), ('C', 'B')])
  >>> factor_ab = DiscreteFactor(['A', 'B'], [2, 2], [1, 2, 3, 4])
  >>> factor_cb = DiscreteFactor(['C', 'B'], [2, 2], [5, 6, 7, 8])
  >>> model.add_factors(factor_ab, factor_cb)
  >>> gibbs = GibbsSampling(model)
  >>> gen = gibbs.generate_sample(size=2)
  >>> [sample for sample in gen]
  [[State(var='C', state=1), State(var='B', state=1), State(var='A', state=0)],
   [State(var='C', state=0), State(var='B', state=1), State(var='A', state=1)]]
docstr_tok: ["Generator","version","of","self.sample","Returns","--","--","--","-","List","of","State","namedtuples",",","representing","the","assignment","to","all","variables","of","the","model",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","from","pgmpy.sampling","import","GibbsSampling",">",">",">","from","pgmpy.models","import","MarkovNetwork",">",">",">","model","=","MarkovNetwork","(","[","(","'","A","'",",","'","B","'",")",",","(","'","C","'",",","'","B","'",")","]",")",">",">",">","factor_ab","=","DiscreteFactor","(","[","'","A","'",",","'","B","'","]",",","[","2",",","2","]",",","[","1",",","2",",","3",",","4","]",")",">",">",">","factor_cb","=","DiscreteFactor","(","[","'","C","'",",","'","B","'","]",",","[","2",",","2","]",",","[","5",",","6",",","7",",","8","]",")",">",">",">","model.add_factors","(","factor_ab",",","factor_cb",")",">",">",">","gibbs","=","GibbsSampling","(","model",")",">",">",">","gen","=","gibbs.generate_sample","(","size=2",")",">",">",">","[","sample","for","sample","in","gen","]","[","[","State","(","var=","'","C","'",",","state=1",")",",","State","(","var=","'","B","'",",","state=1",")",",","State","(","var=","'","A","'",",","state=0",")","]",",","[","State","(","var=","'","C","'",",","state=0",")",",","State","(","var=","'","B","'",",","state=1",")",",","State","(","var=","'","A","'",",","state=1",")","]","]"]
code: def generate_sample(
      self, start_state=None, size=1, include_latents=False, seed=None
  ):
      """
      Generator version of self.sample
  
      Returns
      -------
      List of State namedtuples, representing the assignment to all variables of the model.
  
      Examples
      --------
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> from pgmpy.sampling import GibbsSampling
      >>> from pgmpy.models import MarkovNetwork
      >>> model = MarkovNetwork([('A', 'B'), ('C', 'B')])
      >>> factor_ab = DiscreteFactor(['A', 'B'], [2, 2], [1, 2, 3, 4])
      >>> factor_cb = DiscreteFactor(['C', 'B'], [2, 2], [5, 6, 7, 8])
      >>> model.add_factors(factor_ab, factor_cb)
      >>> gibbs = GibbsSampling(model)
      >>> gen = gibbs.generate_sample(size=2)
      >>> [sample for sample in gen]
      [[State(var='C', state=1), State(var='B', state=1), State(var='A', state=0)],
       [State(var='C', state=0), State(var='B', state=1), State(var='A', state=1)]]
      """
      if seed is not None:
          np.random.seed(seed)
  
      if start_state is None and self.state is None:
          self.state = self.random_state()
      elif start_state is not None:
          self.set_start_state(start_state)
  
      for i in range(size):
          for j, (var, st) in enumerate(self.state):
              other_st = tuple(st for v, st in self.state if var != v)
              next_st = sample_discrete(
                  list(range(self.cardinalities[var])),
                  self.transition_models[var][other_st],
              )[0]
              self.state[j] = State(var, next_st)
          if include_latents:
              yield self.state[:]
          else:
              yield [s for s in self.state if i not in self.latents]
  
imports: import itertools
  from collections import namedtuple
  import networkx
  import numpy
  import pandas
  import torch
  from joblib import Parallel, delayed
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.factors import factor_product
  from pgmpy.models import BayesianNetwork, MarkovChain, MarkovNetwork
  from pgmpy.sampling import BayesianModelInference, _return_samples
  from pgmpy.utils.mathext import sample_discrete, sample_discrete_maps
label_desc: Use image node_id 5 for calling the GibbsSampling obj's underlying member method code with example usage: obj.generate_sample(start_state, size, include_latents, seed) without return types