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

Computes log-likelihood for clusters based on distance-based cohesion. More...

#include <Gamma_likelihood_distances.hpp>

Inheritance diagram for Gamma_likelihood_distances:
Likelihood

Public Member Functions

 Gamma_likelihood_distances (const Data &data, const Natarajan_params &params, const utils_params &utils)
 Constructs a Likelihood object with precomputation.
double cluster_loglikelihood (int cluster_index) const override final
 Computes the full log-likelihood for a cluster.
double cluster_loglikelihood (int cluster_index, const Eigen::Ref< const Eigen::VectorXi > &cls_ass_k) const override final __attribute__((hot))
 Computes the full log-likelihood for a cluster with given assignments.
double point_loglikelihood_cond (int point_index, int cluster_index) const override final __attribute__((hot))
 Computes the conditional log-likelihood of a point given a cluster.
Public Member Functions inherited from Likelihood
 Likelihood (const Data &data)
virtual double clusters_loglikelihood (int c1, int c2) const
 Computes the joint log-likelihood for two clusters.
virtual ~Likelihood ()=default

Private Member Functions

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.

Private Attributes

const Natarajan_params & params
const utils_params & utils
const double lgamma_delta1
 Precomputed lgamma(delta1) for cohesion.
const double log_beta_alpha
 Precomputed log(beta) * alpha - lgamma(alpha).
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.

Additional Inherited Members

Protected Attributes inherited from Likelihood
const Data & data
 Reference to Data object with distances and allocations.

Detailed Description

Computes log-likelihood for clusters based on distance-based cohesion.

This class handles the computation of log-likelihoods for clustering models that incorporate cohesion (within-cluster similarity) 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"

Constructor & Destructor Documentation

◆ Gamma_likelihood_distances()

Gamma_likelihood_distances::Gamma_likelihood_distances ( const Data & data,
const Natarajan_params & params,
const utils_params & utils )
inline

Constructs a Likelihood object with precomputation.

Parameters
dataReference to Data object with distances and allocations
paramsReference to model parameters
utilsReference to utils_params object with utility 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

Member Function Documentation

◆ cluster_loglikelihood() [1/2]

double Gamma_likelihood_distances::cluster_loglikelihood ( int cluster_index) const
finaloverridevirtual

Computes the full log-likelihood for a cluster.

Parameters
cluster_indexIndex 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 Gamma_likelihood_distances::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_indexIndex of the cluster to evaluate
cls_ass_kVector 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 Gamma_likelihood_distances::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_indexIndex of the point being evaluated
cluster_indexIndex of the cluster
cls_ass_kVector of point indices in the cluster
n_kNumber of points in the cluster
Returns
Cohesion log-likelihood contribution

◆ point_loglikelihood_cond()

double Gamma_likelihood_distances::point_loglikelihood_cond ( int point_index,
int cluster_index ) const
finaloverridevirtual

Computes the conditional log-likelihood of a point given a cluster.

Parameters
point_indexIndex of the point to evaluate
cluster_indexIndex 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.

Member Data Documentation

◆ D_cols

const int Gamma_likelihood_distances::D_cols
private

Number of columns in distance matrix.

◆ lgamma_alpha_mh_cache

std::vector<double> Gamma_likelihood_distances::lgamma_alpha_mh_cache
private

Cache for lgamma(alpha_mh) values.

◆ lgamma_delta1

const double Gamma_likelihood_distances::lgamma_delta1
private

Precomputed lgamma(delta1) for cohesion.

◆ log_beta_alpha

const double Gamma_likelihood_distances::log_beta_alpha
private

Precomputed log(beta) * alpha - lgamma(alpha).

◆ log_D_data

std::vector<double> Gamma_likelihood_distances::log_D_data
private

Precomputed log distance matrix (flattened).

◆ params

const Natarajan_params& Gamma_likelihood_distances::params
private

◆ utils

const utils_params& Gamma_likelihood_distances::utils
private

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