Coverage for pesummary/core/reweight.py: 100.0%

9 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1# Licensed under an MIT style license -- see LICENSE.md 

2 

3import numpy as np 

4from pesummary.utils.utils import logger 

5 

6__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"] 

7options = {} 

8 

9 

10def rejection_sampling(data, weights): 

11 """Reweight an input using rejection sampling 

12 

13 Parameters 

14 ---------- 

15 data: np.ndarray/pesummary.utils.samples_dict.SamplesDict 

16 posterior table you wish to reweight 

17 weights: np.ndarray 

18 a set of weights for each sample 

19 """ 

20 weights = np.asarray(weights) 

21 idx = weights > np.random.uniform(0, np.max(weights), len(weights)) 

22 logger.info( 

23 "Rejection sampling resulted in {} samples ({} input)".format( 

24 idx.sum(), len(idx) 

25 ) 

26 ) 

27 return data[idx]