From 6f13174f5fac59040a893f7cdaf78963dd51a4b6 Mon Sep 17 00:00:00 2001 From: Colm Talbot <colm.talbot@ligo.org> Date: Mon, 11 Jun 2018 14:26:59 +1000 Subject: [PATCH] update examples to use PriorSet --- examples/injection_examples/basic_tutorial.py | 15 ++++++--------- .../change_sampled_parameters.py | 12 ++++++++---- .../injection_examples/marginalized_likelihood.py | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/injection_examples/basic_tutorial.py b/examples/injection_examples/basic_tutorial.py index 00e8403b2..39a3d171b 100644 --- a/examples/injection_examples/basic_tutorial.py +++ b/examples/injection_examples/basic_tutorial.py @@ -45,21 +45,18 @@ IFOs = [tupak.gw.detector.get_interferometer_with_fake_noise_and_injection( sampling_frequency=sampling_frequency, outdir=outdir) for name in ['H1', 'L1']] # Set up prior, which is a dictionary -priors = dict() # By default we will sample all terms in the signal models. However, this will take a long time for the calculation, # so for this example we will set almost all of the priors to be equall to their injected values. This implies the # prior is a delta function at the true, injected value. In reality, the sampler implementation is smart enough to # not sample any parameter that has a delta-function prior. - -for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl','psi', 'ra', 'dec', 'geocent_time', 'phase']: - priors[key] = injection_parameters[key] - # The above list does *not* include mass_1, mass_2, iota and luminosity_distance, which means those are the parameters # that will be included in the sampler. If we do nothing, then the default priors get used. -priors['luminosity_distance'] = tupak.core.prior.create_default_prior(name='luminosity_distance') -priors['geocent_time'] = tupak.core.prior.Uniform(injection_parameters['geocent_time'] - 1, - injection_parameters['geocent_time'] + 1, - 'geocent_time') +priors = tupak.gw.prior.BBHPriorSet() +priors['geocent_time'] = tupak.core.prior.Uniform( + minimum=injection_parameters['geocent_time'] - 1, maximum=injection_parameters['geocent_time'] + 1, + name='geocent_time', latex_label='$t_c$') +for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'psi', 'ra', 'dec', 'geocent_time', 'phase']: + priors[key] = injection_parameters[key] # Initialise the likelihood by passing in the interferometer data (IFOs) and the waveoform generator likelihood = tupak.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator, diff --git a/examples/injection_examples/change_sampled_parameters.py b/examples/injection_examples/change_sampled_parameters.py index 5ef99386e..711e195c0 100644 --- a/examples/injection_examples/change_sampled_parameters.py +++ b/examples/injection_examples/change_sampled_parameters.py @@ -27,7 +27,7 @@ waveform_generator = tupak.gw.waveform_generator.WaveformGenerator( sampling_frequency=sampling_frequency, time_duration=time_duration, frequency_domain_source_model=tupak.gw.source.lal_binary_black_hole, parameter_conversion=tupak.gw.conversion.convert_to_lal_binary_black_hole_parameters, - non_standard_sampling_parameter_keys=['chirp_mass', 'mass_ratio', 'cos_iota'], + non_standard_sampling_parameter_keys=['chirp_mass', 'mass_ratio'], parameters=injection_parameters) hf_signal = waveform_generator.frequency_domain_strain() @@ -37,11 +37,15 @@ IFOs = [tupak.gw.detector.get_interferometer_with_fake_noise_and_injection( sampling_frequency=sampling_frequency, outdir=outdir) for name in ['H1', 'L1', 'V1']] # Set up prior -priors = dict() +priors = tupak.gw.prior.BBHPriorSet() +priors.pop('mass_1') +priors.pop('mass_2') +priors['chirp_mass'] = tupak.prior.Uniform(name='chirp_mass', latex_label='$m_c$', minimum=13, maximum=45) +priors['mass_ratio'] = tupak.prior.Uniform(name='mass_ratio', latex_label='$q$', minimum=0.1, maximum=1) # These parameters will not be sampled -for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'psi', 'ra', 'dec', 'geocent_time']: +for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'psi', 'ra', 'dec', 'geocent_time', 'phase']: priors[key] = injection_parameters[key] -priors['luminosity_distance'] = tupak.core.prior.create_default_prior(name='luminosity_distance') +print(priors) # Initialise GravitationalWaveTransient likelihood = tupak.gw.likelihood.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator) diff --git a/examples/injection_examples/marginalized_likelihood.py b/examples/injection_examples/marginalized_likelihood.py index c3c4f29ef..5ca2ed1b8 100644 --- a/examples/injection_examples/marginalized_likelihood.py +++ b/examples/injection_examples/marginalized_likelihood.py @@ -31,7 +31,7 @@ IFOs = [tupak.gw.detector.get_interferometer_with_fake_noise_and_injection( sampling_frequency=sampling_frequency, outdir=outdir) for name in ['H1', 'L1', 'V1']] # Set up prior -priors = dict() +priors = tupak.gw.prior.BBHPriorSet() # These parameters will not be sampled for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'iota', 'ra', 'dec', 'geocent_time']: priors[key] = injection_parameters[key] -- GitLab