bnmf-algs
Namespaces | Classes | Functions
bnmf_algs::details Namespace Reference

Namespace that contains types and functions for internal computations. More...

Namespaces

 bld_mult
 Namespace containing bld_mult update functions (CUDA/non-CUDA).
 
 online_EM
 Namespace containing online_EM algorithm related functions.
 

Classes

class  CollapsedGibbsComputer
 Computer type that will compute the next collapsed gibbs sample when its operator() is invoked. More...
 
class  SampleOnesNoReplaceComputer
 Computer type that will compute the next sample from a given matrix without replacement when its operator() is invoked. More...
 
class  SampleOnesReplaceComputer
 Computer type that will compute the next sample from a given matrix with replacement when its operator() is invoked. More...
 
class  TotalMarginalCalculator
 Class to compute total \(p(X|\Theta) = \sum_S p(X|S)p(S|\Theta)\) for all possible allocation tensors while storing shared state between function invocations. More...
 

Functions

template<typename T , typename Scalar >
double compute_first_term (const tensor_t< T, 3 > &S, const std::vector< Scalar > &alpha)
 Compute the first term of the sum when calculating log marginal of S. More...
 
template<typename T , typename Scalar >
double compute_second_term (const tensor_t< T, 3 > &S, const std::vector< Scalar > &beta)
 Compute the second term of the sum when calculating log marginal of S. More...
 
template<typename T , typename Scalar >
double compute_third_term (const tensor_t< T, 3 > &S, Scalar a, Scalar b)
 Compute the third term of the sum when calculating log marginal of S. More...
 
template<typename T >
double compute_fourth_term (const tensor_t< T, 3 > &S)
 Compute the fourth term of the sum when calculating log marginal of S. More...
 
template<typename T >
void update_X_hat (const matrix_t< T > &nu, const matrix_t< T > &mu, matrix_t< T > &X_hat)
 
template<typename T >
void update_orig_over_appr (const matrix_t< T > &X, const matrix_t< T > &X_hat, const matrix_t< T > &eps_mat, matrix_t< T > &orig_over_appr)
 
template<typename T >
void update_orig_over_appr_squared (const matrix_t< T > &X, const matrix_t< T > &X_hat, const matrix_t< T > &eps_mat, matrix_t< T > &orig_over_appr_squared)
 
template<typename T >
void update_S (const matrix_t< T > &orig_over_appr, const matrix_t< T > &nu, const matrix_t< T > &mu, tensor_t< T, 3 > &S)
 
template<typename T >
void update_alpha_eph (const vector_t< T > &alpha, const tensor_t< T, 3 > &S, matrix_t< T > &alpha_eph)
 
template<typename T >
void update_beta_eph (const vector_t< T > &beta, const tensor_t< T, 3 > &S, matrix_t< T > &beta_eph)
 
template<typename T >
void update_grad_plus (const matrix_t< T > &beta_eph, const tensor_t< T, 3 > &S, tensor_t< T, 3 > &grad_plus)
 
template<typename T >
void update_grad_minus (const matrix_t< T > &alpha_eph, matrix_t< T > &grad_minus)
 
template<typename T >
void update_nu (const matrix_t< T > &orig_over_appr, const matrix_t< T > &orig_over_appr_squared, const matrix_t< T > &mu, const tensor_t< T, 3 > &grad_plus, const matrix_t< T > &grad_minus, double eps, matrix_t< T > &nu)
 
template<typename T >
static void update_mu (const matrix_t< T > &orig_over_appr, const matrix_t< T > &orig_over_appr_squared, const matrix_t< T > &nu, const tensor_t< T, 3 > &grad_plus, const matrix_t< T > &grad_minus, double eps, matrix_t< T > &mu)
 
template<typename T , typename Scalar >
void check_bld_params (const matrix_t< T > &X, size_t z, const alloc_model::Params< Scalar > &model_params)
 Do parameter checks on BLD computing function parameters and throw an assertion error if the parameters are incorrect. More...
 
template<typename T , typename Scalar >
void check_EM_params (const matrix_t< T > &X, const std::vector< alloc_model::Params< Scalar >> &param_vec)
 Do parameter checks on EM algorithms for solving the BLD problem. More...
 
template<typename Real >
Real gsl_psi_wrapper (Real x)
 A template wrapper function around gsl_sf_psi. More...
 
template<typename T >
void check_sample_ones_params (const matrix_t< T > &X)
 
