0

I'm working on a project were I'm performing a model fitting and my problem is that I have 2 of 4 variables that are discrete (this means that are already generated models that I'm just able to read), so I need that when I use the emcee.EnsembleSampler() takes the values of this two variables from 2 list (e.g. m=[1,2,3,4] ,b=[16,17,18,20] ) while the other variables could remains as a continuous variables.

(to get something more concise let say that I'm adjusting a line to a pair of dots where the lines are pre-made in function of the slope m and the position coefficient b, and that a have 2 other variables that let me shift the model in both directions )

 # Packages
 import numpy as np
 impor emcee

 # Data

 x    = x 
 y    = y
 yerr = yerr

 # Functions
 def lnlike(self,theta, x, y, yerr): # Log Likelihood
     m, b, xs, ys = theta
     model = np.genfromtxt('Generic_name_'+str(m)+str(b)) # a two column file 
     model[:,0]+=xs
     model[:,1]+=ys
     inv_sigma2 = 1.0/(yerr**2 )
     return -0.5*(np.sum((y-model)**2))

 def lnprior(self,theta):  # Priors
     m, b, xs, ys = theta
     if m_min< m <m_max and b_min< b <b_max and xs_min< xs <xs_max and ys_min< ys <ys_max :
         return 0.0 
     return -np.inf

 def lnprob(self,theta, x, y, yerr): # Log Probability
     lp = self.lnprior(theta)
     if not np.isfinite(lp):
         return -np.inf
     return lp + self.lnlike(theta, x, y, yerr) # This return the posterior note that the sum of the (ln prob) is the product of the prob

 nwalker= 200
 nchains= 1500
 ndim   = 4
 fguess = [1,2,3,4] # dumb firt guesses
 pos    = [fguess + sigma_gb*np.random.randn(ndim) for i in range(nwalkers)]


 sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, args=(x, y, abs(yerr)))
 

sampler.run_mcmc(pos, nchains, progress=True)

I'm kind of new with this approach so I'm not sure if this is possible or if I should use another tool, also forget about the issues of subtracting point to a a discrete variable , I've already handle that, this it's just a dumb example to be more concise.

How I can make that the sampler just look around the values that I have a model?

Ian Baeza
  • 1
  • 2

0 Answers0