LALInference 4.1.9.1-eeff03c
lalinference_cpnest.py
Go to the documentation of this file.
1##python
2import sys
3import argparse
4from lalinference.wrapper import LALInferenceCBCWrapper
5import os.path
6
7if __name__=='__main__':
8 parser = argparse.ArgumentParser(description='Nested sampling for CBC analysis')
9 parser.add_argument('--nlive',type=int,default=1000)
10 parser.add_argument('--nthreads',type=int,default=1)
11 parser.add_argument('--verbose',action='store_true',default=False)
12 parser.add_argument('--outfile',required=True)
13 parser.add_argument('--plot',default=False,const=True,nargs='?')
14 parser.add_argument('--maxmcmc',default=5000,type=int)
15 parser.add_argument('--poolsize',default=500,type=int)
16 opts, args = parser.parse_known_args(sys.argv)
17
18try:
19 import cpnest.model
20except ImportError as exc:
21 if not "cpnest" in str(exc): # don't catch other errors
22 raise
23 exc.args = (
24 "failed to import cpnest, this is required to run {}, "
25 "please install it manually via `pip install cpnest`".format(
26 os.path.basename(__file__),
27 ),
28 )
29 raise
30
31class LIModel(cpnest.model.Model):
32 def __init__(self, *args, **kwargs):
33 super(LIModel, self).__init__()
35
36 self.names = self.limodel.sampling_params()
37 bounds_dict = self.limodel.prior_bounds()
38 self.bounds = [bounds_dict[p] for p in self.names]
39 print('Sampling in {0}'.format(self.names))
40 print('Bounds: {0}'.format(self.bounds))
41 def log_likelihood(self, x):
42 logl=self.limodel.log_likelihood(x)
43 return logl
44 def log_prior(self, x):
45 logp=self.limodel.log_prior(x)
46 return logp
47
48if __name__=='__main__':
49 print(args)
50 LIstate = LIModel(sys.argv)
51 nest=cpnest.CPNest(LIstate, nlive=opts.nlive, nthreads=opts.nthreads, verbose=opts.verbose, maxmcmc=opts.maxmcmc, poolsize=opts.poolsize)
52 nest.run()
53 if opts.plot:
54 nest.plot()
55
56
57#if __name__=='__main__':
58# main()
Class to wrap a LALInference CBC analysis state, and expose the likelihood and prior methods to pytho...
Definition: wrapper.py:117
def __init__(self, *args, **kwargs)