set_prior

sherpa.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.

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()
Set the prior function to use with a parameter.
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 the the nH parameter of the abs1 model component:

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

>>> set_prior(abs1.nH, lognorm)