set_prior

sherpa.astro.ui.set_prior(par, prior)

Set the prior function to use with a parameter.

The default prior used by get_draws for each parameter is flat, varying between the soft minimum and maximum values of the parameter (as given by the min and max attributes of the parameter object). The set_prior function is used to change the form of the prior for a parameter, and get_prior returns the current prior for a parameter.

Parameters
  • par (a sherpa.models.parameter.Parameter instance) – A parameter of a model instance.

  • prior (function or sherpa.models.model.Model instance) – The function to use for a prior. It must accept a single argument and return a value of the same size as the input.

See also

get_draws

Run the pyBLoCXS MCMC algorithm.

get_prior

Return the prior function for a parameter (MCMC).

set_sampler

Set the MCMC sampler.

Examples

Set the prior for the kT parameter of the therm component to be a gaussian, centered on 1.7 keV and with a FWHM of 0.35 keV:

>>> create_model_component('xsapec', 'therm')
>>> create_model_component('gauss1d', 'p_temp')
>>> p_temp.pos = 1.7
>>> p_temp.fwhm = 0.35
>>> set_prior(therm.kT, p_temp)

Create a function (lognorm) and use it as the prior of the nH parameter of the abs1 model component:

>>> def lognorm(x):
...     nh = 20
...     sigma = 0.5  # use a sigma of 0.5
...     # nH is in units of 10^-22 so convert
...     dx = np.log10(x) + 22 - nh
...     norm = sigma / np.sqrt(2 * np.pi)
...     return norm * np.exp(-0.5 * dx * dx / (sigma * sigma))
...
>>> create_model_component('xsphabs', 'abs1')
>>> set_prior(abs1.nH, lognorm)