def waic(trace, model=None, n_eff=False, pointwise=False):
 model = modelcontext(model)
 log_py = log_post_trace(trace, model)
 lppd_i = logsumexp(log_py, axis=0, b=(1.0 / log_py.shape[0]))
 vars_lpd = np.var(log_py, axis=0)
 if np.any((vars_lpd > 0.4)):
  warnings.warn('For one or more samples the posterior variance of the\n        log predictive densities exceeds 0.4. This could be indication of\n        WAIC starting to fail see http://arxiv.org/abs/1507.04544 for details\n        ')
 waic_i = ((-2) * (lppd_i - vars_lpd))
 waic_se = np.sqrt((len(waic_i) * np.var(waic_i)))
 waic = np.sum(waic_i)
 p_waic = np.sum(vars_lpd)
 if n_eff:
  return (waic, waic_se, p_waic)
 elif pointwise:
  return (waic, waic_se, waic_i, p_waic)
 else:
  return (waic, waic_se)

def waic ( trace , model = None , n_eff = False , pointwise = False ) : model = modelcontext ( model ) log_py = log_post_trace ( trace , model ) lppd_i = logsumexp ( log_py , axis = 0 , b = ( 1.0 / log_py . shape [ 0 ] ) ) vars_lpd = np . var ( log_py , axis = 0 ) if np . any ( ( vars_lpd > 0.4 ) ) : warnings . warn ( 'For one or more samples the posterior variance of the\n        log predictive densities exceeds 0.4. This could be indication of\n        WAIC starting to fail see http://arxiv.org/abs/1507.04544 for details\n        ' ) waic_i = ( ( - 2 ) * ( lppd_i - vars_lpd ) ) waic_se = np . sqrt ( ( len ( waic_i ) * np . var ( waic_i ) ) ) waic = np . sum ( waic_i ) p_waic = np . sum ( vars_lpd ) if n_eff : return ( waic , waic_se , p_waic ) elif pointwise : return ( waic , waic_se , waic_i , p_waic ) else : return ( waic , waic_se )
calculate the widely available information criterion .