def map(prob, modulename='model'): try: mystr = "from " + modulename + " import model" exec(mystr) except: print('cannot import', modulename) M = MAP(model(prob)) M.fit() return M
def sample(self, model, mapstart=False, step_methods=None, iters=80000, burn=20000, num_chains=4, doplot=True, showplots=False, force=False, progress_bar=False): print('MCMC for %s' % self.name) if self.is_done(): if not force: print('\tAlready done, skipping...') return self.db_file else: print( '\tWARNING: recomputing, there might be spurious files from previous runs...' ) # Not a good idea # Let's graph the model graph = pymc.graph.dag(pymc.Model(model), name=self.name, path=self.model_dir) graph.write_png(op.join(self.model_dir, self.name + '.png')) start = time.time() if mapstart: # See http://stronginference.com/post/burn-in-and-other-mcmc-folklore # BUT WARNING, WOULD THIS MAKE MULTIPLE CHAIN START BE OVERLY CORRELATED? try: from pymc import MAP print('\tFinding MAP estimates...') M = MAP(model) M.fit() model = M.variables print('\tMAP estimates found...') except Exception, e: print('\tMAP Failed...', str(e))