Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
emcee
#1
hi guys, ive been using emcee to sample my parameter..
but I still don't have idea how to combine many likelihoods.. it works fine for just one likelihood..
it will be great if you can tell me how to define the posterior so that I can included many likelihood
actually, here im trying to sample theta with prior as listed below
def logprior_BAO(theta):
    A, B, C, D, epsilon, rd = theta
    if A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5 and 146.96<=rd<=147.58:
        return 0.0
    return -np.inf
I also using another prior for the other object
def logprior_SN(theta):
    A, B, C, D, epsilon, M = theta
    if A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5 and -23<= M <= -16:
        return 0.0
    return -np.inf
how can I tell emcee to use first prior for object A and second prior for object B?

I also confused about including likelihood, here I list my 2 likelihood for 2 different data types. these four are for the firs prior
def log_likelihoodeboss(theta, DAdata, Hdata, DAerr, Herr, z):
    A, B, C, D, epsilon, rd= theta
    Hfid = 67.
    rd_fid = 147.78 #Mpc
    H = Hfid*(A*(1+z)**3 + B + C*z + D*(1+z)**epsilon)**0.5 #km/s/Mpc
    integral = integrate.quad(lambda x: 1/H, 0, z)
    model = c*integral[0] #DM Mpc
    kuantitas1 = model/(1+z)*(rd_fid/rd) #DA Mpc
    kuantitas2 = H*rd/rd_fid
    return -0.5 * (((DAdata - kuantitas1)/DAerr)**2 + np.log(2*np.pi*DAerr**2)+ ((Hdata-kuantitas2)/Herr)**2+np.log(2*np.pi*Herr**2))
def log_likelihood6dfgs(theta, sixdfgs_d, sixdfgs_err, sixdfgs_z):
    A, B, C, D, epsilon, rd= theta
    Hfid = 67.
    H = Hfid*(A*(1+sixdfgs_z)**3 + B + C*sixdfgs_z + D*(1+sixdfgs_z)**epsilon)**0.5
    integral = integrate.quad(lambda x: 1/H, 0, sixdfgs_z)
    DM = c*integral[0]
    DV = (DM**2 *c*sixdfgs_z/H)**1/3
    model = rd/DV
    return -0.5 *((sixdfgs_d - model)/sixdfgs_err)**2 + np.log(2*np.pi*sixdfgs_err**2)
and the last likelihood is for the second prior
def log_likelihoodSN(theta, mb, merr, zsn): 
    A, B, C, D, epsilon, M = theta
    Hfid = 67.
    like = 0.
    for i in range(len(zsn)):
        H = Hfid*(A*(1+zsn[i])**3 + B + C*zsn[i] + D*(1+zsn[i])**epsilon)**0.5
        integral = integrate.quad(lambda x: 1/H, 0, zsn[i])
        DL = c*(1+zsn[i])*integral[0]
        model= 25 + 5*np.log10(DL) + M 
        like += -0.5*(np.log(2*np.pi*(merr[i]**2))+((mb[i] - model)/merr[i])**2) 
    return like
when I run them in separate code files, they work fine.. but I can combine them in one code.. actually I need them to combine, so that the posterior is true.
Best Regards, Hana
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020