autofit.UniformPrior#

class UniformPrior[source]#

Bases: Prior

A prior with a 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 = UniformPrior(lower_limit=0.0, upper_limit=2.0), an input prior.value_for(unit=0.5) is equal to 1.0.

[Rich describe how this is done via message]

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

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

Examples

prior = af.UniformPrior(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_prior_from_value

Returns the log prior of a physical value, so the log likelihood of a model evaluation can be converted to a posterior as log_prior + log_likelihood.

logpdf

Compute the log probability density at x.

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

Flatten this prior into a JAX-compatible PyTree representation.

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 uniform prior.

with_limits

Create a new UniformPrior with different bounds.

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_limit, upper_limit) bounds of this uniform prior.

name

ndim

How many dimensions does this variable have?

parameter_string

A human-readable string summarizing the prior's lower and upper limits.

width

The width of the uniform distribution (upper_limit - lower_limit).

tree_flatten()[source]#

Flatten this prior into a JAX-compatible PyTree representation.

Returns:

A (children, aux_data) pair where children are (lower_limit, upper_limit, id).

Return type:

tuple

property width#

The width of the uniform distribution (upper_limit - lower_limit).

with_limits(lower_limit, upper_limit)[source]#

Create a new UniformPrior with different bounds.

Parameters:
  • lower_limit (float) – The new lower bound.

  • upper_limit (float) – The new upper bound.

logpdf(x)[source]#

Compute the log probability density at x.

Adjusts boundary values by epsilon to avoid evaluating exactly at the distribution edges where the PDF is undefined.

Parameters:

x – The value at which to evaluate the log PDF.

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 the prior’s lower and upper limits.

value_for(unit, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautolens/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 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 preserves the historical float(round(..., 14)) snap (used as a hash key in model.priors); the JAX path uses the closed-form lower + (upper - lower) * unit so the trace stays symbolic.

Returns:

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

Return type:

value

Examples

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

physical_value = prior.value_for(unit=0.2)

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

Returns the log prior of a physical value, so the log likelihood of a model evaluation can be converted to a posterior as log_prior + log_likelihood.

This is used by certain non-linear searches (e.g. Emcee) in the log likelihood function evaluation.

For a UniformPrior this is always zero, provided the value is between the lower and upper limit.

property limits: Tuple[float, float]#

The (lower_limit, upper_limit) bounds of this uniform prior.