HalfNormal#

class zfit.prior.HalfNormal(*, sigma, mu=0, name=None)[source]#

Bases: BasePrior

Half-normal prior distribution.

The Half-Normal prior is a normal distribution truncated at a lower bound (typically zero). It’s ideal for parameters that must be positive and where smaller values are more likely than larger ones. The distribution has its mode at the truncation point and decreases monotonically.

This prior is suitable for: - Standard deviations and scale parameters - Variance components in hierarchical models - Any positive parameter where smaller values are preferred - Error terms and measurement uncertainties

Example

>>> # Half-normal starting at 0 with scale 1
>>> prior = HalfNormal(sigma=1.0)
>>>
>>> # Half-normal starting at 2 with scale 0.5
>>> prior = HalfNormal(mu=2.0, sigma=0.5)

Initialize a Half-Normal prior.

Parameters:
  • sigma (float) – Scale parameter controlling the spread of the distribution. Must be positive. Required keyword-only parameter.

  • mu (float) – Location parameter (lower bound) where the distribution starts. Defaults to 0 for a standard half-normal.

  • name (str | None) – Optional name for the prior

__eq__(other)#

Compare two priors for equality.

Parameters:

other – Another ZfitPrior instance to compare with

Returns:

True if the priors are equal

Return type:

bool

__hash__()#

Return hash of the prior based on pdf and name.

Returns:

Hash value for the prior

Return type:

int

log_pdf(value=None)#

Return the log probability of the prior at the given value(s).

Parameters:

value – The parameter value(s) to evaluate the log probability at

Returns:

The log probability

sample(n)#

Sample n values from the prior distribution.

Parameters:

n – Number of samples to draw

Returns:

An array of samples