bnmf-algs
Classes | Functions
bnmf_algs::alloc_model Namespace Reference

Namespace that contains functions related to Allocation Model [5]. More...

Classes

struct  Params
 Structure to hold the parameters for the Allocation Model [5]. More...
 

Functions

template<typename T , typename Scalar >
double log_marginal_S (const tensor_t< T, 3 > &S, const Params< Scalar > &model_params)
 Compute the log marginal of tensor S with respect to the given distribution parameters. More...
 
template<typename T , typename Scalar >
std::tuple< matrix_t< T >, matrix_t< T >, vector_t< T > > bnmf_priors (const shape< 3 > &tensor_shape, const Params< Scalar > &model_params)
 Return prior matrices W, H and vector L according to the Bayesian NMF allocation model using distribution parameters. More...
 
template<typename T >
tensor_t< T, 3 > sample_S (const matrix_t< T > &prior_W, const matrix_t< T > &prior_H, const vector_t< T > &prior_L)
 Sample a tensor S from generative Bayesian NMF model using the given priors. More...
 
template<typename Integer , typename Scalar >
double total_log_marginal (const matrix_t< Integer > &X, const Params< Scalar > &model_params)
 Calculate total marginal value, \(p(X|\Theta) = \sum_S p(X|S)p(S|\Theta)\) where \(Theta\) is model parameters. More...
 
template<typename Scalar >
Params< Scalar > make_bld_params (const shape< 3 > &tensor_shape)
 Make default BLD solver parameters. More...
 
template<typename Scalar >
std::vector< Params< Scalar > > make_EM_params (const shape< 3 > &tensor_shape)
 Make default EM solver parameters. More...
 

Detailed Description

Namespace that contains functions related to Allocation Model [5].

Function Documentation

template<typename T , typename Scalar >
std::tuple<matrix_t<T>, matrix_t<T>, vector_t<T> > bnmf_algs::alloc_model::bnmf_priors ( const shape< 3 > &  tensor_shape,
const Params< Scalar > &  model_params 
)

Return prior matrices W, H and vector L according to the Bayesian NMF allocation model using distribution parameters.

According to the Bayesian NMF allocation model [5],

\(L_j \sim \mathcal{G}(a, b) \qquad W_{:k} \sim \mathcal{D}(\alpha) \qquad H_{:j} \sim \mathcal{D}(\beta)\).

Template Parameters
TValue type of the matrix/vector objects.
ScalarType of the model parameters.
Parameters
tensor_shapeShape of the sample tensor \(x \times y \times z\).
model_paramsAllocation Model parameters. See bnmf_algs::alloc_model::Params<double>.
Returns
std::tuple of \(<W_{x \times z}, H_{z \times y}, L_y>\).
Exceptions
assertionerror if number of alpha parameters is not \(x\), if number of beta parameters is not \(z\).
template<typename T , typename Scalar >
double bnmf_algs::alloc_model::log_marginal_S ( const tensor_t< T, 3 > &  S,
const Params< Scalar > &  model_params 
)

Compute the log marginal of tensor S with respect to the given distribution parameters.

According to the Bayesian NMF allocation model [5],

\(\log{p(S)} = \log{p(W, H, L, S)} - \log{p(W, H, L | S)}\).

Template Parameters
Tvalue type of tensor S.
ScalarType of the model parameters.
Parameters
STensor \(S\) of size \(x \times y \times z \).
model_paramsAllocation model parameters. See bnmf_algs::alloc_model::Params<double>.
Returns
log marginal \(\log{p(S)}\).
Exceptions
assertionerror if number of alpha parameters is not equal to S.dimension(0), if number of beta parameters is not equal to S.dimension(2).
template<typename Scalar >
Params<Scalar> bnmf_algs::alloc_model::make_bld_params ( const shape< 3 > &  tensor_shape)

Make default BLD solver parameters.

This function makes default BLD parameters as specified in Params::Params.

Template Parameters
ScalarType of the parameters.
Parameters
tensor_shapeShape of tensor \(S_{x \times y \times z}\).
Returns
Default parameters to be used with any BLD algorithm.
template<typename Scalar >
std::vector<Params<Scalar> > bnmf_algs::alloc_model::make_EM_params ( const shape< 3 > &  tensor_shape)

Make default EM solver parameters.

This function makes default EM algorithm (such as online_EM) parameters. Note that EM algorithms have a different parametrization than BLD solvers, i.e. there is a parameter for each entry of \(W\) and \(H\) matrices. Therefore, this function returns a vector of \(z\) Params objects where \(z\) is the rank of the decomposition (depth of the hidden tensor \(S\).)

Template Parameters
ScalarType of the parameters.
Parameters
tensor_shapeShape of tensor \(S_{x \times y \times z}\).
Returns
Default parameters to be used with EM algorithms.
template<typename T >
tensor_t<T, 3> bnmf_algs::alloc_model::sample_S ( const matrix_t< T > &  prior_W,
const matrix_t< T > &  prior_H,
const vector_t< T > &  prior_L 
)

Sample a tensor S from generative Bayesian NMF model using the given priors.

According to the generative Bayesian NMF model [5],

\(S_{ijk} \sim \mathcal{PO}(W_{ik}H_{kj}L_{j})\).

Template Parameters
TValue type of the matrix/vector/tensor objects.
Parameters
prior_WPrior matrix for \(W\) of shape \(x \times z\).
prior_HPrior matrix for \(H\) of shape \(z \times y\).
prior_LPrior vector for \(L\) of size \(y\).
Returns
A sample tensor of size \(x \times y \times z\) from generative Bayesian NMF model.
Exceptions
assertionerror if number of columns of prior_W is not equal to number of rows of prior_H, if number of columns of prior_H is not equal to number of columns of prior_L
template<typename Integer , typename Scalar >
double bnmf_algs::alloc_model::total_log_marginal ( const matrix_t< Integer > &  X,
const Params< Scalar > &  model_params 
)

Calculate total marginal value, \(p(X|\Theta) = \sum_S p(X|S)p(S|\Theta)\) where \(Theta\) is model parameters.

Template Parameters
IntegerType of the matrix entries (must be an integer type).
ScalarType of the model parameters.
Parameters
XInteger matrix whose every possible tensor allocation will be tried.
model_paramsModel parameters.
Returns
Total marginal value \(p(X|\Theta)\).