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

Computes log-likelihood for clusters based on distance-based cohesion and repulsion using summary statistics for the repulsion term. More...

#include <Natarajan_likelihood_summaryStats.hpp>

Inheritance diagram for Natarajan_likelihood_summaryStats:
Likelihood

Public Member Functions

 Natarajan_likelihood_summaryStats (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 clusters_loglikelihood (int c1, int c2) const override final
 Computes the joint log-likelihood for two clusters accounting for pairwise repulsion.
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.
double pairwise_repulsion (int cluster_1, int cluster_2) const
 Computes the pairwise repulsion between two clusters.
Public Member Functions inherited from Likelihood
 Likelihood (const Data &data)
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.
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.

Private Attributes

const Natarajan_params & params
 Reference to model parameters.
const utils_params & utils
 Reference to utility parameters.
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).
double lgamma_zeta_mt_cache
 Precomputed lgamma(zeta_mt) for repulsion.
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 and repulsion using summary statistics for the repulsion term.

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. The difference between this class and the original Natarajan_likelihood class is that this class uses summary statistics instead of the full distance matrix for the repulsion term. reference: Natarajan et al. (2023) "Cohesion and Repulsion in Bayesian Distance Clustering"

Constructor & Destructor Documentation

◆ Natarajan_likelihood_summaryStats()

Natarajan_likelihood_summaryStats::Natarajan_likelihood_summaryStats ( 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 Natarajan_likelihood_summaryStats::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 Natarajan_likelihood_summaryStats::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.

◆ clusters_loglikelihood()

double Natarajan_likelihood_summaryStats::clusters_loglikelihood ( int c1,
int c2 ) const
finaloverridevirtual

Computes the joint log-likelihood for two clusters accounting for pairwise repulsion.

Parameters
c1Index of first cluster
c2Index of second cluster
Returns
Joint log-likelihood of clusters c1 and c2

Reimplemented from Likelihood.

◆ compute_cohesion()

double Natarajan_likelihood_summaryStats::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

◆ compute_repulsion()

double Natarajan_likelihood_summaryStats::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_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
Repulsion log-likelihood contribution

◆ pairwise_repulsion()

double Natarajan_likelihood_summaryStats::pairwise_repulsion ( int cluster_1,
int cluster_2 ) const

Computes the pairwise repulsion between two clusters.

Parameters
cluster_1Index of first cluster
cluster_2Index of second cluster
Returns
Log repulsion contribution between cluster_1 and cluster_2

◆ point_loglikelihood_cond()

double Natarajan_likelihood_summaryStats::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 Natarajan_likelihood_summaryStats::D_cols
private

Number of columns in distance matrix.

◆ lgamma_alpha_mh_cache

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

Cache for lgamma(alpha_mh) values.

◆ lgamma_delta1

const double Natarajan_likelihood_summaryStats::lgamma_delta1
private

Precomputed lgamma(delta1) for cohesion.

◆ lgamma_delta2

const double Natarajan_likelihood_summaryStats::lgamma_delta2
private

Precomputed lgamma(delta2) for repulsion.

◆ lgamma_zeta_mt_cache

double Natarajan_likelihood_summaryStats::lgamma_zeta_mt_cache
private

Precomputed lgamma(zeta_mt) for repulsion.

◆ log_beta_alpha

const double Natarajan_likelihood_summaryStats::log_beta_alpha
private

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

◆ log_D_data

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

Precomputed log distance matrix (flattened).

◆ log_gamma_zeta

const double Natarajan_likelihood_summaryStats::log_gamma_zeta
private

Precomputed log(gamma) * zeta - lgamma(zeta).

◆ params

const Natarajan_params& Natarajan_likelihood_summaryStats::params
private

Reference to model parameters.

◆ utils

const utils_params& Natarajan_likelihood_summaryStats::utils
private

Reference to utility parameters.


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