|
Docs
|
Metropolis-Adjusted Langevin Algorithm (MALA) sampler for the latent variable U. More...
#include <MALA.hpp>
Public Member Functions | |
| MALA (Params &p, Data &d, bool use_V=false, double eps=1, bool tuning=false) | |
| Constructor for MALA sampler. | |
| void | update_U () override |
| Performs one MALA update step for the latent variable U. | |
| Public Member Functions inherited from U_sampler | |
| U_sampler (Params &p, Data &d) | |
| Constructor for the U_sampler class. | |
| double | get_U () const |
| Getter for the current value of U. | |
| double | get_acceptance_rate () const |
| Getter for the acceptance rate of U updates. | |
| virtual | ~U_sampler ()=default |
| Virtual destructor for the U_sampler class. | |
Private Member Functions | |
| double | grad_log_conditional_density_U (double U) const |
| Computes the gradient of log conditional density with respect to U. | |
| double | grad_log_conditional_density_V (double v) const |
| Computes the gradient of log conditional density with respect to V = log(U). | |
| void | sampling_U () |
| Samples U using MALA on the original U scale. | |
| void | sampling_V () |
| Samples U using MALA on the transformed V = log(U) scale. | |
| void | Robbins_Monro_tuning () |
| Performs Robbins-Monro tuning of the proposal step size epsilon. | |
Private Attributes | |
| double | epsilon = 1.0 |
| Step size parameter for the Langevin dynamics proposal. | |
| double | old_epsilon = 1.0 |
| Previous value of epsilon, used for restart mechanism in adaptive tuning. | |
| bool | accept = false |
| Flag indicating whether the last proposal was accepted. | |
| bool | use_V = false |
| Flag to use V = log(U) transformation instead of direct U sampling. | |
| bool | tuning_enabled = false |
| Flag to enable/disable Robbins-Monro adaptive tuning of step size. | |
| int | BI_adapt = 5 / (0.574 * (1 - 0.574)) |
| Number of initial iterations before adaptive tuning begins. | |
Additional Inherited Members | |
| Protected Member Functions inherited from U_sampler | |
| double | log_conditional_density_U (double u) const |
| Computes the log conditional density of U given the partition. | |
| double | log_conditional_density_V (double v) const |
| Computes the log conditional density of V = log(U) given the partition. | |
| Protected Attributes inherited from U_sampler | |
| Params & | params |
| Reference to the parameters object containing NGGP parameters. | |
| Data & | data |
| Reference to the data object containing observations and cluster assignments. | |
| int | total_iterations = 0 |
| Counter for total MCMC iterations performed. | |
| int | accepted_U = 0 |
| Counter of accepted U. | |
| std::random_device | rd |
| Random device for seeding. | |
| std::mt19937 | gen |
| Mersenne Twister random number generator. | |
| const double | a_over_sigma = params.a / params.sigma |
| Ratio a/sigma for efficient computation. | |
| const double | tau_power_sigma = std::pow(params.tau, params.sigma) |
| Pre-computed tau^sigma for efficient computation. | |
| const int | n = data.get_n() |
| Number of observations n. | |
| double | U = 1.0 |
| Current value of the latent variable U (initialized to 1.0). | |
Metropolis-Adjusted Langevin Algorithm (MALA) sampler for the latent variable U.
This class implements the MALA algorithm, a gradient-based MCMC sampler that uses first-order derivative information to propose more informed moves in the parameter space. The algorithm can operate either on U directly or on V = log(U) for improved numerical stability.
MALA uses the following proposal mechanism:
The class supports adaptive tuning of the step size ε using the Robbins-Monro algorithm to achieve an optimal acceptance rate of approximately 0.574 (optimal for 1D problems).
Constructor for MALA sampler.
| p | Reference to model parameters |
| d | Reference to observed data |
| use_V | If true, sample on V = log(U) scale instead of U scale (default: false) |
| eps | Initial step size for Langevin dynamics (default: 1.0) |
| tuning | If true, enable Robbins-Monro adaptive tuning (default: false) |
|
private |
Computes the gradient of log conditional density with respect to U.
The gradient is given by: ∇_U log p(U|·) = (n-1)/U - (n - σK)/(U+τ) - a(U+τ)^(σ-1)
| U | The current value of the latent variable U |
|
private |
Computes the gradient of log conditional density with respect to V = log(U).
Uses the chain rule to transform the gradient from U to V scale: ∇_V log p(V|·) = ∇_U log p(U|·) * U + 1
| v | The current value of V = log(U) |
|
private |
Performs Robbins-Monro tuning of the proposal step size epsilon.
Adjusts epsilon to target an acceptance rate of 0.574 (optimal for 1D MALA), based on the Robbins-Monro stochastic approximation algorithm. The update rule is:
epsilon = exp(log(epsilon) + c * δ / t)
where:
Includes a restart mechanism to prevent epsilon from changing too rapidly (resets iteration counter if epsilon changes by more than factor of 3).
|
private |
|
private |
Samples U using MALA on the transformed V = log(U) scale.
Implements MALA on the log-transformed space for better numerical stability:
|
overridevirtual |
Performs one MALA update step for the latent variable U.
Executes the following sequence:
Implements U_sampler.
|
private |
Flag indicating whether the last proposal was accepted.
|
private |
Number of initial iterations before adaptive tuning begins.
Set to 5/(target_acc * (1 - target_acc)) ≈ 20.4 iterations. This allows some initial exploration before adaptation starts.
|
private |
Step size parameter for the Langevin dynamics proposal.
|
private |
Previous value of epsilon, used for restart mechanism in adaptive tuning.
|
private |
Flag to enable/disable Robbins-Monro adaptive tuning of step size.
|
private |
Flag to use V = log(U) transformation instead of direct U sampling.