Personal tools
You are here: Home / CarPy / Burns' Python Scripts / Modules / emceeBridge.py

emceeBridge.py

Python Source icon emceeBridge.py — Python Source, 1 KB

File contents

import pymc
import emcee

class emceeBridge:

   def __init__(self, model, p0):
      self.model = model
      vars = model.cont_vars
      self.ordering = pymc.ArrayOrdering(vars)
      self.bij = pymc.DictToArrayBijection(self.ordering, p0)
      self.dim = self.ordering.dimensions
      self.varnames = ['' for i in range(self.dim)]
      for v in self.ordering.vmap:
         ids = range(self.dim)[v.slc]
         for id in ids:
            self.varnames[id] = v.var

   def toarray(self, point):
      return self.bij.map(point)

   def todict(self, arr):
      return self.bij.rmap(arr)

   def varname(self, i):
      '''Find the variable name for parameter array index i.'''
      return self.varnames[i]

   def __call__(self, p):
      logp = self.bij.mapf(self.model.fastlogp)
      return logp(p)