Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lalinference_cpnest.py
Go to the documentation of this file.
1##python
2import sys
3import argparse
4from lalinference.wrapper import LALInferenceCBCWrapper
5import os.path
6try:
7 import cpnest.model
8except ImportError as exc:
9 if not "cpnest" in str(exc): # don't catch other errors
10 raise
11 exc.args = (
12 "failed to import cpnest, this is required to run {}, "
13 "please install it manually via `pip install cpnest`".format(
14 os.path.basename(__file__),
15 ),
16 )
17 raise
18
19class LIModel(cpnest.model.Model):
20 def __init__(self, *args, **kwargs):
21 super(LIModel, self).__init__()
23
24 self.names = self.limodel.sampling_params()
25 bounds_dict = self.limodel.prior_bounds()
26 self.bounds = [bounds_dict[p] for p in self.names]
27 print('Sampling in {0}'.format(self.names))
28 print('Bounds: {0}'.format(self.bounds))
29 def log_likelihood(self, x):
30 logl=self.limodel.log_likelihood(x)
31 return logl
32 def log_prior(self, x):
33 logp=self.limodel.log_prior(x)
34 return logp
35
36if __name__=='__main__':
37 parser = argparse.ArgumentParser(description='Nested sampling for CBC analysis')
38 parser.add_argument('--nlive',type=int,default=1000)
39 parser.add_argument('--nthreads',type=int,default=1)
40 parser.add_argument('--verbose',action='store_true',default=False)
41 parser.add_argument('--outfile',required=True)
42 parser.add_argument('--plot',default=False,const=True,nargs='?')
43 parser.add_argument('--maxmcmc',default=5000,type=int)
44 parser.add_argument('--poolsize',default=500,type=int)
45 opts, args = parser.parse_known_args(sys.argv)
46 print(args)
47 LIstate = LIModel(sys.argv)
48 nest=cpnest.CPNest(LIstate, nlive=opts.nlive, nthreads=opts.nthreads, verbose=opts.verbose, maxmcmc=opts.maxmcmc, poolsize=opts.poolsize)
49 nest.run()
50 if opts.plot:
51 nest.plot()
52
53
54#if __name__=='__main__':
55# 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)