morphogen.distributions

Probability distributions of positive scalars (radii, lengths, weights…).

A distribution is given in configuration files either as a number (constant) or as a mapping with a type key:

radius: 1.0
radius: {type: uniform, low: 0.5, high: 1.5}
radius: {type: lognormal, mean: 1.0, std: 0.3}
radius: {type: normal, mean: 20.0, std: 13.5}      # truncated to positive values
radius: {type: discrete, values: [1.0, 2.0], weights: [0.7, 0.3]}

Unbounded distributions are truncated at their 1 - 1e-9 quantile so that every model can bound the extent of its grains (needed to generate unbiased samples).

morphogen.distributions.TAIL_QUANTILE = 0.999999999

Quantile at which unbounded distributions are truncated.

class morphogen.distributions.Distribution[source]

Bases: ABC

Distribution of a positive random variable.

abstractmethod sample(rng: Generator, n: int) → ndarray[source]

Draw n values.

abstractmethod moment(k: int) → float[source]

Raw moment E[X**k].

abstractmethod upper() → float[source]

Largest value that can be drawn.

abstractmethod quadrature(n: int = 128) → tuple[ndarray, ndarray][source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

abstractmethod to_config()[source]

Plain configuration value (number or mapping).

mean() → float[source]
std() → float[source]
median() → float[source]
property is_constant: bool
expect(f, n: int = 128) → float[source]

E[f(X)] for a vectorized function f.

class morphogen.distributions.Constant(value: 'float')[source]

Bases: Distribution

sample(rng, n)[source]

Draw n values.

moment(k)[source]

Raw moment E[X**k].

upper()[source]

Largest value that can be drawn.

quadrature(n=128)[source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

property is_constant
median()[source]
to_config()[source]

Plain configuration value (number or mapping).

class morphogen.distributions.Uniform(low: 'float', high: 'float')[source]

Bases: Distribution

sample(rng, n)[source]

Draw n values.

moment(k)[source]

Raw moment E[X**k].

upper()[source]

Largest value that can be drawn.

quadrature(n=128)[source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

to_config()[source]

Plain configuration value (number or mapping).

class morphogen.distributions.LogNormal(mean_value: float, std_value: float)[source]

Bases: Distribution

Log-normal distribution given by the mean and standard deviation of X itself.

property sigma: float
property mu: float
sample(rng, n)[source]

Draw n values.

moment(k)[source]

Raw moment E[X**k].

upper()[source]

Largest value that can be drawn.

quadrature(n=128)[source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

to_config()[source]

Plain configuration value (number or mapping).

class morphogen.distributions.TruncatedNormal(loc: float, scale: float, low: float = 0.0, high: float = inf)[source]

Bases: Distribution

Normal distribution N(mean, std) truncated to [low, high] (default: positive).

sample(rng, n)[source]

Draw n values.

moment(k)[source]

Raw moment E[X**k].

upper()[source]

Largest value that can be drawn.

quadrature(n=128)[source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

to_config()[source]

Plain configuration value (number or mapping).

class morphogen.distributions.Discrete(values: 'tuple[float, ...]', weights: 'tuple[float, ...]')[source]

Bases: Distribution

sample(rng, n)[source]

Draw n values.

moment(k)[source]

Raw moment E[X**k].

upper()[source]

Largest value that can be drawn.

quadrature(n=128)[source]

Nodes and weights approximating E[f(X)] by sum(w * f(x)).

to_config()[source]

Plain configuration value (number or mapping).

morphogen.distributions.distribution_from_config(value, name: str = 'distribution') → Distribution[source]

Build a distribution from a number or a mapping (see the module docstring).