Coverage for bilby/gw/sampler/proposal.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-06 04:57 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-06 04:57 +0000
1import random
3import numpy as np
5from ...core.sampler.proposal import JumpProposal
8class SkyLocationWanderJump(JumpProposal):
9 """
10 Jump proposal for wandering over the sky location. Does a Gaussian step in
11 RA and DEC depending on the temperature.
12 """
14 def __call__(self, sample, **kwargs):
15 temperature = 1 / kwargs.get('inverse_temperature', 1.0)
16 sigma = np.sqrt(temperature) / 2 / np.pi
17 sample['ra'] += random.gauss(0, sigma)
18 sample['dec'] += random.gauss(0, sigma)
19 return super(SkyLocationWanderJump, self).__call__(sample)
22class CorrelatedPolarisationPhaseJump(JumpProposal):
23 """
24 Correlated polarisation/phase jump proposal. Jumps between degenerate phi/psi regions.
25 """
27 def __call__(self, sample, **kwargs):
28 alpha = sample['psi'] + sample['phase']
29 beta = sample['psi'] - sample['phase']
31 draw = random.random()
32 if draw < 0.5:
33 alpha = 3.0 * np.pi * random.random()
34 else:
35 beta = 3.0 * np.pi * random.random() - 2 * np.pi
36 sample['psi'] = (alpha + beta) * 0.5
37 sample['phase'] = (alpha - beta) * 0.5
38 return super(CorrelatedPolarisationPhaseJump, self).__call__(sample)
41class PolarisationPhaseJump(JumpProposal):
42 """
43 Correlated polarisation/phase jump proposal. Jumps between degenerate phi/psi regions.
44 """
46 def __call__(self, sample, **kwargs):
47 sample['phase'] += np.pi
48 sample['psi'] += np.pi / 2
49 return super(PolarisationPhaseJump, self).__call__(sample)