autofit.LogUniformPrior#

class LogUniformPrior[source]#

Bases: Prior

A prior with a log base 10 uniform distribution, defined between a lower limit and upper limit.

The conversion of an input unit value, u, to a physical value, p, via the prior is as follows:

\[\]

For example for prior = LogUniformPrior(lower_limit=10.0, upper_limit=1000.0), an input prior.value_for(unit=0.5) is equal to 100.0.

[Rich describe how this is done via message]

Parameters:
  • lower_limit (float) – The lower limit of the log10 uniform distribution defining the prior.

  • upper_limit (float) – The upper limit of the log10 uniform distribution defining the prior.

Examples

prior = af.LogUniformPrior(lower_limit=0.0, upper_limit=2.0)

physical_value = prior.value_for(unit=0.2)

Methods

dict

Return a dictionary representation of this GaussianPrior instance, including mean and sigma.

for_class_and_attribute_name

Create a prior from the configuration for a given class and attribute.

from_dict

Returns a prior from a JSON representation.

gaussian_prior_model_for_arguments

Look up this prior in an arguments dict and return the mapped value.

has

Does this instance have an attribute which is of type cls?

instance_for_arguments

Look up this prior's value in an arguments dictionary.

log_normalisation

The constant -log(log(upper / lower)) dropped from log_prior_from_value (which returns -log(value)).

log_prior_from_value

Returns the log prior density at a physical value, used by Emcee / Zeus / MLE searches to form a log-posterior via log_likelihood + sum(log_priors).

make_indexes

name_of_class

A string name for the class, with the prior suffix removed.

new

Returns a copy of this prior with a new id assigned making it distinct

next_id

project

Project this prior given samples and log weights from a search.

random

A random value sampled from this prior

replacing_for_path

Create a new model replacing the value for a given path with a new value

tree_flatten

tree_unflatten

Create a prior from a flattened PyTree

unit_value_for

Compute the unit value between 0 and 1 for the physical value.

value_for

Returns a physical value from an input unit value according to the limits of the log10 uniform prior.

with_limits

Create a new log 10 uniform prior centred between two limits with sigma distance between this limits.

with_message

Return a copy of this prior with a different message (distribution).

Attributes

component_number

factor

A callable PDF used as a factor in factor graphs

identifier

label

limits

The (lower, upper) bounds of this prior.

lower_limit_strict

Whether the support excludes the corresponding limit itself, i.e. whether the bound is value > limit rather than value >= limit.

name

ndim

How many dimensions does this variable have?

parameter_string

A human-readable string summarizing this prior's parameters.

upper_limit_strict

tree_flatten()[source]#
classmethod with_limits(lower_limit, upper_limit)[source]#

Create a new log 10 uniform prior centred between two limits with sigma distance between this limits.

Note that these limits are not strict so exceptions will not be raised for values outside of the limits.

This function is typically used in prior passing, where the result of a model-fit are used to create new Gaussian priors centred on the previously estimated median PDF model.

Parameters:
  • lower_limit (float) – The lower limit of the new LogUniform prior.

  • upper_limit (float) – The upper limit of the new LogUniform Prior.

Return type:

A new LogUniform.

log_prior_from_value(value, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.12/site-packages/numpy/__init__.py'>)[source]#

Returns the log prior density at a physical value, used by Emcee / Zeus / MLE searches to form a log-posterior via log_likelihood + sum(log_priors).

For a log-uniform prior on [lower_limit, upper_limit] the density is p(x) = 1 / (x * log(upper_limit / lower_limit)), giving log p(x) = -log(x) - log(log(upper_limit / lower_limit)). The normalisation constant -log(log(upper_limit / lower_limit)) is dropped (it is irrelevant to posterior shape), matching the convention used by UniformPrior.log_prior_from_value which drops -log(b - a) to return 0.0.

Outside [lower_limit, upper_limit] the density is zero, so -inf is returned — on both the NumPy and JAX paths. This bound test is the only support enforcement in the search fitness path (see UniformPrior.log_prior_from_value and PyAutoFit#1489): for MCMC an out-of-box proposal becomes a rejected move. It also keeps the figure-of-merit finite where Emcee’s stretch move proposes a non-positive value: -log of a non-positive value is NaN, which would otherwise crash the search with ValueError: Probability function returned NaN. The “double where” pattern (a safe surrogate inside the log) ensures no log of a non-positive value is evaluated, avoiding NumPy ``RuntimeWarning``s.

Parameters:
  • value – The physical value of this prior’s corresponding parameter in a NonLinearSearch sample.

  • xp – Array-module to dispatch on (numpy or jax.numpy). Default numpy.

log_normalisation(xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.12/site-packages/numpy/__init__.py'>)[source]#

The constant -log(log(upper / lower)) dropped from log_prior_from_value (which returns -log(value)). See Prior.log_normalisation.

value_for(unit, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.12/site-packages/numpy/__init__.py'>)[source]#

Returns a physical value from an input unit value according to the limits of the log10 uniform prior.

Parameters:
  • unit – A unit value between 0 and 1.

  • xp – Array-module to dispatch on (numpy or jax.numpy). Default numpy. The NumPy path delegates to the message stack (scipy-backed); the JAX path uses the closed-form lower * (upper / lower) ** unit.

Returns:

The unit value mapped to a physical value according to the prior.

Return type:

value

Examples

prior = af.LogUniformPrior(lower_limit=0.0, upper_limit=2.0)

physical_value = prior.value_for(unit=0.2)

dict()[source]#

Return a dictionary representation of this GaussianPrior instance, including mean and sigma.

Return type:

Dictionary containing prior parameters.

property parameter_string: str#

A human-readable string summarizing this prior’s parameters.

Subclasses must implement this to return a description such as "mean = 0.0, sigma = 1.0" or "lower_limit = 0.0, upper_limit = 1.0".