Docs
Loading...
Searching...
No Matches
Process Class Referenceabstract

Abstract base class for Bayesian nonparametric processes. More...

#include <Process.hpp>

Inheritance diagram for Process:
DP NGGP DPx NGGPx

Public Member Functions

 Process (Data &d, const Params &p)
 Constructor initializing process with data and parameters.
virtual double gibbs_prior_existing_cluster (int cls_idx, int obs_idx) const =0
 Compute prior probability for assigning observation to existing cluster.
virtual Eigen::VectorXd gibbs_prior_existing_clusters (int obs_idx) const =0
 Compute prior probabilities for assigning observation to all existing clusters.
virtual double gibbs_prior_new_cluster () const =0
 Compute prior probability for creating a new cluster.
virtual double gibbs_prior_new_cluster_obs (int obs_idx) const
 Compute prior probability for creating a new cluster for a specific observation.
virtual double prior_ratio_split (int ci, int cj) const =0
 Compute prior ratio for split move in split-merge algorithm.
virtual double prior_ratio_merge (int size_old_ci, int size_old_cj) const =0
 Compute prior ratio for merge move in split-merge algorithm.
virtual double prior_ratio_shuffle (int size_old_ci, int size_old_cj, int ci, int cj) const =0
 Compute prior ratio for shuffle move in split-merge algorithm.
void set_old_allocations (const Eigen::VectorXi &new_allocations)
 Store current allocations for potential rollback.
void set_old_cluster_members (const std::unordered_map< int, std::vector< int > > &new_cluster_members)
 Store current cluster members for potential rollback.
void set_old_K (int new_K)
 Store current number of clusters for potential rollback.
void restore_state ()
 Restores the cached state into the data object.
const Eigen::VectorXi & old_allocations_view () const
 Provides read-only access to the stored previous allocations.
void set_idx_i (int i)
 Set index of first observation in split-merge pair.
void set_idx_j (int j)
 Set index of second observation in split-merge pair.
virtual void update_params ()=0
 Update process parameters during MCMC sampling.
virtual ~Process ()
 Virtual destructor for proper cleanup of derived classes.

Protected Member Functions

const std::unordered_map< int, std::vector< int > > & old_cluster_members_view () const
 Provides read-only access to the stored previous cluster members.

Protected Attributes

Datadata
 Reference to the data object containing observations and allocations.
const Paramsparams
 Reference to the parameters object containing process hyperparameters.
Eigen::VectorXi old_allocations
 Storage for previous allocations to enable rollback in case of rejection or for computation requiring it.
std::unordered_map< int, std::vector< int > > old_cluster_members
 Storage for previous cluster members to enable rollback in case of rejection or for computation requiring it.
int old_K = 0
 Number of clusters associated with the stored previous state.
int idx_i
 Index of first observation involved in split-merge move.
int idx_j
 Index of second observation involved in split-merge move.
const double log_a = log(params.a)
 Precomputed logarithm of total mass parameter for efficiency.

Detailed Description

Abstract base class for Bayesian nonparametric processes.

This class provides the foundation for implementing different types of Bayesian nonparametric processes including Dirichlet Process (DP), Normalized Generalized Gamma Process (NGGP), and their weighted variants (DPW, NGGPW). It defines the interface for prior computations needed in both Gibbs sampling and split-merge MCMC algorithms.

The class handles:

  • Prior probability computations for existing and new clusters
  • Prior ratio calculations for split-merge moves
  • Parameter updates during MCMC sampling
  • State management for split-merge algorithms

Derived classes must implement the pure virtual methods to define their specific process characteristics (DP, NGGP, NGGPW, DPW).

See also
DP, NGGP, NGGPW, DPW

Constructor & Destructor Documentation

◆ Process()

Process::Process ( Data & d,
const Params & p )
inline

Constructor initializing process with data and parameters.

Parameters
dReference to Data object containing observations and current allocations
pReference to Params object containing process hyperparameters

Initializes the process and stores a copy of current allocations for potential rollback operations during split-merge moves.

◆ ~Process()

virtual Process::~Process ( )
inlinevirtual

Virtual destructor for proper cleanup of derived classes.

Member Function Documentation

◆ gibbs_prior_existing_cluster()

virtual double Process::gibbs_prior_existing_cluster ( int cls_idx,
int obs_idx ) const
pure virtual

Compute prior probability for assigning observation to existing cluster.

Parameters
cls_idxIndex of the existing cluster
obs_idxIndex of the observation to be assigned
Returns
Log prior probability of assignment to existing cluster

This method computes the prior component of the probability for assigning an observation to an existing cluster in Gibbs sampling. The exact computation depends on the specific process (DP, NGGP, etc.).

Implemented in DP, DPx, NGGP, and NGGPx.

◆ gibbs_prior_existing_clusters()

virtual Eigen::VectorXd Process::gibbs_prior_existing_clusters ( int obs_idx) const
pure virtual

Compute prior probabilities for assigning observation to all existing clusters.

Parameters
obs_idxIndex of the observation to be assigned
Returns
Vector of log prior probabilities for all existing clusters

This method computes the prior components of the probabilities for assigning an observation to each existing cluster in Gibbs sampling. The exact computation depends on the specific process (DP, NGGP, etc.). The returned vector has a length equal to the current number of clusters.

Implemented in DP, DPx, NGGP, and NGGPx.

◆ gibbs_prior_new_cluster()

virtual double Process::gibbs_prior_new_cluster ( ) const
pure virtual

