Computes log-likelihood for clusters based on distance-based cohesion and repulsion.
More...
#include <Natarajan_likelihood.hpp>
|
| double | compute_cohesion (int point_index, int cluster_index, const Eigen::Ref< const Eigen::VectorXi > &cls_ass_k, int n_k) const |
| | Computes the cohesion component of the log-likelihood.
|
| double | compute_repulsion (int point_index, int cluster_index, const Eigen::Ref< const Eigen::VectorXi > &cls_ass_k, int n_k) const |
| | Computes the repulsion component of the log-likelihood.
|
|
| const double | lgamma_delta1 |
| | Precomputed lgamma(delta1) for cohesion.
|
| const double | log_beta_alpha |
| | Precomputed log(beta) * alpha - lgamma(alpha).
|
| const double | lgamma_delta2 |
| | Precomputed lgamma(delta2) for repulsion.
|
| const double | log_gamma_zeta |
| | Precomputed log(gamma) * zeta - lgamma(zeta).
|
| std::vector< double > | lgamma_zeta_mt_cache |
| | Cache for lgamma(zeta_mt) values.
|
| std::vector< double > | lgamma_alpha_mh_cache |
| | Cache for lgamma(alpha_mh) values.
|
| std::vector< double > | log_D_data |
| | Precomputed log distance matrix (flattened).
|
| const int | D_cols |
| | Number of columns in distance matrix.
|
|
| const Data & | data |
| | Reference to Data object with distances and allocations.
|
| const Params & | params |
| | Reference to model parameters.
|
Computes log-likelihood for clusters based on distance-based cohesion and repulsion.
This class handles the computation of log-likelihoods for clustering models that incorporate both cohesion (within-cluster similarity) and repulsion (between-cluster dissimilarity) components. It precomputes values for efficiency and provides methods to evaluate both cluster-level and point-level conditional log-likelihoods. reference: Natarajan et al. (2023) "Cohesion and Repulsion in Bayesian Distance Clustering"
◆ Natarajan_likelihood()
| Natarajan_likelihood::Natarajan_likelihood |
( |
const Data & | data, |
|
|
const Params & | param ) |
|
inline |
Constructs a Likelihood object with precomputation.
- Parameters
-
| data | Reference to Data object with distances and allocations |
| param | Reference to model parameters |
The constructor precomputes several values for computational efficiency:
- Log-gamma values for delta parameters
- Logarithmic combinations of hyperparameters
- Logarithm of the entire distance matrix
◆ cluster_loglikelihood() [1/2]
| double Natarajan_likelihood::cluster_loglikelihood |
( |
int | cluster_index | ) |
const |
|
finaloverridevirtual |
Computes the full log-likelihood for a cluster.
- Parameters
-
| cluster_index | Index of the cluster to evaluate |
- Returns
- Total log-likelihood (cohesion + repulsion)
This method computes both the within-cluster cohesion and the between-cluster repulsion contributions for the specified cluster.
Implements Likelihood.
◆ cluster_loglikelihood() [2/2]
| double Natarajan_likelihood::cluster_loglikelihood |
( |
int | cluster_index, |
|
|
const Eigen::Ref< const Eigen::VectorXi > & | cls_ass_k ) const |
|
finaloverridevirtual |
Computes the full log-likelihood for a cluster with given assignments.
- Parameters
-
| cluster_index | Index of the cluster to evaluate |
| cls_ass_k | Vector of point indices in the cluster |
- Returns
- Total log-likelihood (cohesion + repulsion)
This overload allows computing the likelihood with a custom set of cluster assignments without modifying the data structure.
Implements Likelihood.
◆ compute_cohesion()
| double Natarajan_likelihood::compute_cohesion |
( |
int | point_index, |
|
|
int | cluster_index, |
|
|
const Eigen::Ref< const Eigen::VectorXi > & | cls_ass_k, |
|
|
int | n_k ) const |
|
private |
Computes the cohesion component of the log-likelihood.
- Parameters
-
| point_index | Index of the point being evaluated |
| cluster_index | Index of the cluster |
| cls_ass_k | Vector of point indices in the cluster |
| n_k | Number of points in the cluster |
- Returns
- Cohesion log-likelihood contribution
◆ compute_repulsion()
| double Natarajan_likelihood::compute_repulsion |
( |
int | point_index, |
|
|
int | cluster_index, |
|
|
const Eigen::Ref< const Eigen::VectorXi > & | cls_ass_k, |
|
|
int | n_k ) const |
|
private |
Computes the repulsion component of the log-likelihood.
- Parameters
-
| point_index | Index of the point being evaluated |
| cluster_index | Index of the cluster |
| cls_ass_k | Vector of point indices in the cluster |
| n_k | Number of points in the cluster |
- Returns
- Repulsion log-likelihood contribution
◆ point_loglikelihood_cond()
| double Natarajan_likelihood::point_loglikelihood_cond |
( |
int | point_index, |
|
|
int | cluster_index ) const |
|
finaloverridevirtual |
Computes the conditional log-likelihood of a point given a cluster.
- Parameters
-
| point_index | Index of the point to evaluate |
| cluster_index | Index of the target cluster |
- Returns
- Conditional log-likelihood of assigning the point to the cluster
This method evaluates how well a point fits into a specific cluster, considering both its cohesion with points in that cluster and its repulsion from points in other clusters.
Implements Likelihood.
◆ D_cols
| const int Natarajan_likelihood::D_cols |
|
private |
Number of columns in distance matrix.
◆ lgamma_alpha_mh_cache
| std::vector<double> Natarajan_likelihood::lgamma_alpha_mh_cache |
|
private |
Cache for lgamma(alpha_mh) values.
◆ lgamma_delta1
| const double Natarajan_likelihood::lgamma_delta1 |
|
private |
Precomputed lgamma(delta1) for cohesion.
◆ lgamma_delta2
| const double Natarajan_likelihood::lgamma_delta2 |
|
private |
Precomputed lgamma(delta2) for repulsion.
◆ lgamma_zeta_mt_cache
| std::vector<double> Natarajan_likelihood::lgamma_zeta_mt_cache |
|
private |
Cache for lgamma(zeta_mt) values.
◆ log_beta_alpha
| const double Natarajan_likelihood::log_beta_alpha |
|
private |
Precomputed log(beta) * alpha - lgamma(alpha).
◆ log_D_data
| std::vector<double> Natarajan_likelihood::log_D_data |
|
private |
Precomputed log distance matrix (flattened).
◆ log_gamma_zeta
| const double Natarajan_likelihood::log_gamma_zeta |
|
private |
Precomputed log(gamma) * zeta - lgamma(zeta).
The documentation for this class was generated from the following files: