biogeme.latent_variables.positive_parameter_factory module¶
Factory utilities for strictly positive parameters.
This module provides a generic mechanism to define positive model parameters in a way that is compatible with both maximum likelihood and Bayesian estimation.
In a maximum likelihood context, positivity is typically enforced by estimating the logarithm of the parameter and exponentiating it. This avoids explicit constraints and generally improves numerical stability.
In a Bayesian context, it is often preferable to work directly with the parameter itself and impose positivity through a lower bound set to a small positive value. This leads to more interpretable posterior draws and avoids artificial symmetry in the parameter space.
The use of factories abstracts away these implementation details: components that rely on positive parameters do not need to know whether a log-transformed or directly constrained representation is used.
- class biogeme.latent_variables.positive_parameter_factory.PositiveParameterFactory(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for factories creating strictly positive model parameters.
Implementations return a Biogeme
Expressionrepresenting a parameter constrained to be strictly positive.
- class biogeme.latent_variables.positive_parameter_factory.SigmaFactory(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for factories creating strictly positive sigma (scale) parameters.
- biogeme.latent_variables.positive_parameter_factory.make_positive_parameter_factory(*, use_log)[source]¶
Create a factory for strictly positive parameters.
Two parameterizations are supported:
If
use_logis True, the returned factory creates an unconstrained parameter in log-space (named"<prefix>_<name>_log") and returns its exponential. This is typically used for maximum-likelihood estimation.If
use_logis False, the returned factory creates a directly constrained parameter (named"<prefix>_<name>") with a lower bound set toSMALL_POSITIVE. This is typically used for Bayesian estimation.
- Parameters:
use_log (
bool) – If True, define parameters in log-space and exponentiate them.- Return type:
- Returns:
A callable factory compatible with
PositiveParameterFactory.
- biogeme.latent_variables.positive_parameter_factory.make_sigma_factory(*, use_log)[source]¶
Create a sigma factory (specialization of the positive-parameter factory).
The sigma factory creates a strictly positive scale parameter named
"<prefix>_sigma"(or"<prefix>_sigma_log"in log-space) using the same parameterization rules asmake_positive_parameter_factory().- Parameters:
use_log (
bool) – If True, define sigma in log-space and exponentiate it.- Return type:
- Returns:
A callable factory compatible with
SigmaFactory.