probstochsim py -(continued class samplinginferencemethod(inferencemethod)"""the abstract class of sampling-based belief network inference methods"" def __init__(self,gm=none)inferencemethod __init__(selfgm def query(self,qvar,obs={},number_samples= ,sample_order=none)raise notimplementederror("samplinginferencemethod query"abstract rejection sampling probstochsim py -(continued class rejectionsampling(samplinginferencemethod)"""the class that queries graphical models using rejection sampling gm is belief network to query ""method_name "rejection sampling def __init__(selfgm=none)samplinginferencemethod __init__(selfgm def query(selfqvarobs={}number_samples= sample_order=none)"""computes (qvar obswhere qvar is variable obs is {variable:valuedictionary sample_order is list of variables where the parents come before the variable ""if sample_order is nonesample_order self gm topological_sort(self display( ,*sample_order,sep="\ "counts {val: for val in qvar domainfor in range(number_samples)rejected false sample {for nvar in sample_orderfac self gm var cpt[nvar#factor with nvar as child val sample_one({ :fac get_value({**samplenvar: }for in nvar domain}self display( ,val,end="\ "if nvar in obs and obs[nvar!valrejected true self display( ,"rejected"break sample[nvarval version june