Priors

Prior distributions for Bayesian inference.

socca.priors.uniform(low, high)[source]

Create a uniform prior distribution with validation.

Constructs a uniform distribution over the interval [low, high] with automatic validation that the lower bound is less than the upper bound.

Parameters:
  • low (float) – Lower bound of the uniform distribution.

  • high (float) – Upper bound of the uniform distribution.

Returns:

Uniform distribution object.

Return type:

numpyro.distributions.Uniform

Raises:

ValueError – If low >= high.

socca.priors.loguniform(low, high)[source]

Create a log-uniform prior distribution with validation.

Constructs a log-uniform distribution over the interval [low, high], where log(x) is uniformly distributed. Useful for parameters that span many orders of magnitude.

Parameters:
  • low (float) – Lower bound of the log-uniform distribution (must be positive).

  • high (float) – Upper bound of the log-uniform distribution.

Returns:

Log-uniform distribution object.

Return type:

numpyro.distributions.LogUniform

Raises:

ValueError – If low >= high.

socca.priors.normal(loc, scale)[source]

Create a normal (Gaussian) prior distribution.

Constructs a normal distribution with specified mean and standard deviation. Commonly used for parameters with expected values and uncertainties.

Parameters:
  • loc (float) – Mean (location parameter) of the normal distribution.

  • scale (float) – Standard deviation (scale parameter) of the normal distribution.

Returns:

Normal distribution object.

Return type:

numpyro.distributions.Normal

class socca.priors.SplitNormal(losig, hisig, validate_args=None)[source]

Bases: Distribution

Split Normal (two-piece normal) distribution centered at 0.

Parameters:
  • losig (scale for x < 0)

  • hisig (scale for x >= 0)

log_prob(x)[source]

Compute log probability density for split normal distribution.

Evaluates the log probability using different scales for positive and negative values, with proper normalization to ensure the distribution integrates to 1.

Parameters:

x (float or array_like) – Value(s) at which to evaluate the log probability.

Returns:

Log probability density at x.

Return type:

float or array_like

socca.priors.splitnormal(loc, losig, hisig)[source]

Create a split normal distribution centered at a specified location.

Constructs an asymmetric normal distribution with different standard deviations for values below and above the center. Useful for modeling parameters with asymmetric uncertainties.

Parameters:
  • loc (float) – Center (location) of the split normal distribution.

  • losig (float) – Standard deviation for values below the center (x < loc).

  • hisig (float) – Standard deviation for values above the center (x >= loc).

Returns:

Split normal distribution centered at loc.

Return type:

numpyro.distributions.TransformedDistribution

Notes

The distribution is constructed by applying an affine transformation to shift the base SplitNormal (centered at 0) to the desired location.

class socca.priors.LogPowerLaw(alpha, low, high, validate_args=None)[source]

Bases: Distribution

Power-law prior for a parameter sampled in log space.

If theta = log(R_e), this distribution has:

log_prob(theta) ∝ (alpha + 1) * theta

where the (alpha + 1) accounts for the Jacobian of the log transform, such that the implied prior on R_e is p(R_e) ∝ R_e^alpha.

Parameters:
  • alpha (float) – Power-law index in linear space. alpha = -1 : log-uniform (flat in log space) alpha = 0 : flat/uniform in linear space alpha = +1 : linear prior (favours large R_e)

  • low (float) – Lower bound in log space

  • high (float) – Upper bound in log space

log_prob(theta)[source]

Compute log probability density in log space.

Parameters:

theta (float or array_like) – Value(s) in log space at which to evaluate the log probability.

Returns:

Log probability density at theta.

Return type:

float or array_like

icdf(u)[source]

Compute the inverse CDF (quantile function) in log space.

Parameters:

u (float or array_like) – Uniform random variable(s) in [0, 1].

Returns:

Corresponding sample(s) in linear space.

Return type:

float or array_like

sample(key, sample_shape=())[source]

Draw random samples from the distribution.

Parameters:
  • key (jax.random.PRNGKey) – JAX random key.

  • sample_shape (tuple, optional) – Shape of the sample batch.

