Docs
Loading...
Searching...
No Matches
MALA Class Reference

Metropolis-Adjusted Langevin Algorithm (MALA) sampler for the latent variable U. More...

#include <MALA.hpp>

Inheritance diagram for MALA:
U_sampler

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
Paramsparams
 Reference to the parameters object containing NGGP parameters.
Datadata
 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).

Detailed Description

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:

  • U' = U + (ε²/2)∇log p(U|·) + ε*Z, where Z ~ N(0,1)

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).

See also
U_sampler

Constructor & Destructor Documentation

◆ MALA()

MALA::MALA ( Params & p,
Data & d,
bool use_V = false,
double eps = 1,
bool tuning = false )
inline

Constructor for MALA sampler.

Parameters
pReference to model parameters
dReference to observed data
use_VIf true, sample on V = log(U) scale instead of U scale (default: false)
epsInitial step size for Langevin dynamics (default: 1.0)
tuningIf true, enable Robbins-Monro adaptive tuning (default: false)

Member Function Documentation

◆ grad_log_conditional_density_U()

double MALA::grad_log_conditional_density_U ( double U) const
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)

Parameters
UThe current value of the latent variable U
Returns
The gradient value at U

◆ grad_log_conditional_density_V()

double MALA::grad_log_conditional_density_V ( double v) const
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

Parameters
vThe current value of V = log(U)
Returns
The gradient value at V

◆ Robbins_Monro_tuning()

void MALA::Robbins_Monro_tuning ( )
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:

  • δ = (accepted ? 1.0 : 0.0) - target_acc
  • c = 1.0 / (target_acc * (1 - target_acc))
  • t = total_iterations

Includes a restart mechanism to prevent epsilon from changing too rapidly (resets iteration counter if epsilon changes by more than factor of 3).

Note
Only active after BI_adapt initial iterations and when tuning_enabled is true
See also
Garthwaite et al. (2016), "Adaptive optimal scaling of Metropolis-Hastings algorithms using the Robbins-Monro process"

◆ sampling_U()

void MALA::sampling_U ( )
private

Samples U using MALA on the original U scale.

Implements the MALA proposal mechanism directly on U:

  • Proposes U' = U + (ε²/2)∇log p(U) + ε*Z
  • Computes acceptance ratio including asymmetric proposal densities
  • Accepts/rejects according to Metropolis-Hastings criterion

◆ sampling_V()

void MALA::sampling_V ( )
private

Samples U using MALA on the transformed V = log(U) scale.

Implements MALA on the log-transformed space for better numerical stability:

  • Proposes V' = V + (ε²/2)∇log p(V) + ε*Z
  • Transforms back to U scale: U' = exp(V')
  • Includes Jacobian correction in acceptance ratio
  • Useful when U is constrained to be positive and has large dynamic range

◆ update_U()

void MALA::update_U ( )
overridevirtual

Performs one MALA update step for the latent variable U.

Executes the following sequence:

  1. Increments iteration counter
  2. Performs MALA sampling (either on V or U scale based on use_V flag)
  3. Applies Robbins-Monro tuning if enabled
Note
Overrides the pure virtual function from U_sampler base class

Implements U_sampler.

Member Data Documentation

◆ accept

bool MALA::accept = false
private

Flag indicating whether the last proposal was accepted.

◆ BI_adapt

int MALA::BI_adapt = 5 / (0.574 * (1 - 0.574))
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.

◆ epsilon

double MALA::epsilon = 1.0
private

Step size parameter for the Langevin dynamics proposal.

◆ old_epsilon

double MALA::old_epsilon = 1.0
private

Previous value of epsilon, used for restart mechanism in adaptive tuning.

◆ tuning_enabled

bool MALA::tuning_enabled = false
private

Flag to enable/disable Robbins-Monro adaptive tuning of step size.

◆ use_V

bool MALA::use_V = false
private

Flag to use V = log(U) transformation instead of direct U sampling.


The documentation for this class was generated from the following files: