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

NGGP clustering process with module-based covariates. More...

#include <NGGPx.hpp>

Inheritance diagram for NGGPx:
NGGP Process

Public Member Functions

 NGGPx (Data &d, Params &p, U_sampler &U_sam, const std::vector< std::shared_ptr< Module > > &mods)
 Construct an NGGPWx process.
Gibbs Sampling Methods
double gibbs_prior_existing_cluster (int cls_idx, int obs_idx=0) const override
 Computes the log prior probability of assigning a data point to an existing cluster.
Eigen::VectorXd gibbs_prior_existing_clusters (int obs_idx) const override
 Computes the log prior for assigning an observation to each existing cluster.
double gibbs_prior_new_cluster () const override
 Computes the log prior probability of assigning a data point to a new cluster.
double gibbs_prior_new_cluster_obs (int obs_idx) const override
 Observation-specific new-cluster prior.
Split-Merge Algorithm Methods
double prior_ratio_split (int ci, int cj) const override
 Computes the prior ratio for a split operation in a spatially-aware NGGP-based split-merge MCMC algorithm.
double prior_ratio_merge (int size_old_ci, int size_old_cj) const override
 Computes the prior ratio for a merge operation in a spatially-aware NGGP-based split-merge MCMC algorithm.
double prior_ratio_shuffle (int size_old_ci, int size_old_cj, int ci, int cj) const override
 Computes the prior ratio for a shuffle operation in a spatially-aware NGGP-based split-merge MCMC algorithm.
Parameter Update Methods
void update_params () override
 Update process parameters.
Public Member Functions inherited from NGGP
 NGGP (Data &d, Params &p, U_sampler &mh)
 Constructor for the Normalized Generalized Gamma Process.
Public Member Functions inherited from Process
 Process (Data &d, const Params &p)
 Constructor initializing process with data and parameters.
void set_old_allocations (const Eigen::VectorXi &new_allocations)
 Store current allocations for potential rollback.
void set_old_cluster_members (const std::unordered_map< int, std::vector< int > > &new_cluster_members)
 Store current cluster members for potential rollback.
void set_old_K (int new_K)
 Store current number of clusters for potential rollback.
void restore_state ()
 Restores the cached state into the data object.
const Eigen::VectorXi & old_allocations_view () const
 Provides read-only access to the stored previous allocations.
void set_idx_i (int i)
 Set index of first observation in split-merge pair.
void set_idx_j (int j)
 Set index of second observation in split-merge pair.
virtual ~Process ()
 Virtual destructor for proper cleanup of derived classes.

Protected Attributes

std::vector< std::shared_ptr< Module > > modules
Protected Attributes inherited from NGGP
U_samplerU_sampler_method
 Reference to the U_sampler instance for updating the latent variable U.
std::random_device rd
 Random device for seeding.
std::mt19937 gen
 Mersenne Twister random number generator.
Protected Attributes inherited from Process
Datadata
 Reference to the data object containing observations and allocations.
const Paramsparams
 Reference to the parameters object containing process hyperparameters.
Eigen::VectorXi old_allocations
 Storage for previous allocations to enable rollback in case of rejection or for computation requiring it.
std::unordered_map< int, std::vector< int > > old_cluster_members
 Storage for previous cluster members to enable rollback in case of rejection or for computation requiring it.
int old_K = 0
 Number of clusters associated with the stored previous state.
int idx_i
 Index of first observation involved in split-merge move.
int idx_j
 Index of second observation involved in split-merge move.
const double log_a = log(params.a)
 Precomputed logarithm of total mass parameter for efficiency.

Additional Inherited Members

Protected Member Functions inherited from Process
const std::unordered_map< int, std::vector< int > > & old_cluster_members_view () const
 Provides read-only access to the stored previous cluster members.

Detailed Description

NGGP clustering process with module-based covariates.

This class extends the Normalized Generalized Gamma Process (NGGP) to incorporate module-based computations for covariates and other similarity terms. It augments Gibbs and split-merge moves with module contributions computed through the Module interface.

Constructor & Destructor Documentation

◆ NGGPx()

NGGPx::NGGPx ( Data & d,
Params & p,
U_sampler & U_sam,
const std::vector< std::shared_ptr< Module > > & mods )
inline

Construct an NGGPWx process.

