|
Docs
|
Random Walk Metropolis-Hastings sampler for updating the latent variable U. More...
#include <RWMH.hpp>
Public Member Functions | |
| RWMH (Params &p, Data &d, bool use_V=false, double prop_sd=1, bool tuning=false) | |
| Constructor for the RWMH sampler. | |
| void | update_U () override |
| Updates the latent variable U using Random Walk Metropolis-Hastings. | |
| 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 | |
| void | Robbins_Monro_tuning () |
| Performs Robbins-Monro adaptive tuning of the proposal standard deviation. | |
Sampling Methods | |
Private methods implementing RWMH updates on different scales. | |
| void | sampling_U () |
| Performs one RWMH update step for U on the original scale. | |
| void | sampling_V () |
| Performs one RWMH update step for V = log(U). | |
Private Attributes | |
| double | proposal_sd = 1.0 |
| Standard deviation for the Gaussian proposal distribution. | |
| bool | accept = false |
| Flag indicating whether the last proposal was accepted. | |
| bool | use_V = false |
| Flag to use V = log(U) scale for sampling instead of U directly. | |
| bool | tuning_enabled = false |
| Flag to enable/disable Robbins-Monro automatic tuning. | |
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). | |
Random Walk Metropolis-Hastings sampler for updating the latent variable U.
This class implements a Random Walk Metropolis-Hastings (RWMH) algorithm for sampling the latent variable U in NGGP mixture models. The sampler uses a Gaussian proposal distribution centered at the current value.
The sampler can operate on either:
The class also supports automatic tuning of the proposal standard deviation using the Robbins-Monro stochastic approximation algorithm to achieve an optimal acceptance rate of approximately 0.44 for one-dimensional proposals.
|
inline |
Constructor for the RWMH sampler.
Initializes the Random Walk Metropolis-Hastings sampler with specified configuration parameters.
| p | Reference to the parameters object containing NGGP parameters. |
| d | Reference to the data object containing observations and cluster assignments. |
| use_V | If true, perform sampling on V = log(U) scale; if false, sample U directly. |
| prop_sd | Initial standard deviation for the Gaussian proposal distribution (default: 1.0). |
| tuning | If true, enable Robbins-Monro adaptive tuning of proposal_sd (default: false). |
|
private |
Performs Robbins-Monro adaptive tuning of the proposal standard deviation.
Adjusts the proposal standard deviation to target an optimal acceptance rate of 0.44 for one-dimensional random walk proposals. The tuning follows the Robbins-Monro stochastic approximation scheme:
where:


(optimal for 1D random walk)
is the current iteration number
|
private |
Performs one RWMH update step for U on the original scale.
Proposes a new value from a truncated normal distribution:
The acceptance probability accounts for the asymmetric proposal due to truncation:
where
is the truncated normal proposal density.
|
private |
Performs one RWMH update step for V = log(U).
Proposes a new value from an unrestricted normal distribution:
The acceptance probability simplifies to:
|
overridevirtual |
Updates the latent variable U using Random Walk Metropolis-Hastings.
This method performs one iteration of the RWMH algorithm. It:
The choice between U and V scale affects the proposal distribution and acceptance probability calculation.
Implements U_sampler.
|
private |
Flag indicating whether the last proposal was accepted.
|
private |
Standard deviation for the Gaussian proposal distribution.
This parameter controls the step size of the random walk proposal. It can be automatically tuned using Robbins-Monro adaptation if enabled.
|
private |
Flag to enable/disable Robbins-Monro automatic tuning.
|
private |
Flag to use V = log(U) scale for sampling instead of U directly.