Docs
Loading...
Searching...
No Matches
U_sampler Class Referenceabstract

Abstract base class for MCMC sampling of the latent variable U. More...

#include <U_sampler.hpp>

Inheritance diagram for U_sampler:
MALA RWMH

Public Member Functions

 U_sampler (Params &p, Data &d)
 Constructor for the U_sampler class.
virtual void update_U ()=0
 Pure virtual method to update the latent variable U.
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.

Protected Member Functions

Conditional Density Functions

Methods for computing conditional densities of U and V = log(U).

These functions evaluate the (unnormalized) conditional density of the latent variable U given the current partition, which is required for MCMC acceptance probabilities in Metropolis-Hastings algorithms.

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

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.
Cached Constants

Pre-computed values for computational efficiency.

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

Abstract base class for MCMC sampling of the latent variable U.

This class provides the interface and common functionality for sampling the latent variable U in Normalized Generalized Gamma Process (NGGP) mixture models. The latent variable U appears in the conditional distribution of the partition and must be updated via MCMC methods.

Derived classes must implement the update_U() method using specific sampling algorithms such as Random Walk Metropolis-Hastings (RWMH) or Metropolis-Adjusted Langevin Algorithm (MALA).

Note
Reference: "Clustering blood donors via mixtures of product partition models with covariates" by Argiento et al., 2024

Constructor & Destructor Documentation

◆ U_sampler()

U_sampler::U_sampler ( Params & p,
Data & d )
inline

Constructor for the U_sampler class.

Initializes the sampler with references to the parameters and data objects. The latent variable U is initialized to 1.0.

Parameters
pReference to the parameters object containing NGGP parameters (a, sigma, tau).
dReference to the data object containing observations and cluster assignments.

◆ ~U_sampler()

virtual U_sampler::~U_sampler ( )
virtualdefault

Virtual destructor for the U_sampler class.

Member Function Documentation

◆ get_acceptance_rate()

double U_sampler::get_acceptance_rate ( ) const
inline

Getter for the acceptance rate of U updates.

Returns
The acceptance rate as a double.

◆ get_U()

double U_sampler::get_U ( ) const
inline

Getter for the current value of U.

Returns
The current value of the latent variable U.

◆ log_conditional_density_U()

double U_sampler::log_conditional_density_U ( double u) const
protected

Computes the log conditional density of U given the partition.

This method evaluates the unnormalized log conditional density of the latent variable U given the current partition π. The conditional density follows:

\‍[f_{U|\pi}(u) \propto u^{n-1} \cdot (u + \tau)^{-(n-\sigma|\pi|)}
\cdot \exp\left(-\frac{a}{\sigma}\left((u+\tau)^\sigma -
\tau^\sigma\right)\right) \‍]

where:

  • $n$ is the number of observations
  • $|\pi|$ is the number of clusters (K)
  • $\sigma, a, \tau$ are NGGP parameters

The log density is computed as the sum of three terms:

  1. $(n-1) \log(u)$
  2. $-(n - \sigma K) \log(u + \tau)$
  3. $-\frac{a}{\sigma}\left((u+\tau)^\sigma - \tau^\sigma\right)$
Parameters
uThe value of U at which to evaluate the density.
Returns
The log of the unnormalized conditional density.
Note
Reference: "Clustering blood donors via mixtures of product partition models with covariates" by Argiento et al., 2024
See also
log_conditional_density_V()

◆ log_conditional_density_V()

double U_sampler::log_conditional_density_V ( double v) const
protected

Computes the log conditional density of V = log(U) given the partition.

This method evaluates the unnormalized log conditional density of the transformed latent variable V = log(U) given the current partition π. The transformation uses the change-of-variables formula:

\‍[f_{V|\pi}(v) = f_{U|\pi}(e^v) \cdot \left|\frac{dU}{dV}\right|
= f_{U|\pi}(u) \cdot u
\‍]

Taking the logarithm:

\‍[\log f_{V|\pi}(v) = \log f_{U|\pi}(e^v) + \log(e^v) = \log f_{U|\pi}(u) + v
\‍]

This transformed density is useful for MCMC sampling on the log scale, which can improve numerical stability and sampling efficiency.

Parameters
vThe value of V = log(U) at which to evaluate the density.
Returns
The log of the unnormalized conditional density of V.
See also
log_conditional_density_U()

◆ update_U()

virtual void U_sampler::update_U ( )
pure virtual

Pure virtual method to update the latent variable U.

This method must be implemented by derived classes to perform MCMC updates of the latent variable U using specific sampling algorithms (e.g., Random Walk Metropolis-Hastings, MALA).

Implemented in MALA, and RWMH.

Member Data Documentation

◆ a_over_sigma

const double U_sampler::a_over_sigma = params.a / params.sigma
protected

Ratio a/sigma for efficient computation.

◆ accepted_U

int U_sampler::accepted_U = 0
protected

Counter of accepted U.

◆ data

Data& U_sampler::data
protected

Reference to the data object containing observations and cluster assignments.

◆ gen

std::mt19937 U_sampler::gen
mutableprotected

Mersenne Twister random number generator.

◆ n

const int U_sampler::n = data.get_n()
protected

Number of observations n.

◆ params

Params& U_sampler::params
protected

Reference to the parameters object containing NGGP parameters.

◆ rd

std::random_device U_sampler::rd
protected

Random device for seeding.

◆ tau_power_sigma

const double U_sampler::tau_power_sigma = std::pow(params.tau, params.sigma)
protected

Pre-computed tau^sigma for efficient computation.

◆ total_iterations

int U_sampler::total_iterations = 0
protected

Counter for total MCMC iterations performed.

◆ U

double U_sampler::U = 1.0
protected

Current value of the latent variable U (initialized to 1.0).


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