template<typename IntIterator >
void right_partition (IntIterator begin, IntIterator end, IntIterator all_begin, IntIterator all_end, std::vector< std::pair< size_t, size_t >> &change_indices)
 Partition the number stored at the beginning of the given sequence towards the end of the sequence by computing new partitions using exactly one increment and one decrement operations. More...
 
template<typename IntIterator >
void left_partition (IntIterator begin, IntIterator end, IntIterator all_begin, IntIterator all_end, std::vector< std::pair< size_t, size_t >> &change_indices)
 Partition the number stored at the end of the given sequence towards the beginning of the sequence by computing new partitions using exactly one increment and one decrement operations. More...
 

Detailed Description

Namespace that contains types and functions for internal computations.

Functions and classes in this namespace are not meant for direct usage by the users of bnmf-algs library; hence, behaviours of some functions may not be as expected. Additionally, some of these functions and types are not directly tested, and their behaviour is verified through correct behaviour of the API functions and types using them.

Function Documentation

template<typename T , typename Scalar >
void bnmf_algs::details::check_bld_params ( const matrix_t< T > &  X,
size_t  z,
const alloc_model::Params< Scalar > &  model_params 
)

Do parameter checks on BLD computing function parameters and throw an assertion error if the parameters are incorrect.

Template Parameters
TType of the matrix/tensor entries.
ScalarType of the scalars used as model parameters.
Remarks
Throws assertion error if the parameters are incorrect.
template<typename T , typename Scalar >
void bnmf_algs::details::check_EM_params ( const matrix_t< T > &  X,
const std::vector< alloc_model::Params< Scalar >> &  param_vec 
)

Do parameter checks on EM algorithms for solving the BLD problem.

Template Parameters
Ttype of the matrix entries.
ScalarType of the scalars used as model parameters.
Remarks
Throws assertion error if the parameters are incorrect.
template<typename T >
void bnmf_algs::details::check_sample_ones_params ( const matrix_t< T > &  X)
template<typename T , typename Scalar >
double bnmf_algs::details::compute_first_term ( const tensor_t< T, 3 > &  S,
const std::vector< Scalar > &  alpha 
)

Compute the first term of the sum when calculating log marginal of S.

Template Parameters
ScalarType of the model parameters.
TValue type of the tensor S.
Parameters
STensor S.
alphaParameter vector of Dirichlet prior for matrix \(W\) of size \(x\).
Returns
Value of the first term
template<typename T >
double bnmf_algs::details::compute_fourth_term ( const tensor_t< T, 3 > &  S)

Compute the fourth term of the sum when calculating log marginal of S.

Template Parameters
TValue type of tensor S.
Parameters
STensor S.
Returns
Value of the fourth term
template<typename T , typename Scalar >
double bnmf_algs::details::compute_second_term ( const tensor_t< T, 3 > &  S,
const std::vector< Scalar > &  beta 
)

Compute the second term of the sum when calculating log marginal of S.

Template Parameters
ScalarType of the model parameters.
TValue type of tensor S.
Parameters
STensor S.
betaParameter vector of Dirichlet prior for matrix \(H\) of size \(z\).
Returns
Value of the second term
template<typename T , typename Scalar >
double bnmf_algs::details::compute_third_term ( const tensor_t< T, 3 > &  S,
Scalar  a,
Scalar  b 
)

Compute the third term of the sum when calculating log marginal of S.

Template Parameters
ScalarType of the model parameters.
TValue type of tensor S.
Parameters
STensor S.
aShape parameter of Gamma distribution.
bRate parameter of Gamma distribution.
Returns
Value of the third term
template<typename Real >
Real bnmf_algs::details::gsl_psi_wrapper ( Real  x)

A template wrapper function around gsl_sf_psi.

gsl_sf_psi can only be called with double arguments. This function wraps gsl_sf_psi using static casts. Argument type is cast to double, gsl_sf_psi is called and the resulting double is cast back to argument type.

Template Parameters
RealType of the input.
Parameters
xInput.
Returns
Output of gsl_sf_psi with the same type as the parameter.
template<typename IntIterator >
void bnmf_algs::details::left_partition ( IntIterator  begin,
IntIterator  end,
IntIterator  all_begin,
IntIterator  all_end,
std::vector< std::pair< size_t, size_t >> &  change_indices 
)

Partition the number stored at the end of the given sequence towards the beginning of the sequence by computing new partitions using exactly one increment and one decrement operations.

This function partitions the number given at the end of the given sequence, *(end - 1) , towards the beginning, *begin . The indices of the values incremented/decremented to compute a new partition is pushed to the back of the given output vector, change_indices.

