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

Dirichlet Process with module-based covariates for Bayesian nonparametric clustering. More...

#include <DPx.hpp>

Inheritance diagram for DPx:
DP Process

Public Member Functions

 DPx (Data &d, Params &p, const std::vector< std::shared_ptr< Module > > &mods)
 Constructor for the Dirichlet Process with modules.
void update_params () override
 Updates the module-based parameters.
Gibbs Sampling Methods
double gibbs_prior_existing_cluster (int cls_idx, int obs_idx) 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 probabilities of assigning a data point to every existing cluster. This method is useful for Gibbs sampling over existing clusters. It returns a vector of log prior probabilities for all existing clusters.
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 split-merge MCMC.
double prior_ratio_merge (int size_old_ci, int size_old_cj) const override
 Computes the prior ratio for a merge operation in split-merge MCMC.
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 split-merge MCMC.
Public Member Functions inherited from DP
 DP (Data &d, Params &p)
 Constructor for the Dirichlet 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 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

Dirichlet Process with module-based covariates for Bayesian nonparametric clustering.

This class extends the Dirichlet Process to incorporate covariates and other similarity components through a Module interface. It provides methods for Gibbs sampling and split-merge algorithms that account for module-based dependencies between observations.

Constructor & Destructor Documentation

◆ DPx()

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

Constructor for the Dirichlet Process with modules.

Parameters
dReference to the data object containing observations and cluster assignments.
pReference to the parameters object.
modsVector of shared pointers to Module objects providing similarity computations.

Member Function Documentation

◆ gibbs_prior_existing_cluster()

double DPx::gibbs_prior_existing_cluster ( int cls_idx,
int obs_idx ) const
nodiscardoverridevirtual

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

This method incorporates module-based similarity contributions when computing the prior probability.

Parameters
cls_idxThe index of the cluster.
obs_idxThe index of the observation to assign.
Returns
The log prior probability of assigning the data point to the existing cluster.

Reimplemented from DP.

◆ gibbs_prior_existing_clusters()

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

Computes the log prior probabilities of assigning a data point to every existing cluster. This method is useful for Gibbs sampling over existing clusters. It returns a vector of log prior probabilities for all existing clusters.

Parameters
obs_idxThe index of the observation to assign.
Returns
A vector of log prior probabilities for assigning the data point to each existing cluster.

Computes the log prior probabilities of assigning a data point to all existing clusters.

This method incorporates module-based similarity contributions to compute the prior probabilities. Modules can represent any type of similarity component (spatial, covariate-based, etc.).

Parameters
obs_idxThe index of the observation to assign.
Returns
A vector of log prior probabilities for assigning the data point to each existing cluster.

Reimplemented from DP.

◆ gibbs_prior_new_cluster()

double DPx::gibbs_prior_new_cluster ( ) const
nodiscardoverridevirtual

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

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

Reimplemented from DP.

◆ gibbs_prior_new_cluster_obs()

double DPx::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 DPx::prior_ratio_merge ( int size_old_ci,
int size_old_cj ) const
nodiscardoverridevirtual

Computes the prior ratio for a merge operation in split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for merging clusters.

Parameters
size_old_ciThe size of the first cluster before the merge.
size_old_cjThe size of the second cluster before the merge.
Returns
The log prior ratio for the merge operation.

Computes the prior ratio for a merge operation in split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for merging clusters.

Parameters
size_old_ciThe size of the first cluster before the merge.
size_old_cjThe size of the second cluster before the merge.
Returns
The log prior ratio for the merge operation.

Reimplemented from DP.

◆ prior_ratio_shuffle()

double DPx::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 split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for shuffling observations between clusters.

Parameters
size_old_ciThe size of the first cluster before the shuffle.
size_old_cjThe size of the second cluster before the shuffle.
ciThe first cluster index involved in the shuffle.
cjThe second cluster index involved in the shuffle.
Returns
The log prior ratio for the shuffle operation.

Computes the prior ratio for a shuffle operation in split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for shuffling observations between clusters.

Parameters
size_old_ciThe size of the first cluster before the shuffle.
size_old_cjThe size of the second cluster before the shuffle.
ciThe first cluster index involved in the shuffle.
cjThe second cluster index involved in the shuffle.
Returns
The log prior ratio for the shuffle operation.

Reimplemented from DP.

◆ prior_ratio_split()

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

Computes the prior ratio for a split operation in split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for splitting clusters.

Parameters
ciThe first cluster index involved in the split.
cjThe second cluster index involved in the split.
Returns
The log prior ratio for the split operation.

Computes the prior ratio for a split operation in split-merge MCMC.

This method accounts for both the Dirichlet Process prior and module-based similarity terms when computing the acceptance ratio for splitting clusters.

Parameters
ciThe first cluster index involved in the split.
cjThe second cluster index involved in the split.
Returns
The log prior ratio for the split operation.

Reimplemented from DP.

◆ update_params()

void DPx::update_params ( )
inlineoverridevirtual

Updates the module-based parameters.

This is a null implementation as DPx has no parameters to update beyond those handled by the base Process class.

Reimplemented from DP.

Member Data Documentation

◆ modules

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

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