Skip to content

Update sources to be functions

Gregory Ashton requested to merge update-how-sources-are-defined into master

An idea inspired by discussion with @paul-lasky and @moritz.huebner.

Users should be able to input a function alone for the source and shouldn't have to worry about subclassing something. This enables this for the current implementation, and could easily be modified for the changes suggested in !13 (merged). Additionally I think it solves (my) issue with !13 (merged) - namely that user defined sources are subject to errors.

Key changes

  1. The Source class is replaced by a WaveformGenerator class

This is really just a more accurate name for what is currently implemented. As noted by Moritz, semantically the Source (i.e. a BBH) doesn't care about the frequencies or time-series it is computed at.

  1. The WaveformGenerator take a function source_model which returns the frequency-domain strain. It then does the introspection to work out what parameters the source_model needs and defaults them to None.

Currently, it still uses "the pass in the parameters" when calculating the frequency domain strain approach. But can easily be modified to fit with !13 (merged) . We can also add functions to set the values (if for example one wants to inject a signal).

Example

Here is psuedo-code example of how it will eventually work (the BasicTutorial.py currently does work but is missing some of the functionality described here).

def BBH(frequency_array, mass_1, mass_2, luminosity_distance, spin_1, spin_2,
        iota, phase, waveform_approximant, reference_frequency, ra, dec,
        geocent_time, psi):
 
    .... #The usual stuff using lalsim

    return {'plus': h_plus, 'cross': h_cross}


time_duration = 1.
sampling_frequency = 4096.
waveformgenerator = peyote.source.WaveformGenerator('BBH', sampling_frequency, time_duration, BBH)

# Inject a signal
waveformgenerator.set_parameters(mass_1=10, mass_2=5, ....) 
hf_signal = waveformgenerator.frequency_domain_strain(simulation_parameters)

# Simulate the data in H1
...
IFOs = [H1, L1]

likelihood = peyote.likelihood.likelihood(IFOs, waveformgenerator)

# Pass this likelihood and a prior to the sampler

Advantages

  1. Can satisfy !13 (merged)
  2. Easy for users to define their own models
  3. Instance variables (i.e. mass_1 etc) not required at initialisation, but explicitly set before using (either for an injection or inference).

TO DO

  • Add a default waveform generator (e.g. waveformgenerator = peyote.BBH)
  • If accepted, should source.py be renamed?
  • Figure out how to specify if it is a time-domain and frequency-domain and add the approach FFTing functions
  • Update to work with !13 (merged)

Thoughts?

@paul-lasky @moritz.huebner @colm.talbot @rory-smith

Edited by Gregory Ashton

Merge request reports