Returns:

Random samples in linear space.

Return type:

array_like

socca.priors.logpowerlaw(alpha, low, high)[source]

Create a power-law prior for a parameter sampled in log space.

Parameters:
  • alpha (float) – Power-law index in linear space.

  • low (float) – Lower bound in linear space (log-transformed internally).

  • high (float) – Upper bound in linear space (log-transformed internally).

Returns:

Power-law distribution in log space.

Return type:

LogPowerLaw

class socca.priors.PowerLaw(alpha, low, high, validate_args=None)[source]

Bases: Distribution

Power-law prior in linear space.

p(x) ∝ x^alpha for x in [low, high]

Parameters:
  • alpha (float) – Power-law index. alpha = 0 : flat/uniform alpha = +1 : linear (favours large values) alpha = -1 : log-uniform

  • low (float) – Lower bound in linear space

  • high (float) – Upper bound in linear space

log_prob(x)[source]

Compute log probability density in linear space.

Parameters:

x (float or array_like) – Value(s) at which to evaluate the log probability.

Returns:

Log probability density at x.

Return type:

float or array_like

icdf(u)[source]

Compute the inverse CDF (quantile function).

Parameters:

u (float or array_like) – Uniform random variable(s) in [0, 1].

Returns:

Corresponding sample(s) in linear space.

Return type:

float or array_like

sample(key, sample_shape=())[source]

Draw random samples from the distribution.

Parameters:
  • key (jax.random.PRNGKey) – JAX random key.

  • sample_shape (tuple, optional) – Shape of the sample batch.

Returns:

Random samples.

Return type:

array_like

socca.priors.powerlaw(alpha, low, high)[source]

Create a power-law prior distribution in linear space.

Parameters:
  • alpha (float) – Power-law index.

  • low (float) – Lower bound in linear space.

  • high (float) – Upper bound in linear space.

Returns:

Power-law distribution in linear space.

Return type:

PowerLaw

socca.priors.boundto(comp, var)[source]

Create a lambda function to bind a parameter to another component’s parameter.

Creates a functional relationship where one component’s parameter is constrained to equal another component’s parameter. Useful for tying parameters together across multiple model components.

Parameters:
  • comp (Component or str) – Component object or string representation of component whose parameter should be referenced. If string, it is evaluated.

  • var (str) – Name of the parameter variable to bind to.

Returns:

A lambda function that takes the bound parameter and returns its value.

Return type:

lambda function

Examples

Bind the x-coordinate of component2 to match component1’s x-coordinate: >>> comp2.xc = boundto(comp1, ‘xc’)

Notes

The binding is implemented by creating a lambda that takes the referenced parameter as input and returns it unchanged.

class socca.priors.pocomcPrior(dists, seed=0)[source]

Bases: object

Prior distribution adapter for pocoMC sampler.

Wraps numpyro distributions to provide the interface required by the pocoMC sampler, including log probability density, sampling, and bounds.

logpdf(x)[source]

Compute log probability density for the joint prior distribution.

Evaluates the sum of log probabilities across all parameter dimensions, assuming independence between parameters.

Parameters:

x (array_like, shape (n_samples, n_dims)) – Sample points at which to evaluate the log probability density.

Returns:

Log probability density for each sample.

Return type:

numpy.ndarray, shape (n_samples,)

rvs(size=1)[source]

Generate random samples from the prior distribution.

Draws independent samples from each parameter’s prior distribution and stacks them into a 2D array.

Parameters:

size (int, optional) – Number of samples to generate. Default is 1.

Returns:

Array of random samples, where each column corresponds to a parameter dimension.

Return type:

jax.numpy.ndarray, shape (size, n_dims)

Notes

Uses JAX’s PRNG system with automatic key splitting for reproducible random number generation.

property bounds

Get parameter bounds from prior distributions.

Returns:

Array of [lower, upper] bounds for each parameter.

Return type:

numpy.ndarray, shape (n_dims, 2)

property dim

Get number of parameter dimensions.

Returns:

Number of parameters in the prior distribution.

Return type:

int