You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it'd be great to implement a couple of functions to compute a mu(z) calculation (e.g. for supernova cosmology).
I've whipped up a couple of functions that work on my end within a Numpyro-based BHM sampler (based on BAHAMAS)
importjax.numpyasnpfromjaximportgrad, jit, vmap, random, laximportjaximportjax_cosmoasjcimportscipy.constantsascnstinference_type="w"# the integrand in the calculation of mu from z,cosmology@jitdefintegrand(zba, omegam, omegade, w):
return1.0/np.sqrt(
omegam*(1+zba)**3+omegade*(1+zba)**(3.+3.*w) + (1.-omegam-omegade)*(1.+zba)**2
)
# integration of the integrand given above, vmapped over z-axis@jitdefhubble(z,omegam, omegade,w):
# method for calculating the integralfn=lambdaz: jc.scipy.integrate.romb(integrand,0., z, args=(omegam,omegade,w)) #[0]I=jax.vmap(fn)(z)
returnI
then we can compute a Dlz that changes with the curvature value omegakmag by defining a couple of lax conditional statements
@jitdefDlz(omegam, omegade, h, z, w, z_helio):
# which inference are we doing ?ifinference_type=="omegade":
omegakmag=np.sqrt(np.abs(1-omegam-omegade))
else:
omegakmag=0.hubbleint=hubble(z,omegam,omegade,w)
condition1= (omegam+omegade==1) # return True if = 1 condition2= (omegam+omegade>1.)
#if (omegam+omegade)>1:defifbigger(omegakmag):
return (cnst.c*1e-5*(1+z_helio)/(h*omegakmag)) *np.sin(hubbleint*omegakmag)
# if (omegam+omegade)<1:defifsmaller(omegakmag):
returncnst.c*1e-5*(1+z_helio)/(h*omegakmag) *np.sinh(hubbleint*omegakmag)
# if (omegam+omegade==1):defequalfun(omegakmag):
returncnst.c*1e-5*(1+z_helio)*hubbleint/h# if not equal, default to >1 conditiondefnotequalfun(omegakmag):
returnlax.cond(condition2, true_fun=ifbigger, false_fun=ifsmaller, operand=omegakmag)
distance=lax.cond(condition1, true_fun=equalfun, false_fun=notequalfun, operand=omegakmag)
returndistance# muz: distance modulus as function of params, redshift@jitdefmuz(omegam, w, z):
z_helio=z# should this be different ?omegade=1.-omegam#w = -1.0 # freeze wh=0.72return (5.0*np.log10(Dlz(omegam, omegade, h, z, w, z_helio))+25.)
the calculation for 500 supernova distances is super quick:
time to compute 500 SNIa distance integrals:
CPU times: user 1.23 s, sys: 9.98 ms, total: 1.24 s
Wall time: 1.28 s
A lot of this might be redundant, but would be great to see integrated into the full package. I'm polishing my sampler code on my end, so at the very least these functions could live over there.
The text was updated successfully, but these errors were encountered:
it'd be great to implement a couple of functions to compute a mu(z) calculation (e.g. for supernova cosmology).
I've whipped up a couple of functions that work on my end within a Numpyro-based BHM sampler (based on BAHAMAS)
then we can compute a Dlz that changes with the curvature value
omegakmag
by defining a couple of lax conditional statementsthe calculation for 500 supernova distances is super quick:
A lot of this might be redundant, but would be great to see integrated into the full package. I'm polishing my sampler code on my end, so at the very least these functions could live over there.
The text was updated successfully, but these errors were encountered: