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: Computes the Gibbs transition models from a Bayesian Network.
  'Probabilistic Graphical Model Principles and Techniques', Koller and
  Friedman, Section 12.3.3 pp 512-513.
  
  Parameters
  ----------
  model: BayesianNetwork
      The model from which probabilities will be computed.
docstr_tok: ["Computes","the","Gibbs","transition","models","from","a","Bayesian","Network",".","'Probabilistic","Graphical","Model","Principles","and","Techniques","'",",","Koller","and","Friedman",",","Section","12.3.3","pp","512-513",".","Parameters","--","--","--","--","--","model",":","BayesianNetwork","The","model","from","which","probabilities","will","be","computed","."]
code: def _get_kernel_from_bayesian_model(self, model):
      """
      Computes the Gibbs transition models from a Bayesian Network.
      'Probabilistic Graphical Model Principles and Techniques', Koller and
      Friedman, Section 12.3.3 pp 512-513.
  
      Parameters
      ----------
      model: BayesianNetwork
          The model from which probabilities will be computed.
      """
      self.variables = np.array(model.nodes())
      self.latents = model.latents
      self.cardinalities = {
          var: model.get_cpds(var).variable_card
          for var in self.variables
      }
  
      for var in self.variables:
          other_vars = [v for v in self.variables if var != v]
          other_cards = [self.cardinalities[v] for v in other_vars]
          kernel = {}
          factors = [
              cpd.to_factor()
              for cpd in model.cpds
              if var in cpd.scope()
          ]
          factor = factor_product(*factors)
          scope = set(factor.scope())
          for tup in itertools.product(
              *[range(card) for card in other_cards]
          ):
              states = [
                  State(v, s)
                  for v, s in zip(other_vars, tup)
                  if v in scope
              ]
              reduced_factor = factor.reduce(states, inplace=False)
              kernel[tup] = reduced_factor.values / sum(
                  reduced_factor.values
              )
          self.transition_models[var] = kernel
  
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 2 for calling the GibbsSampling obj's underlying member method code with example usage: obj._get_kernel_from_bayesian_model(model) without return types