|
Docs
|
Module for categorical covariate-related computations within clustering processes. More...
#include <categorical_covariate_module.hpp>
Public Member Functions | |
| CategoricalCovariatesModule (const Data &data_, const Eigen::VectorXi categorical_covariate, std::vector< double > prior_alpha_, const Eigen::VectorXi *old_alloc_provider=nullptr, const std::unordered_map< int, std::vector< int > > *old_cluster_members_provider_=nullptr) | |
| Constructor for CategoricalCovariatesModule. | |
Similarity Computation Methods | |
| double | compute_similarity_cls (int cls_idx, bool old_allo=false) const override __attribute__((hot)) |
| Compute covariate similarity contribution for a cluster. | |
| double | compute_similarity_obs (int obs_idx, int cls_idx) const override __attribute__((hot)) |
| Compute covariate similarity for a single observation in a cluster. | |
| Eigen::VectorXd | compute_similarity_obs (int obs_idx) const override __attribute__((hot)) |
| Compute covariate similarity contributions for all existing clusters. | |
| Public Member Functions inherited from Module | |
| Module (const Eigen::VectorXi *old_allocations_provider_=nullptr, const std::unordered_map< int, std::vector< int > > *old_cluster_members_provider_=nullptr) | |
| void | set_old_allocations_provider (const Eigen::VectorXi *provider) |
| void | set_old_cluster_members_provider (const std::unordered_map< int, std::vector< int > > *provider) |
| virtual | ~Module ()=default |
Protected Attributes | |
Module References | |
| const std::vector< double > | prior_alpha |
| const Data & | data |
| Reference to data object with cluster assignments. | |
| const Eigen::VectorXi | categorical_covariate_data |
Precomputed Values | |
| const double | alpha_0 = std::accumulate(prior_alpha.begin(), prior_alpha.end(), 0.0) |
| const double | lgamma_alpha_0 = std::lgamma(alpha_0) |
| double | prod_lgamma_prior = 0 |
| Protected Attributes inherited from Module | |
| const Eigen::VectorXi * | old_allocations_provider |
| Provider function for accessing old allocation state. | |
| const std::unordered_map< int, std::vector< int > > * | old_cluster_members_provider |
| Provider function for accessing old cluster members map. | |
Module for categorical covariate-related computations within clustering processes.
This class implements covariate-related computations for clustering processes where covariates are categorical ({1, ..., C}). It computes similarity measures based on the distribution of categorical covariates within clusters using a Dirichlet-Multinomial model.
alphas correspond to the concentration parameters for each category.
|
inline |
Constructor for CategoricalCovariatesModule.
| data_ | Reference to data object with cluster assignments |
| categorical_covariate | Categorical covariate values for observations |
| prior_alpha_ | Prior alpha parameters for Dirichlet-Multinomial model |
| old_alloc_provider | Optional pointer to previous allocation provider |
| old_cluster_members_provider_ | Optional pointer to previous cluster members provider |
|
overridevirtual |
Compute covariate similarity contribution for a cluster.
Computes the log marginal likelihood of the covariates within a cluster under the Dirichlet-Multinomial conjugate model. Higher values indicate that observations in the cluster have similar covariate values. ...
The computation follows Müller et al. (2011):
Implements Module.
|
overridevirtual |
Compute covariate similarity contributions for all existing clusters.
Computes the predictive contributions for adding observation obs_idx to each existing cluster, considering covariate values.
| obs_idx | Index of the observation |
Implements Module.
|
overridevirtual |
Compute covariate similarity for a single observation in a cluster.
Computes the predictive contribution when adding observation obs_idx to cluster cls_idx, considering the covariate values.
| obs_idx | Index of the observation |
| cls_idx | Index of the cluster |
Used in Gibbs sampling to compute the probability of assigning an observation to a cluster based on covariate similarity.
Implements Module.
|
protected |
Sum of prior alphas
|
protected |
Categorical covariate values for observations
|
protected |
Reference to data object with cluster assignments.
|
protected |
Log Gamma of sum of prior alphas
|
protected |
Prior alpha parameters for Dirichlet-Multinomial model
|
protected |
Sum of log Gamma of prior alphas