def trace_cov(trace, vars=None, model=None):
 model = modelcontext(model)
 if (model is not None):
  vars = model.free_RVs
 elif (vars is None):
  vars = trace.varnames
 def flat_t(var):
  x = trace[str(var)]
  return x.reshape((x.shape[0], np.prod(x.shape[1:], dtype=int)))
 return np.cov(np.concatenate(list(map(flat_t, vars)), 1).T)

def trace_cov ( trace , vars = None , model = None ) : model = modelcontext ( model ) if ( model is not None ) : vars = model . free_RVs elif ( vars is None ) : vars = trace . varnames def flat_t ( var ) : x = trace [ str ( var ) ] return x . reshape ( ( x . shape [ 0 ] , np . prod ( x . shape [ 1 : ] , dtype = int ) ) ) return np . cov ( np . concatenate ( list ( map ( flat_t , vars ) ) , 1 ) . T )
calculate the flattened covariance matrix using a sample trace useful if you want to base your covariance matrix for further sampling on some initial samples .