def detector_response_dCS(frequencies, chirpm, symmratio, spin1, spin2, Luminosity_Distance, theta, phi, iota, alpha_squared, bppe, NSflag, cosmology=cosmology.Planck15): mass1 = utilities.calculate_mass1(chirpm, symmratio) mass2 = utilities.calculate_mass2(chirpm, symmratio) template = dcsimr_detector_frame(mass1=mass1, mass2=mass2, spin1=spin1, spin2=spin2, collision_time=0, collision_phase=0, Luminosity_Distance=Luminosity_Distance, phase_mod=alpha_squared, cosmo_model=cosmology, NSflag=NSflag) frequencies = np.asarray(frequencies) amp, phase, hreal = template.calculate_waveform_vector(frequencies) h_complex = amp * (np.exp(-1j * phase)) Fplus = (1 / 2) * (1 + np.cos(theta)**2) * np.cos(2 * phi) Fcross = np.cos(theta) * np.sin(2 * phi) Q = (1 + np.cos(iota)**2) / 2 * Fplus + 1j * Fcross * np.cos(iota) template_detector_response = h_complex * Q return template_detector_response
def log_likelihood_detector_frame_SNR(Data, frequencies, noise, SNR, t_c, phi_c, chirpm, symmratio, spin1, spin2, alpha_squared, bppe, NSflag, detector, cosmology=cosmology.Planck15): mass1 = utilities.calculate_mass1(chirpm, symmratio) mass2 = utilities.calculate_mass2(chirpm, symmratio) DL = 100 * mpc model = dcsimr_detector_frame(mass1=mass1, mass2=mass2, spin1=spin1, spin2=spin2, collision_time=t_c, collision_phase=phi_c, Luminosity_Distance=DL, phase_mod=alpha_squared, cosmo_model=cosmology, NSflag=NSflag) #model = imrdf(mass1=mass1,mass2=mass2, spin1=spin1,spin2=spin2, collision_time=t_c,collision_phase=phi_c, # Luminosity_Distance=DL, cosmo_model=cosmology,NSflag=NSflag) frequencies = np.asarray(frequencies) model.fix_snr_series(snr_target=SNR, detector=detector, frequencies=frequencies) amp, phase, hreal = model.calculate_waveform_vector(frequencies) #h_complex = np.multiply(amp,np.add(np.cos(phase),-1j*np.sin(phase))) h_complex = amp * np.exp(-1j * phase) #noise_temp,noise_func, freq = model.populate_noise(detector=detector,int_scheme='quad') resid = np.subtract(Data, h_complex) #integrand_numerator = np.multiply(np.conjugate(Data), h_complex) + np.multiply(Data,np.conjugate( h_complex)) integrand_numerator = np.multiply(resid, np.conjugate(resid)) #noise_root =noise_func(frequencies) #noise = np.multiply(noise_root, noise_root) integrand = np.divide(integrand_numerator, noise) integral = np.real(simps(integrand, frequencies)) #integral = np.real(np.sum(integrand)) return -2 * integral
def log_likelihood_Full(Data, frequencies, A0, t_c, phi_c, chirpm, symmratio, chi_s, chi_a, beta, bppe, NSflag, N_detectors, detector, cosmology=cosmology.Planck15): DL = ((np.pi / 30)**(1 / 2) / A0) * chirpm**2 * (np.pi * chirpm)**(-7 / 6) Z = Distance(DL / mpc, unit=u.Mpc).compute_z(cosmology=cosmology) chirpme = chirpm / (1 + Z) mass1 = utilities.calculate_mass1(chirpme, symmratio) mass2 = utilities.calculate_mass2(chirpme, symmratio) chi1 = chi_s + chi_a chi2 = chi_s - chi_a model = modimrins(mass1=mass1, mass2=mass2, spin1=chi1, spin2=chi2, collision_time=t_c, collision_phase=phi_c, Luminosity_Distance=DL, phase_mod=beta, bppe=bppe, cosmo_model=cosmology, NSflag=NSflag, N_detectors=N_detectors) frequencies = np.asarray(frequencies) amp, phase, hreal = model.calculate_waveform_vector(frequencies) h_complex = np.multiply(amp, np.add(np.cos(phase), 1j * np.sin(phase))) noise_temp, noise_func, freq = model.populate_noise(detector=detector, int_scheme='quad') resid = np.subtract(Data, h_complex) #integrand_numerator = np.multiply(np.conjugate(Data), h_complex) + np.multiply(Data,np.conjugate( h_complex)) integrand_numerator = np.multiply(resid, np.conjugate(resid)) noise_root = noise_func(frequencies) noise = np.multiply(noise_root, noise_root) integrand = np.divide(integrand_numerator, noise) integral = np.real(simps(integrand, frequencies)) return -2 * integral
def log_likelihood(Data, frequencies, DL, t_c, phi_c, chirpm, symmratio, spin1, spin2, alpha_squared, bppe, NSflag, N_detectors, detector, cosmology=cosmology.Planck15): #Z = Distance(DL/mpc,unit=u.Mpc).compute_z(cosmology = cosmology) #chirpme = chirpm/(1+Z) mass1 = utilities.calculate_mass1(chirpm, symmratio) mass2 = utilities.calculate_mass2(chirpm, symmratio) model = dcsimr_detector_frame(mass1=mass1, mass2=mass2, spin1=spin1, spin2=spin2, collision_time=t_c, collision_phase=phi_c, Luminosity_Distance=DL, phase_mod=alpha_squared, cosmo_model=cosmology, NSflag=NSflag, N_detectors=N_detectors) frequencies = np.asarray(frequencies) amp, phase, hreal = model.calculate_waveform_vector(frequencies) #h_complex = np.multiply(amp,np.add(np.cos(phase),-1j*np.sin(phase))) h_complex = amp * np.exp(-1j * phase) noise_temp, noise_func, freq = model.populate_noise(detector=detector, int_scheme='quad') resid = np.subtract(Data, h_complex) #integrand_numerator = np.multiply(np.conjugate(Data), h_complex) + np.multiply(Data,np.conjugate( h_complex)) integrand_numerator = np.multiply(resid, np.conjugate(resid)) noise_root = noise_func(frequencies) noise = np.multiply(noise_root, noise_root) integrand = np.divide(integrand_numerator, noise) integral = np.real(simps(integrand, frequencies)) return -2 * integral
def log_likelihood_maximized_coal_ratio(Data, frequencies, noise, SNR, chirpm, symmratio, spin1, spin2, alpha_squared, bppe, NSflag, cosmology=cosmology.Planck15): deltaf = frequencies[1] - frequencies[0] #Construct template with random luminosity distance mass1 = utilities.calculate_mass1(chirpm, symmratio) mass2 = utilities.calculate_mass2(chirpm, symmratio) DL = 100 * mpc template = dcsimr_detector_frame(mass1=mass1, mass2=mass2, spin1=spin1, spin2=spin2, collision_time=0, collision_phase=0, Luminosity_Distance=DL, phase_mod=alpha_squared, cosmo_model=cosmology, NSflag=NSflag) #Construct preliminary waveform for template frequencies = np.asarray(frequencies) amp, phase, hreal = template.calculate_waveform_vector(frequencies) h_complex = amp * np.exp(-1j * phase) #construct noise model #noise_temp,noise_func, freq = template.populate_noise(detector=detector,int_scheme='quad') #noise_root =noise_func(frequencies) #noise = np.multiply(noise_root, noise_root) #Fix snr of template to match the data snr_template = np.sqrt(4 * simps(amp * amp / noise, frequencies).real) h_complex = SNR / snr_template * h_complex #Construct the inverse fourier transform of the inner product (D|h) g_tilde = 4 * np.divide(np.multiply(np.conjugate(Data), h_complex), noise) g = np.fft.ifft(g_tilde) #Maximize over tc and phic gmag = np.abs(g) #maxg = np.amax( gmag ).real*len(frequencies) maxg = np.amax(gmag).real * (deltaf * len(frequencies)) #Construct the SNR in the Riemann sum approximation - Noramlization factors were combined #with the normalization factors for the ifft #Note: tried to avoid this, but it seems mixing integration schemes causes issues # ie, using simps and sum interchangeably doesn't work. Need to use sum to normalize ifft #snr1sum = np.sum((4*(Data*np.conjugate(Data))/noise).real) #snr1 = np.sqrt(snr1sum*(frequencies[-1]-frequencies[0])/len(frequencies)) #Print out the maximal phi #maxgindex = np.argmax( gmag ) #maxgcompl = g[maxgindex] #print(np.arctan((maxgcompl).imag/(maxgcompl).real)) #Return the loglikelihood #return -SNR**2*(1-maxg/(snr1sum)) return -(0.5 * SNR**2 - maxg)
def log_likelihood_marginalized_coal(Data, frequencies, noise, SNR, chirpm, symmratio, spin1, spin2, alpha_squared, bppe, NSflag, cosmology=cosmology.Planck15): deltaf = frequencies[1] - frequencies[0] #Construct template with random luminosity distance mass1 = utilities.calculate_mass1(chirpm, symmratio) mass2 = utilities.calculate_mass2(chirpm, symmratio) DL = 100 * mpc template = dcsimr_detector_frame(mass1=mass1, mass2=mass2, spin1=spin1, spin2=spin2, collision_time=0, collision_phase=0, Luminosity_Distance=DL, phase_mod=alpha_squared, cosmo_model=cosmology, NSflag=NSflag) #Construct preliminary waveform for template frequencies = np.asarray(frequencies) amp, phase, hreal = template.calculate_waveform_vector(frequencies) h_complex = amp * np.exp(-1j * phase) #construct noise model #start=time() #noise_temp,noise_func, freq = template.populate_noise(detector=detector,int_scheme='quad') #noise_root =noise_func(frequencies) #noise = np.multiply(noise_root, noise_root) #print('noise time: ', time()-start) #Fix snr of template to match the data snr_template = np.sqrt(4 * simps(amp * amp / noise, frequencies).real) h_complex = SNR / snr_template * h_complex #Construct the inverse fourier transform of the inner product (D|h) #h_complex = np.insert(h_complex,0,np.conjugate(np.flip(h_complex))) #Data = np.insert(Data,0,np.conjugate(np.flip(Data))) #noise = np.insert(noise,0,np.conjugate(np.flip(noise))) #frequncies =np.insert(frequencies,0,-np.flip(frequencies)) g_tilde = np.divide(np.multiply(np.conjugate(Data), h_complex), noise) g = np.abs(np.fft.fft(g_tilde)) * 4 * deltaf #/len(frequencies) gmax = np.amax(g) sumg = np.sum(i0e(g) * np.exp(g - gmax)) * 1 / (len(frequencies) * deltaf) #print(sumg, gmax/SNR**2,np.log(sumg)) if sumg != np.inf: return np.log(sumg) + gmax - SNR**2 else: #print("inf") items = bi(g) sumg = np.sum(items) * 1 / (len(frequencies) * deltaf) return log(sumg) - SNR**2