For n = *(end - 1) and k = end - begin , this function stores exactly \({n + k - 1}\choose{k - 1}\) different partitions between begin and end iterators. Increment/decrement indices of each partition is stored in the given output vector.

Template Parameters
IntegerInteger type to use.
Parameters
beginBeginning (leftmost iterator) of the sequence to store the partitions of the rightmost number.
endEnd (rightmost past one) of the sequence to store the partitions of the rightmost number. The number to partition must reside on the iterator before end.
all_beginBeginning of the whole sequence that stores complete partitions. This is the beginning iterator of the original vector that is modified to store various partitions of the original number.
all_endEnd of the whole sequence that stores complete partitions.
change_indicesOutput vector that stores increment/decrement index pairs to compute the next partition from previous one.
template<typename IntIterator >
void bnmf_algs::details::right_partition ( IntIterator  begin,
IntIterator  end,
IntIterator  all_begin,
IntIterator  all_end,
std::vector< std::pair< size_t, size_t >> &  change_indices 
)

Partition the number stored at the beginning of the given sequence towards the end of the sequence by computing new partitions using exactly one increment and one decrement operations.

This function partitions the number given at the beginning of the given sequence, *begin , towards the end, *(end - 1) . The indices of the values incremented/decremented to compute a new partition is pushed to the back of the given output vector, change_indices.

For n = *begin and k = end - begin , this function stores exactly \({n + k - 1}\choose{k - 1}\) different partitions between begin and end iterators. Increment/decrement indices of each partition is stored in the given output vector.

Template Parameters
IntegerInteger type to use.
Parameters
beginBeginning (leftmost iterator) of the sequence to store the partitions of the leftmost number. (*begin)
endEnd (rightmost past one) of the sequence to store the partitions of the rightmost number.
all_beginBeginning of the whole sequence that stores complete partitions. This is the beginning iterator of the original vector that is modified to store various partitions of the original number.
all_endEnd of the whole sequence that stores complete partitions.
change_indicesOutput vector that stores increment/decrement index pairs to compute the next partition from previous one.
template<typename T >
void bnmf_algs::details::update_alpha_eph ( const vector_t< T > &  alpha,
const tensor_t< T, 3 > &  S,
matrix_t< T > &  alpha_eph 
)
template<typename T >
void bnmf_algs::details::update_beta_eph ( const vector_t< T > &  beta,
const tensor_t< T, 3 > &  S,
matrix_t< T > &  beta_eph 
)
template<typename T >
void bnmf_algs::details::update_grad_minus ( const matrix_t< T > &  alpha_eph,
matrix_t< T > &  grad_minus 
)
template<typename T >
void bnmf_algs::details::update_grad_plus ( const matrix_t< T > &  beta_eph,
const tensor_t< T, 3 > &  S,
tensor_t< T, 3 > &  grad_plus 
)
template<typename T >
static void bnmf_algs::details::update_mu ( const matrix_t< T > &  orig_over_appr,
const matrix_t< T > &  orig_over_appr_squared,
const matrix_t< T > &  nu,
const tensor_t< T, 3 > &  grad_plus,
const matrix_t< T > &  grad_minus,
double  eps,
matrix_t< T > &  mu 
)
static
template<typename T >
void bnmf_algs::details::update_nu ( const matrix_t< T > &  orig_over_appr,
const matrix_t< T > &  orig_over_appr_squared,
const matrix_t< T > &  mu,
const tensor_t< T, 3 > &  grad_plus,
const matrix_t< T > &  grad_minus,
double  eps,
matrix_t< T > &  nu 
)
template<typename T >
void bnmf_algs::details::update_orig_over_appr ( const matrix_t< T > &  X,
const matrix_t< T > &  X_hat,
const matrix_t< T > &  eps_mat,
matrix_t< T > &  orig_over_appr 
)
template<typename T >
void bnmf_algs::details::update_orig_over_appr_squared ( const matrix_t< T > &  X,
const matrix_t< T > &  X_hat,
const matrix_t< T > &  eps_mat,
matrix_t< T > &  orig_over_appr_squared 
)
template<typename T >
void bnmf_algs::details::update_S ( const matrix_t< T > &  orig_over_appr,
const matrix_t< T > &  nu,
const matrix_t< T > &  mu,
tensor_t< T, 3 > &  S 
)
template<typename T >
void bnmf_algs::details::update_X_hat ( const matrix_t< T > &  nu,
const matrix_t< T > &  mu,
matrix_t< T > &  X_hat 
)