def sample_ppc(trace, samples=None, model=None, vars=None, size=None, random_seed=None, progressbar=True):
 if (samples is None):
  samples = len(trace)
 if (model is None):
  model = modelcontext(model)
 if (vars is None):
  vars = model.observed_RVs
 seed(random_seed)
 if progressbar:
  indices = tqdm(randint(0, len(trace), samples), total=samples)
 else:
  indices = randint(0, len(trace), samples)
 ppc = defaultdict(list)
 for idx in indices:
  param = trace[idx]
  for var in vars:
   ppc[var.name].append(var.distribution.random(point=param, size=size))
 return {k: np.asarray(v) for (k, v) in ppc.items()}

def sample_ppc ( trace , samples = None , model = None , vars = None , size = None , random_seed = None , progressbar = True ) : if ( samples is None ) : samples = len ( trace ) if ( model is None ) : model = modelcontext ( model ) if ( vars is None ) : vars = model . observed_RVs seed ( random_seed ) if progressbar : indices = tqdm ( randint ( 0 , len ( trace ) , samples ) , total = samples ) else : indices = randint ( 0 , len ( trace ) , samples ) ppc = defaultdict ( list ) for idx in indices : param = trace [ idx ] for var in vars : ppc [ var . name ] . append ( var . distribution . random ( point = param , size = size ) ) return { k : np . asarray ( v ) for ( k , v ) in ppc . items ( ) }
generate posterior predictive samples from a model given a trace .