Compute prior probability for creating a new cluster.

Returns
Log prior probability of creating a new cluster

This method computes the prior probability of assigning an observation to a new cluster in Gibbs sampling. The computation is process-specific.

Implemented in DP, DPx, NGGP, and NGGPx.

◆ gibbs_prior_new_cluster_obs()

virtual double Process::gibbs_prior_new_cluster_obs ( int obs_idx) const
inlinevirtual

Compute prior probability for creating a new cluster for a specific observation.

Parameters
obs_idxIndex of the observation being (re)assigned.
Returns
Log prior probability of assigning obs_idx to a new cluster.

Some models (e.g., PPMx covariate similarity) add an observation-dependent term to the "new cluster" option. By default, this falls back to the observation-agnostic prior returned by gibbs_prior_new_cluster().

Reimplemented in DPx, and NGGPx.

◆ old_allocations_view()

const Eigen::VectorXi & Process::old_allocations_view ( ) const
inlinenodiscard

Provides read-only access to the stored previous allocations.

Returns
Const reference to the vector of previous allocations.

◆ old_cluster_members_view()

const std::unordered_map< int, std::vector< int > > & Process::old_cluster_members_view ( ) const
inlinenodiscardprotected

Provides read-only access to the stored previous cluster members.

Returns
Const reference to the unordered map of previous cluster members.

◆ prior_ratio_merge()

virtual double Process::prior_ratio_merge ( int size_old_ci,
int size_old_cj ) const
pure virtual

Compute prior ratio for merge move in split-merge algorithm.

Parameters
size_old_ciSize of first cluster before merge
size_old_cjSize of second cluster before merge
Returns
Log prior ratio for the merge move

Computes the ratio of prior probabilities when merging two clusters into one cluster. Used in the acceptance probability of merge moves.

Implemented in DP, DPx, NGGP, and NGGPx.

◆ prior_ratio_shuffle()

virtual double Process::prior_ratio_shuffle ( int size_old_ci,
int size_old_cj,
int ci,
int cj ) const
pure virtual

Compute prior ratio for shuffle move in split-merge algorithm.

Parameters
size_old_ciSize of first cluster before shuffle
size_old_cjSize of second cluster before shuffle
ciIndex of first cluster after shuffle
cjIndex of second cluster after shuffle
Returns
Log prior ratio for the shuffle move

Computes the ratio of prior probabilities when redistributing observations between two existing clusters. Used in restricted Gibbs sampling.

Implemented in DP, DPx, NGGP, and NGGPx.

◆ prior_ratio_split()

virtual double Process::prior_ratio_split ( int ci,
int cj ) const
pure virtual

Compute prior ratio for split move in split-merge algorithm.

Parameters
ciIndex of first resulting cluster after split
cjIndex of second resulting cluster after split
Returns
Log prior ratio for the split move

Computes the ratio of prior probabilities when splitting a cluster into two clusters. Used in the acceptance probability of split moves.

Implemented in DP, DPx, NGGP, and NGGPx.

◆ restore_state()

void Process::restore_state ( )
inline

Restores the cached state into the data object.

◆ set_idx_i()

void Process::set_idx_i ( int i)
inline

Set index of first observation in split-merge pair.

Parameters
iIndex of first observation

◆ set_idx_j()

void Process::set_idx_j ( int j)
inline

Set index of second observation in split-merge pair.

Parameters
jIndex of second observation

◆ set_old_allocations()

void Process::set_old_allocations ( const Eigen::VectorXi & new_allocations)
inline

Store current allocations for potential rollback.

Parameters
new_allocationsCurrent allocation vector to store

Saves the current state of cluster allocations before attempting a split-merge move, enabling rollback if the move is rejected.

◆ set_old_cluster_members()

void Process::set_old_cluster_members ( const std::unordered_map< int, std::vector< int > > & new_cluster_members)
inline

Store current cluster members for potential rollback.

Parameters
new_cluster_membersCurrent cluster members map to store

Saves the current state of cluster members before attempting a split-merge move, enabling rollback if the move is rejected.

◆ set_old_K()

void Process::set_old_K ( int new_K)
inline

Store current number of clusters for potential rollback.

Parameters
new_KNumber of clusters to cache

◆ update_params()

virtual void Process::update_params ( )
pure virtual

Update process parameters during MCMC sampling.

This method allows derived classes to update their specific parameters during the MCMC chain. For example, some processes may need to sample hyperparameters or update auxiliary variables. Implementation is process-specific.

Implemented in DP, DPx, NGGP, and NGGPx.

Member Data Documentation

◆ data

Data& Process::data
protected

Reference to the data object containing observations and allocations.

◆ idx_i

int Process::idx_i
protected

Index of first observation involved in split-merge move.

◆ idx_j

int Process::idx_j
protected

Index of second observation involved in split-merge move.

◆ log_a

const double Process::log_a = log(params.a)
protected

Precomputed logarithm of total mass parameter for efficiency.

◆ old_allocations

Eigen::VectorXi Process::old_allocations
protected

Storage for previous allocations to enable rollback in case of rejection or for computation requiring it.

◆ old_cluster_members

std::unordered_map<int, std::vector<int> > Process::old_cluster_members
protected

Storage for previous cluster members to enable rollback in case of rejection or for computation requiring it.

◆ old_K

int Process::old_K = 0
protected

Number of clusters associated with the stored previous state.

◆ params

const Params& Process::params
protected

Reference to the parameters object containing process hyperparameters.


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