def second_generation_mass_spin( dataset, alpha, beta, mmin, mmax, lam, mpp, sigpp, ): second_generation_mass = two_component_primary_mass_ratio( dataset=dataset, alpha=alpha, beta=beta * 4, mmin=mmin * 2, mmax=mmax * 2, lam=lam, mpp=mpp * 2, sigpp=sigpp * 2, ) alpha_2g, beta_2g, _ = mu_chi_var_chi_max_to_alpha_beta_max(mu_chi=0.67, var_chi=0.01, amax=1) second_generation_spin = iid_spin_magnitude_beta(dataset=dataset, alpha_chi=alpha_2g, beta_chi=beta_2g, amax=1) return second_generation_mass * second_generation_spin
def test_returns_zero_alpha_beta_less_zero(self): parameters = self.prior.sample() for key in ["alpha_chi", "beta_chi"]: parameters[key] = -1 self.assertEqual( spin.iid_spin_magnitude_beta(self.test_data, **parameters), 0 )
def test_spin_magnitude_normalised(self): norms = list() for ii in range(self.n_test): parameters = self.prior.sample() temp = spin.iid_spin_magnitude_beta(self.test_data, **parameters) norms.append(trapz(trapz(temp, self.a_array), self.a_array)) self.assertAlmostEqual(float(xp.max(xp.abs(1 - xp.asarray(norms)))), 0, 1)
def test_iid_matches_independent_magnitudes(self): iid_params = self.prior.sample() ind_params = dict() ind_params.update({key + '_1': iid_params[key] for key in iid_params}) ind_params.update({key + '_2': iid_params[key] for key in iid_params}) self.assertEquals(0.0, xp.max( spin.iid_spin_magnitude_beta(self.test_data, **iid_params) - spin.independent_spin_magnitude_beta( self.test_data, **ind_params)))
def test_iid_matches_independent(self): params = self.prior.sample() mag_params = {key: params[key] for key in ['amax', 'alpha_chi', 'beta_chi']} tilt_params = {key: params[key] for key in ['xi_spin', 'sigma_spin']} self.assertEquals(0.0, xp.max( spin.iid_spin(self.test_data, **params) - spin.iid_spin_magnitude_beta(self.test_data, **mag_params) * spin.iid_spin_orientation_gaussian_isotropic( self.test_data, **tilt_params)))
def generate_population_prior(population_params): params = DEFAULT_POPULATION_PARAMS.copy() params.update(population_params) p, _ = convert_to_beta_parameters(params) # make grid_x-vals num_x = 10000 mass = np.linspace(5, 100, num=num_x) q = np.linspace(0, 1, num=num_x) cos_vals = np.linspace(-1, 1, num=num_x) a = np.linspace(0, 1, num=num_x) z = np.linspace(0, 2.3, num=num_x) # calcualte probabilites mass_model = SinglePeakSmoothedMassDistribution() p_mass = mass_model.p_m1( dataset=pd.DataFrame(dict(mass_1=mass)), alpha=p["alpha"], mmin=p["mmin"], mmax=p["mmax"], lam=p["lam"], mpp=p["mpp"], sigpp=p["sigpp"], delta_m=p["delta_m"], ) p_q = mass_model.p_q( dataset=pd.DataFrame(dict(mass_ratio=q, mass_1=mass)), beta=p["beta"], mmin=p["mmin"], delta_m=p["delta_m"], ) p_costheta12 = truncnorm(xx=cos_vals, mu=1, sigma=p["sigma_12"], high=1, low=-1) p_costilt1 = truncnorm(xx=cos_vals, mu=1, sigma=p["sigma_1"], high=1, low=-1) p_a = iid_spin_magnitude_beta( dataset=pd.DataFrame(dict(a_1=a, a_2=a)), amax=p["amax"], alpha_chi=p["alpha_chi"], beta_chi=p["beta_chi"], ) p_z = PowerLawRedshift(z_max=2.3).probability(dataset=pd.DataFrame( dict(redshift=z)), lamb=p["lamb"]) # after generating prior, generate samples, then convert the samples to BBH params priors = bilby.prior.PriorDict( dict( a_1=Interped(a, p_a, minimum=0, maximum=1, name="a_1", latex_label="$a_1$"), a_2=Interped(a, p_a, minimum=0, maximum=1, name="a_2", latex_label="$a_2$"), redshift=Interped( z, p_z, minimum=0, maximum=2.3, name="redshift", latex_label="$pred_z$", ), cos_tilt_1=Interped( cos_vals, p_costilt1, minimum=-1, maximum=1, name="cos_tilt_1", latex_label="$\\cos\ \\mathrm{tilt}_1$", ), cos_theta_12=Interped( cos_vals, p_costheta12, minimum=-1, maximum=1, name="cos_theta_12", latex_label="$\\cos\ \\theta_{12}$", ), mass_1_source=Interped( mass, p_mass, minimum=5, maximum=100, name="mass_1_source", latex_label="$m_{1}$", ), mass_ratio=Interped( q, p_q, minimum=0, maximum=1, name="mass_ratio", latex_label="$q$", ), dec=Cosine(name="dec"), ra=Uniform(name="ra", minimum=0, maximum=2 * np.pi, boundary="periodic"), psi=Uniform(name="psi", minimum=0, maximum=np.pi, boundary="periodic"), phi_1=Uniform( name="phi_1", minimum=0, maximum=2 * np.pi, boundary="periodic", latex_label="$\\phi_1$", ), phi_12=Uniform( name="phi_z_s12", minimum=0, maximum=2 * np.pi, boundary="periodic", latex_label="$\\phi_{12}$", ), phase=Uniform(name="phase", minimum=0, maximum=2 * np.pi, boundary="periodic"), incl=Uniform(name="incl", minimum=0, maximum=2 * np.pi, boundary="periodic"), geocent_time=Uniform( minimum=-0.1, maximum=0.1, name="geocent_time", latex_label="$t_c$", unit="$s$", ), )) return priors