nanograv / enterprise

ENTERPRISE (Enhanced Numerical Toolbox Enabling a Robust PulsaR Inference SuitE) is a pulsar timing analysis code, aimed at noise analysis, gravitational-wave searches, and timing model analysis.
https://enterprise.readthedocs.io
MIT License
65 stars 67 forks source link

Allow reuse of FourierBasisGP with different phase shifts provided as parameters #254

Closed vallis closed 3 years ago

vallis commented 3 years ago

Would speed up computation of background distributions (e.g., for optimal statistic). Seems straightforward using parameter-dependent bases and caching.

Hazboun6 commented 3 years ago

@vallis I've been thinking about this again since I can run sky scramble OS analyses on my laptop, but need a cluster to do the phase shift OS in a reasonable amount of time. Have you thought about this anymore? When you mention a parameter-dependent basis, are you thinking that a simple fix would just be to set the phase shift seed as a parameter?

The pertinent part of the code, starting here,

# Use seed to make a repeatable random phase
if pseed is not None:
    # Use the first toa to make a different seed for every pulsar
    seed = int(toas[0] / 17) + pseed
    np.random.seed(seed)

# add random phase shift to basis functions
ranphase = np.random.uniform(0.0, 2 * np.pi, nmodes) if pshift else np.zeros(nmodes)

sets a seed for that specific pulsar based on the seed given.

Just wanted to get this conversation started again before it is too late to be useful for our current analysis.

vallis commented 3 years ago

Hello @Hazboun6, thanks for reminding me about this. With my latest master (on github.com/vallis/enterprise) you should be able to give pseed to FourierBasisCommonGP as a Parameter instead of a value, e.g.,

    gc = gp_signals.FourierBasisCommonGP(prior, orf, pseed=parameter.Uniform(0,32768))

Then pta.params would include an extra parameter B1855+09_common_fourier_pseed that will set the seed for the basis, and that you will need the sampler to pass along to the likelihood with everything else. If you don't pass it you get no shifts, since pseed defaults to None for createfourierdesignmatrix_red.

Now if I could just get the code to lint I could make a PR and see if it passes tests, but maybe you can try it yourself already.

vallis commented 3 years ago

This is in the current master.