reasoning under uncertainty gibbs sampling the following implements gibbs samplinga form of markov chain monte carlo mcmc probstochsim py -(continued #import random #from probgraphicalmodels import inferencemethod #from probstochsim import sample_onesamplinginferencemethod class gibbssampling(samplinginferencemethod)"""the class that queries graphical models using gibbs sampling bn is graphical model ( belief networkto query ""method_name "gibbs sampling def __init__(selfgm=none)samplinginferencemethod __init__(selfgmself gm gm def query(selfqvarobs={}number_samples= burn_in= sample_order=none)"""computes (qvar obswhere qvar is variable obs is {variable:valuedictionary sample_order is list of non-observed variables in orderor if sample_order nonethe variables are shuffled at each iteration ""counts {val: for val in qvar domainif sample_order is not nonevariables sample_order elsevariables [ for in self gm variables if not in obsvar_to_factors { :set(for in self gm variablesfor fac in self gm factorsfor var in fac variablesvar_to_factors[varadd(facsample {var:random choice(var domainfor var in variablesself display( ,"sample:",samplesample update(obsfor in range(burn_in number_samples)if sample_order =nonerandom shuffle(variablesfor var in variablesget unnormalized probability distribution of var given its neighbours vardist {val: for val in var domainfor val in var domainsample[varval version june