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

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

#include <Natarajan_likelihood.hpp>

Inheritance diagram for Natarajan_likelihood:
Likelihood

Public Member Functions

 Natarajan_likelihood (const Data &data, const Params &param)
 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, const Params &param)
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 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.

Additional Inherited Members

Protected Attributes inherited from Likelihood
const Datadata
 Reference to Data object with distances and allocations.
const Paramsparams
 Reference to model parameters.

Detailed Description

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"

Constructor & Destructor Documentation

◆ Natarajan_likelihood()

Natarajan_likelihood::Natarajan_likelihood ( const Data & data,
const Params & param )
inline

Constructs a Likelihood object with precomputation.

Parameters
dataReference to Data object with distances and allocations
paramReference 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

Member Function Documentation

◆ cluster_loglikelihood() [1/2]

double Natarajan_likelihood::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::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 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_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::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

◆ 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_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::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: