openmc.stats.Discrete

class openmc.stats.Discrete(x, p, bias=None)[source]

Distribution characterized by a probability mass function.

The Discrete distribution assigns probability values to discrete values of a random variable, rather than expressing the distribution as a continuous random variable.

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

  • p (Iterable of float) – Discrete probability for each value

  • bias (Iterable of float, optional) – Alternative discrete probabilities for biased sampling. Defaults to None for unbiased sampling.

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

  • p (numpy.ndarray) – Discrete probability for each value

  • support (set) – Values of the random variable over which the distribution is nonzero-valued

  • bias (numpy.ndarray or None) – Discrete probabilities for biased sampling

clip(tolerance: float = 1e-06, inplace: bool = False) Discrete[source]

Remove low-importance points from discrete distribution.

Given a probability mass function \(p(x)\) with \(\{x_1, x_2, x_3, \dots\}\) the possible values of the random variable with corresponding probabilities \(\{p_1, p_2, p_3, \dots\}\), this function will remove any low-importance points such that \(\sum_i x_i p_i\) is preserved to within some threshold.

For biased distributions, clipping should be performed before the bias probabilities are added.

Added in version 0.14.0.

Parameters:
  • tolerance (float) – Maximum fraction of \(\sum_i x_i p_i\) that will be discarded.

  • inplace (bool) – Whether to modify the current object in-place or return a new one.

Return type:

Discrete distribution with low-importance points removed

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 discrete distribution from an XML element

Parameters:

elem (lxml.etree._Element) – XML element

Returns:

Discrete distribution generated from XML element

Return type:

openmc.stats.Discrete

integral()[source]

Return integral of distribution

Added in version 0.13.1.

Returns:

Integral of discrete distribution

Return type:

float

mean() float[source]

Return mean of the discrete distribution

The mean is the weighted average of the discrete values.

Added in version 0.15.3.

Returns:

Mean of discrete distribution

Return type:

float

classmethod merge(dists: Sequence[Discrete], probs: Sequence[float])[source]

Merge multiple discrete distributions into a single distribution

Added in version 0.13.1.

Parameters:
  • dists (iterable of openmc.stats.Discrete) – Discrete distributions to combine

  • probs (iterable of float) – Probability of each distribution

Returns:

Combined discrete distribution

Return type:

openmc.stats.Discrete

normalize()[source]

Normalize the probabilities stored on the distribution

sample(n_samples=1, seed=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)[source]

Return XML representation of the discrete distribution

Parameters:

element_name (str) – XML element name

Returns:

element – XML element containing discrete distribution data

Return type:

lxml.etree._Element