openmc.stats.Tabular

class openmc.stats.Tabular(x: Sequence[float], p: Sequence[float], interpolation: str = 'linear-linear', ignore_negative: bool = False, bias: Univariate | None = None)[source]

Piecewise continuous probability distribution.

This class is used to represent a probability distribution whose density function is tabulated at specific values with a specified interpolation scheme.

Parameters:
  • x (Iterable of float) – Tabulated values of the random variable

  • p (Iterable of float) – Tabulated probabilities. For histogram interpolation, if the length of p is the same as x, the last value is ignored. Probabilities p are given per unit of x.

  • interpolation ({'histogram', 'linear-linear', 'linear-log', 'log-linear', 'log-log'}, optional) – Indicates how the density function is interpolated between tabulated points. Defaults to ‘linear-linear’.

  • ignore_negative (bool) – Ignore negative probabilities

  • bias (openmc.stats.Univariate, optional) – Distribution for biased sampling.

Variables:
  • x (numpy.ndarray) – Tabulated values of the random variable

  • p (numpy.ndarray) – Tabulated probabilities

  • interpolation ({'histogram', 'linear-linear', 'linear-log', 'log-linear', 'log-log'}) – Indicates how the density function is interpolated between tabulated points. Defaults to ‘linear-linear’.

  • support (tuple of float) – A 2-tuple (lower, upper) defining the interval over which the distribution is nonzero-valued

  • bias (openmc.stats.Univariate or None) – Distribution for biased sampling

Notes

The probabilities p are interpreted per unit of the corresponding independent variable x. This follows the definition of a probability density function (PDF) in probability theory, where the PDF represents the relative likelihood of the random variable taking on a particular value per unit of the variable. For example, if x represents energy in eV, then p should represent probabilities per eV.

evaluate(x)[source]

Evaluate the probability density at the provided value.

Parameters:

x (float or sequence of float) – Location to evaluate p(x)

Returns:

Value of p(x)

Return type:

float or numpy.ndarray

classmethod from_xml_element(elem: Element)[source]

Generate tabular distribution from an XML element

Parameters:

elem (lxml.etree._Element) – XML element

Returns:

Tabular distribution generated from XML element

Return type:

openmc.stats.Tabular

integral()[source]

Return integral of distribution

Added in version 0.13.1.

Returns:

Integral of tabular distrbution

Return type:

float

mean()[source]

Compute the mean of the tabular distribution

normalize()[source]

Normalize the probabilities stored on the distribution

sample(n_samples: int = 1, seed: int | None = None)[source]

Sample the univariate distribution, handling biasing automatically.

Parameters:
  • n_samples (int) – Number of sampled values to generate

  • seed (int or None) – Initial random number seed.

Returns:

A tuple of (samples, weights)

Return type:

tuple of numpy.ndarray

property support

Return the support of the probability distribution.

Returns:

Returns the set of unique points assigned probability mass in a discrete distribution, the sampling interval for a continuous distribution, or a dictionary storing the discrete and continuous parts of the support of a mixed random variable

Return type:

set or tuple of float or dict

to_xml_element(element_name: str)[source]

Return XML representation of the tabular distribution

Parameters:

element_name (str) – XML element name

Returns:

element – XML element containing tabular distribution data

Return type:

lxml.etree._Element