Priors#

multilightning is compatible with the priors defined in lightning.priors. However, the addition of multi-region fitting introduces the need for priors which connect parameters together between different models. multilightning implements three connections: Normal and Uniform connections, which assume the distance and absolute distance in the parameter values are normally and uniformly distributed, respectively; and a fixed connection, which pins the parameter to a reference value.

These are slightly hacked together, which you can tell by the weird way you initialize them. Each prior takes as arguments:

  • Its own parameters: \(\mu\) and \(\sigma\) for the normal connection, \(a\) and \(b\) for the uniform, nothing for the fixed connection.

  • The name of the region to target, as a string.

  • The index of the parameter to target.

Therefore NormalConnection([0.0, 1.0], 'disk', 0) assumes that the distance between the given parameter and the first parameter (i.e., the parameter at index 0) of the 'disk' component is drawn from the standard normal distribution.

Note

This construction actually means you can use these priors to link parameters within the same region: the above construction could be used to link the second piecewise-constant SFH coefficient in the disk component to the first, for example.

class multi_lightning.priors.NormalConnection#

Bases: AnalyticPrior

Treats the distance \(\delta x = x_1 - x_2\) as a Normal random variable with \(\delta x \sim N(\mu, \sigma)\)

Parameters:
paramsarray-like, (2,)

Mean and sigma of the normal distribution.

target_namestr

Name of region to target

param_idxint

Index of parameter in region model.

Methods

evaluate(x1, x2)

Calculate prior probability.

quantile(q)

Calculate quantile function:

sample(size[, rng, seed])

Sample from the prior.

__init__(params, target_name, param_idx)#
__new__(*args, **kwargs)#
evaluate(x1, x2)#

Calculate prior probability.

Returns an array with the same shape as x1 that is equal to

\[p = \frac{1}{\sigma \sqrt{2 \pi}} \exp[- (\delta x - \mu)^2 / \sigma^2)]\]

where

\[\delta x = x_1 - x_2\]
quantile(q)#

Calculate quantile function:

Return an array with the same shape as q that is equal to

\[\delta x = \mu + \sigma \sqrt{2} {\rm erfinv}(2 q - 1)\]

where

\[\delta x = x_1 - x_2\]
sample(size, rng=None, seed=None)#

Sample from the prior.

Parameters:
sizeint

Number of samples to draw

rngnumpy.random.Generator

Numpy object for random number generation; see numpy.random.default_rng()

seedint

Seed for random number generation. If you pass a pre-constructed generator this is ignored.

Returns:
samplesnumpy array

Random samples

class multi_lightning.priors.UniformConnection#

Bases: AnalyticPrior

Treats the absolute distance \(dx = |x_1 - x_2|\) as a Uniform random variable with dx ~ U(0, D_{max}), i.e., x2 can be at most Dmax from x1.

Parameters:
paramsarray-like, (2,)

Lower and upper bound of the uniform distribution.

target_namestr

Name of region to target

param_idxint

Index of parameter in region model.

Methods

evaluate(x1, x2)

Calculate prior probability.

quantile(q)

Calculate quantile function.

sample(size[, rng, seed])

Sample from the prior.

__init__(param, target_name, param_idx)#
__new__(*args, **kwargs)#
evaluate(x1, x2)#

Calculate prior probability.

Return an array with the same shape as x1 that’s equal to \(1 / D_{max}\) wherever \(dx\) is in \([a,b)\) and 0 elsewhere.

quantile(q)#

Calculate quantile function.

Return an array with the same shape as q that’s equal to \(q D_{max}\).

sample(size, rng=None, seed=None)#

Sample from the prior.

Parameters:
sizeint

Number of samples to draw

rngnumpy.random.Generator

Numpy object for random number generation; see numpy.random.default_rng()

seedint

Seed for random number generation. If you pass a pre-constructed generator this is ignored.

Returns:
samplesnumpy array

Random samples

class multi_lightning.priors.FixedConnection#

Dummy prior. We use this to hold a parameter value fixed to a parameter from another region.

Note that this prior doesn’t fully implement lightning.priors.AnalyticPrior and can’t be used to sample

Parameters:
target_namestr

Name of region to target

param_idxint

Index of parameter in region model.

Methods

evaluate(x1, x2)

Returns x1 == x2

__init__(target_name, param_idx)#
__new__(*args, **kwargs)#
evaluate(x1, x2)#

Returns x1 == x2