Likelihood
Instances of Likelihood
are called by worker sampling
processes for evaluation of a likelihood function.
- class xpsi.Likelihood.Likelihood(star, signals, num_energies=128, fast_rel_num_energies=0.25, threads=1, llzero=-1e+90, externally_updated=False, prior=None, max_energy=None)[source]
Bases:
ParameterSubspace
A container for all objects related to likelihood evaluation.
A collective for objects pertaining to a statistical analysis of X-ray signals. These objects include X-ray data (sub)sets, the model instruments used to acquire these data sets, and the model star and model backgrounds.
- Parameters:
star (obj) – An instance of
Star
. This instance is the model star.signals (list) –
Either:
num_energies (float) – Number of energies to compute specific photon flux signals at for likelihood evaluation. These energies will be distributed linearly in logarithmic space within the union of waveband coverages achieved by some set of instruments. Gaps in waveband coverage will be skipped.
fast_rel_num_energies (float) – Fraction of the normal number of energies to use in fast mode.
threads (int) – The number of
OpenMP
threads to spawn for integration. The default number of threads used by low-level integration routines is1
. The number can be increased if the parallelisation paradigm on a cluster is changed such that, e.g., per node there is one thread per CPU, instead of oneOpenMPI
process. It is recommended thatthreads
is1
; more threads are useful when performing integrals at high resolution, but not necessarily when integrating many times as when sampling, because the MPI parallelisation paradigm is invoked.llzero (float) – The minimum log-likelihood setting for MultiNest. Points whose log-likelihood is lower than this value are ignored, which is useful for defining complicated priors.
externally_updated (bool) – Update the parameter values upon call to the likelihood object? If so, then pass
False
. A parameter vector then needs to be passed to the likelihood object. Otherwise, safely assume that the new parameter values are set externally, e.g., in a prior object when inverse sampling the prior for nested sampling.prior (obj) – Instance of subclass of
Prior
.max_energy (float) – Optional maximum of energy set for signal computation. If no maximum is requested (the default), then the maximum is equal to the maximum energy from the loaded instrument response models.
- __call__(p=None, reinitialise=False, force=False)[source]
Evaluate the logarithm of the joint likelihood over all pulsations.
- Parameters:
p (list) – Parameter vector if parameters not updated externally.
reinitialise (optional[bool]) – Call
self.reinitialise()
?force (optional[bool]) – Force complete reevaluation even if some parameters are unchanged. To faciliate this, all parameter caches are cleared.
- Returns:
The logarithm of the likelihood.
- __str__()
Get a summary of the parameters constituting the subspace.
- check(hypercube_points, loglikelihood_call_vals, rtol_loglike, atol_loglike=0.0, logprior_call_vals=None, rtol_logprior=None, atol_logprior=None, physical_points=None, force_update=False, numpy_allclose=False)[source]
Perform checks on the likelihood evaluator and the prior density.
Can be called from
nested()
to execute a check before automatically commencing a sampling process.- Parameters:
hypercube_points (ndarray[n,m]) – A set of
n
points in the unit hypercube, wherem
is dimensionality (self.num_params
) of the sampling space – i.e., of the hypercube. If you want to pass the physical points instead, just passNone
here.physical_points (optional(ndarray[n,m])) – A set of
n
points in the physical parameter space, wherem
is dimensionality (self.num_params
) of the sampling space. Thehypercube_points
, if notNone
, will be ignored.force_update (optional[bool]) – Force everything to be re-calculated regardless of what was computed before. This can be used to prevent errors in cases when the automatic check for update need is not working as intended.
numpy_allclose (optional[bool]) – Determine whether the allclose function of numpy is used when evaluating the closeness of the given and calculated likelihood. By default, a fallback implementation is used, which also prints the likelihood values.
- property less_than_llzero
Get a number less than the minimum log-likelihood threshold.
- property llzero
Get the minimum log-likelihood setting passed to MultiNest.
- property random_near_llzero
Get the minimum log-likelihood scaled randomly by up to an order of magnitude.
- synthesise(p, reinitialise=False, force=False, **kwargs)[source]
Synthesise pulsation data.
- Parameters:
p (list) – Parameter vector.
reinitialise (optional[bool]) – Call
self.reinitialise()
?force (optional[bool]) – Force complete reevaluation even if some parameters are unchanged.
kwargs (dict) – Keyword arguments propagated to custom signal synthesis methods. Examples of such arguments include exposure times or required total count numbers (see example notebooks).
- property threads
Get the number of threads spawned for integration.