def likelihood_function(right_ascension, declination, phi_orb, inclination, psi, distance): # use EXTREMELY many bits lnL = numpy.zeros(right_ascension.shape, dtype=numpy.float128) # PRB: can we move this loop inside the factored_likelihood? It might help. i = 0 # choose an array at the target sampling rate. P is inherited globally for ph, th, phr, ic, ps, di in zip(right_ascension, declination, phi_orb, inclination, psi, distance): P.phi = ph # right ascension P.theta = th # declination P.tref = fiducial_epoch # see 'tvals', above P.phiref = phr # ref. orbital phase P.incl = ic # inclination P.psi = ps # polarization angle P.dist = di * 1.e6 * lal.PC_SI # luminosity distance lnL[i] = factored_likelihood.factored_log_likelihood_time_marginalized( tvals, P, rholms_intp, rholms, cross_terms, det_epochs, opts.l_max, interpolate=opts.interpolate_time) i += 1 return numpy.exp(lnL)
def likelihood_function(right_ascension, declination, phi_orb, inclination, psi, distance): # use EXTREMELY many bits lnL = numpy.zeros(right_ascension.shape,dtype=numpy.float128) # PRB: can we move this loop inside the factored_likelihood? It might help. i = 0 # choose an array at the target sampling rate. P is inherited globally for ph, th, phr, ic, ps, di in zip(right_ascension, declination, phi_orb, inclination, psi, distance): P.phi = ph # right ascension P.theta = th # declination P.tref = fiducial_epoch # see 'tvals', above P.phiref = phr # ref. orbital phase P.incl = ic # inclination P.psi = ps # polarization angle P.dist = di* 1.e6 * lal.PC_SI # luminosity distance lnL[i] = factored_likelihood.factored_log_likelihood_time_marginalized(tvals, P, rholms_intp, rholms, cross_terms, det_epochs, opts.l_max,interpolate=opts.interpolate_time) i+=1 return numpy.exp(lnL)
def likelihood_function(right_ascension, declination, phi_orb, inclination, psi, distance): P.phi = right_ascension # right ascension P.theta = declination # declination P.tref = fiducial_epoch # see 'tvals', above P.phiref = phi_orb # ref. orbital phase P.incl = inclination # inclination P.psi = psi # polarization angle P.dist = distance * 1.e6 * lal.PC_SI # luminosity distance lnL = factored_likelihood.factored_log_likelihood_time_marginalized( tvals, P, rholms_intp, rholms, cross_terms, det_epochs, opts.l_max, interpolate=opts.interpolate_time) return numpy.exp(lnL)
def likelihood_function(right_ascension, declination, phi_orb, inclination, psi, distance): ''' # FIXME - this is pretty bad max_tpb = 1024 # Max number of threads per block for GPU: FIXME should be an --option ntimes = len(rholms['H1'][(2,0)]) # FIXME this should be dynamic nmodes = len(rholms['H1'].keys()) # FIXME this should be dynamic too nclmns = numpy.int32( ntimes + max_tpb - (ntimes % max_tpb) ) # Number of cols to pad w/ 0s nsamps = len(right_ascension) ''' ### import math right_ascension = numpy.linspace(0.1, math.pi, nsamps) + 1.0 declination = numpy.linspace(0.1, math.pi, nsamps) + 2.0 tref = numpy.linspace(0.1, math.pi, nsamps) + 3.0 phi_orb = numpy.linspace(0.1, math.pi, nsamps) + 4.0 inclination = numpy.linspace(0.1, math.pi, nsamps) + 5.0 psi = numpy.linspace(0.1, math.pi, nsamps) + 6.0 #distance = numpy.linspace(0.1, math.pi, nsamps) + 7.0 distance = numpy.ones(nsamps).astype(numpy.float64) ### ''' right_ascension = right_ascension.astype(numpy.float64) declination = declination.astype(numpy.float64) tref = numpy.array([fiducial_epoch for item in right_ascension]).astype(numpy.float64) phi_orb = phi_orb.astype(numpy.float64) inclination = inclination.astype(numpy.float64) psi = psi.astype(numpy.float64) distance = distance.astype(numpy.float64)*1.e6*lal.PC_SI # Pass a block of zeros onto the GPU to hold results from each detector lnL_block = numpy.zeros((nsamps * nmodes, nclmns)).astype(numpy.float64) lnL_block_gpu = gpuarray.to_gpu(lnL_block) ''' for det in rholms.keys(): # Convert the crossterms to matrices CTU = numpy.zeros(len(cross_termsU[det].keys()), dtype=numpy.complex128) CTV = numpy.zeros(len(cross_termsV[det].keys()), dtype=numpy.complex128) sort_terms_keys = sorted(cross_termsU[det], key=lambda tup: (tup[0][1], tup[1][1])) for i in range(0, len(cross_termsU[det].keys())): CTU[i] = cross_termsU[det][sort_terms_keys[i]] CTV[i] = cross_termsV[det][sort_terms_keys[i]] side = numpy.sqrt(len(cross_termsU[det].keys())) CTU = CTU.reshape((side, side)) CTV = CTV.reshape((side, side)) det_tns = numpy.array( lalsim.DetectorPrefixToLALDetector(det).response).astype( numpy.float64) lnL_block_gpu += factored_likelihood.factored_log_likelihood_time_marginalized_gpu( mod, right_ascension, declination, tref, phi_orb, inclination, psi, distance, det_tns, rholms[det], CTU, CTV) print("Marginalizing over Time... \n") network_lnL_marg_gpu = factored_likelihood.marginalize_all_lnL( mod, lnL_block_gpu, nmodes, nsamps, ntimes, nclmns, tvals[1] - tvals[0]) print("Done marginalizing over time. \n") # OLD STUFF # use EXTREMELY many bits lnL = numpy.zeros(right_ascension.shape, dtype=numpy.float128) # PRB: can we move this loop inside the factored_likelihood? It might help. i = 0 # choose an array at the target sampling rate. P is inherited globally for ph, th, phr, ic, ps, di in zip(right_ascension, declination, phi_orb, inclination, psi, distance): P.phi = ph # right ascension P.theta = th # declination P.tref = tref[i] #fiducial_epoch # see 'tvals', above P.phiref = phr # ref. orbital phase P.incl = ic # inclination P.psi = ps # polarization angle P.dist = di * 1.e6 * lal.PC_SI # luminosity distance lnL[i] = factored_likelihood.factored_log_likelihood_time_marginalized( tvals, P, rholms_intp, rholms, cross_termsU, cross_termsV, det_epochs, opts.l_max, interpolate=opts.interpolate_time) i += 1 import pdb pdb.set_trace() return numpy.exp(lnL)
def likelihood_function(right_ascension, declination, phi_orb, inclination, psi, distance): ''' # FIXME - this is pretty bad max_tpb = 1024 # Max number of threads per block for GPU: FIXME should be an --option ntimes = len(rholms['H1'][(2,0)]) # FIXME this should be dynamic nmodes = len(rholms['H1'].keys()) # FIXME this should be dynamic too nclmns = numpy.int32( ntimes + max_tpb - (ntimes % max_tpb) ) # Number of cols to pad w/ 0s nsamps = len(right_ascension) ''' ### import math right_ascension = numpy.linspace(0.1, math.pi, nsamps) + 1.0 declination = numpy.linspace(0.1, math.pi, nsamps) + 2.0 tref = numpy.linspace(0.1, math.pi, nsamps) + 3.0 phi_orb = numpy.linspace(0.1, math.pi, nsamps) + 4.0 inclination = numpy.linspace(0.1, math.pi, nsamps) + 5.0 psi = numpy.linspace(0.1, math.pi, nsamps) + 6.0 #distance = numpy.linspace(0.1, math.pi, nsamps) + 7.0 distance = numpy.ones(nsamps).astype(numpy.float64) ### ''' right_ascension = right_ascension.astype(numpy.float64) declination = declination.astype(numpy.float64) tref = numpy.array([fiducial_epoch for item in right_ascension]).astype(numpy.float64) phi_orb = phi_orb.astype(numpy.float64) inclination = inclination.astype(numpy.float64) psi = psi.astype(numpy.float64) distance = distance.astype(numpy.float64)*1.e6*lal.PC_SI # Pass a block of zeros onto the GPU to hold results from each detector lnL_block = numpy.zeros((nsamps * nmodes, nclmns)).astype(numpy.float64) lnL_block_gpu = gpuarray.to_gpu(lnL_block) ''' for det in rholms.keys(): # Convert the crossterms to matrices CTU = numpy.zeros(len(cross_termsU[det].keys()), dtype=numpy.complex128) CTV = numpy.zeros(len(cross_termsV[det].keys()), dtype=numpy.complex128) sort_terms_keys = sorted(cross_termsU[det], key=lambda tup: (tup[0][1], tup[1][1])) for i in range(0, len(cross_termsU[det].keys())): CTU[i] = cross_termsU[det][sort_terms_keys[i]] CTV[i] = cross_termsV[det][sort_terms_keys[i]] side = numpy.sqrt(len(cross_termsU[det].keys())) CTU = CTU.reshape((side, side)) CTV = CTV.reshape((side, side)) det_tns = numpy.array(lalsim.DetectorPrefixToLALDetector(det).response).astype(numpy.float64) lnL_block_gpu += factored_likelihood.factored_log_likelihood_time_marginalized_gpu(mod, right_ascension, declination, tref, phi_orb, inclination, psi, distance, det_tns, rholms[det], CTU, CTV) print("Marginalizing over Time... \n") network_lnL_marg_gpu = factored_likelihood.marginalize_all_lnL(mod, lnL_block_gpu, nmodes, nsamps, ntimes, nclmns, tvals[1]-tvals[0]) print("Done marginalizing over time. \n") # OLD STUFF # use EXTREMELY many bits lnL = numpy.zeros(right_ascension.shape,dtype=numpy.float128) # PRB: can we move this loop inside the factored_likelihood? It might help. i = 0 # choose an array at the target sampling rate. P is inherited globally for ph, th, phr, ic, ps, di in zip(right_ascension, declination, phi_orb, inclination, psi, distance): P.phi = ph # right ascension P.theta = th # declination P.tref = tref[i] #fiducial_epoch # see 'tvals', above P.phiref = phr # ref. orbital phase P.incl = ic # inclination P.psi = ps # polarization angle P.dist = di* 1.e6 * lal.PC_SI # luminosity distance lnL[i] = factored_likelihood.factored_log_likelihood_time_marginalized(tvals, P, rholms_intp, rholms, cross_termsU, cross_termsV, det_epochs, opts.l_max,interpolate=opts.interpolate_time) i+=1 import pdb pdb.set_trace() return numpy.exp(lnL)