cache.h

This file contains the cache structure, which optimizes MCMC inference for the HDP. This structure is specialized for various combinations of BaseDistribution and DataDistribution, and the specializations are also implemented in this file.

Classes, functions, and variables in this file
structcache
structcache< BaseDistribution, dense_categorical< V >, unsigned int, V, typename std::enable_if< is_dirichlet< BaseDistribution >::value >::type >
structcache< BaseDistribution, constant< K >, K, V >

## struct cache[view source]

template<typename BaseDistribution, typename DataDistribution, typename K, typename V>

This structure is used to provide optimizations for the Gibbs sampler in mcmc.h for specific combinations of BaseDistribution and DataDistribution. This struct is specialized for those particular combinations of base distribution and likelihood. These specializations are implemented further down in this file. Currently, a default implementation is unavailable.

Public members
cache (const sampler_root & h)
V **compute_root_probabilities (const hdp_sampler< BaseDistribution, DataDistribution, K, V > & h, const K & observation)
V **compute_root_probabilities (const hdp_sampler< BaseDistribution, DataDistribution, K, V > & h, const K * observations, unsigned int observation_count)
cache::cache(
 const sampler_root & h )

Constructs a cache structure for the HDP sampler hierarchy rooted at h.

V ** cache::compute_root_probabilities(
 const hdp_sampler< BaseDistribution, DataDistribution, K, V > & h, const K & observation )

Computes a matrix, where every row corresponds to a sample from the posterior, and every column is a table at the root node. Each element contains the probability of assigning the given observation to each table at the root (without taking into account table sizes and the alpha parameter).

V ** cache::compute_root_probabilities(
 const hdp_sampler< BaseDistribution, DataDistribution, K, V > & h, const K * observations, unsigned int observation_count )

Constructs a map from observations to a vector, of which each element is the probability of assigning that observation to each table at the root (without taking into account table sizes and the alpha parameter).

## struct cache< BaseDistribution, dense_categorical< V >, unsigned int, V, typename std::enable_if< is_dirichlet< BaseDistribution >::value >::type >[view source]

template<typename BaseDistribution, typename V>

A specialization of cache where the BaseDistribution satisfies is_dirichlet and the DataDistribution is dense_categorical.

Public members
cache (const sampler_root & h)
V **compute_root_probabilities (const sampler_root & h, const unsigned int & observation) const
V **compute_root_probabilities (sampler_root & h, const unsigned int * observations, unsigned int observation_count) const
cache< BaseDistribution, dense_categorical< V >, unsigned int, V, typename std::enable_if< is_dirichlet< BaseDistribution >::value >::type >::cache(
 const sampler_root & h )

Constructs a cache structure for the HDP sampler hierarchy rooted at h.

V ** cache< BaseDistribution, dense_categorical< V >, unsigned int, V, typename std::enable_if< is_dirichlet< BaseDistribution >::value >::type >::compute_root_probabilities(
 const sampler_root & h, const unsigned int & observation ) const

Computes a matrix, where every row corresponds to a sample from the posterior, and every column is a table at the root node. Each element contains the probability of assigning the given observation to each table at the root (without taking into account table sizes and the alpha parameter).

V ** cache< BaseDistribution, dense_categorical< V >, unsigned int, V, typename std::enable_if< is_dirichlet< BaseDistribution >::value >::type >::compute_root_probabilities(
 sampler_root & h, const unsigned int * observations, unsigned int observation_count ) const

Constructs a map from observations to a vector, of which each element is the probability of assigning that observation to each table at the root (without taking into account table sizes and the alpha parameter).

## struct cache< BaseDistribution, constant< K >, K, V >[view source]

template<typename BaseDistribution, typename K, typename V>

A specialization of cache where the DataDistribution is a constant (degenerate) distribution. There is no restriction on BaseDistribution.

Public members
cache (const sampler_root & h)
array< unsigned int > *compute_root_probabilities (const sampler_root & h, const K & observation)
array< unsigned int > *compute_root_probabilities (const sampler_root & h, const K * observations, unsigned int observation_count)
cache< BaseDistribution, constant< K >, K, V >::cache(
 const sampler_root & h )

Constructs a cache structure for the HDP sampler hierarchy rooted at h.

array< unsigned int > * cache< BaseDistribution, constant< K >, K, V >::compute_root_probabilities(
 const sampler_root & h, const K & observation )

Computes a matrix, where every row corresponds to a sample from the posterior, and every column is a table at the root node. Each element contains the probability of assigning the given observation to each table at the root (without taking into account table sizes and the alpha parameter).

array< unsigned int > * cache< BaseDistribution, constant< K >, K, V >::compute_root_probabilities(
 const sampler_root & h, const K * observations, unsigned int observation_count )

Constructs a map from observations to a vector, of which each element is the probability of assigning that observation to each table at the root (without taking into account table sizes and the alpha parameter).

This optimization exploits the fact that every table must have at most one distinct observation. In addition, probabilities in each vector are either 0 or 1. As a result, the matrix is zero except for the diagonal, and so we only return the diagonal.