Parameters
dData container.
pModel and sampler parameters.
U_samSampler for the latent NGGP auxiliary variable $U$.
modsVector of shared pointers to Module objects providing similarity computations.

Member Function Documentation

◆ gibbs_prior_existing_cluster()

double NGGPx::gibbs_prior_existing_cluster ( int cls_idx,
int obs_idx = 0 ) const
nodiscardoverridevirtual

Computes the log prior probability of assigning a data point to an existing cluster.

Combines the NGGP term for an existing cluster with spatial weighting and (when applicable in the implementation) covariate similarity contributions.

Parameters
cls_idxCluster index.
obs_idxObservation index (used for observation-specific spatial/covariate terms).
Returns
Log prior (up to an additive constant) for assigning observation obs_idx to existing cluster cls_idx.

Reimplemented from NGGP.

◆ gibbs_prior_existing_clusters()

Eigen::VectorXd NGGPx::gibbs_prior_existing_clusters ( int obs_idx) const
nodiscardoverridevirtual

Computes the log prior for assigning an observation to each existing cluster.

Parameters
obs_idxObservation index.
Returns
Vector of size $K$ containing log priors (up to an additive constant), one per existing cluster.

Reimplemented from NGGP.

◆ gibbs_prior_new_cluster()

double NGGPx::gibbs_prior_new_cluster ( ) const
nodiscardoverridevirtual

Computes the log prior probability of assigning a data point to a new cluster.

This is the baseline new-cluster mass from the NGGP model (without observation-specific covariate effects).

Returns
Log prior (up to an additive constant) for creating a new cluster.

Reimplemented from NGGP.

◆ gibbs_prior_new_cluster_obs()

double NGGPx::gibbs_prior_new_cluster_obs ( int obs_idx) const
nodiscardoverridevirtual

Observation-specific new-cluster prior.

Extends the baseline new-cluster prior by including the covariate singleton similarity contribution for observation obs_idx.

Parameters
obs_idxObservation index.
Returns
Log prior (up to an additive constant) for assigning observation obs_idx to a newly created cluster.

Reimplemented from Process.

◆ prior_ratio_merge()

double NGGPx::prior_ratio_merge ( int size_old_ci,
int size_old_cj ) const
nodiscardoverridevirtual

Computes the prior ratio for a merge operation in a spatially-aware NGGP-based split-merge MCMC algorithm.

Accounts for the NGGP prior and spatial/covariate contributions (as implemented by NGGPW and CovariatesModule).

Parameters
size_old_ciSize of the first cluster before the merge.
size_old_cjSize of the second cluster before the merge.
Returns
Log prior ratio contribution for the merge move.

Reimplemented from NGGP.

◆ prior_ratio_shuffle()

double NGGPx::prior_ratio_shuffle ( int size_old_ci,
int size_old_cj,
int ci,
int cj ) const
nodiscardoverridevirtual

Computes the prior ratio for a shuffle operation in a spatially-aware NGGP-based split-merge MCMC algorithm.

Accounts for the NGGP prior and spatial/covariate contributions (as implemented by NGGPW and CovariatesModule).

Parameters
size_old_ciSize of the first cluster before the shuffle.
size_old_cjSize of the second cluster before the shuffle.
ciIndex of the first cluster involved in the shuffle.
cjIndex of the second cluster involved in the shuffle.
Returns
Log prior ratio contribution for the shuffle move.

Reimplemented from NGGP.

◆ prior_ratio_split()

double NGGPx::prior_ratio_split ( int ci,
int cj ) const
nodiscardoverridevirtual

Computes the prior ratio for a split operation in a spatially-aware NGGP-based split-merge MCMC algorithm.

Accounts for the NGGP prior and spatial/covariate contributions (as implemented by NGGPW and CovariatesModule).

Parameters
ciIndex of the first (proposed) split cluster.
cjIndex of the second (proposed) split cluster.
Returns
Log prior ratio contribution for the split move.

Reimplemented from NGGP.

◆ update_params()

void NGGPx::update_params ( )
inlineoverridevirtual

Update process parameters.

Delegates to the configured U_sampler implementation to update the latent auxiliary variable $U$ conditional on the current partition.

See also
U_sampler::update_U()

Reimplemented from NGGP.

Member Data Documentation

◆ modules

std::vector<std::shared_ptr<Module> > NGGPx::modules
protected

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