bnmf-algs
|
Namespace containing online_EM algorithm related functions. More...
Functions | |
template<typename T > | |
size_t | init_nan_values (matrix_t< T > &X) |
Initialize all NaN values in the given matrix with the mean of the remaining values that are different than NaN. More... | |
template<typename Scalar > | |
std::pair< matrix_t< Scalar >, matrix_t< Scalar > > | init_alpha_beta (const std::vector< alloc_model::Params< Scalar >> ¶m_vec, size_t y) |
Initialize each entry of alpha and beta matrices with the given model parameters. More... | |
template<typename T > | |
std::tuple< matrix_t< T >, matrix_t< T >, vector_t< T > > | init_S_xx (const matrix_t< T > &X_full, size_t z, const std::vector< size_t > &ii, const std::vector< size_t > &jj) |
Initialize S_pjk, S_ipk matrices and S_ppk vector from a Dirichlet distribution with all parameters equal to 1. More... | |
template<typename T , typename Scalar , typename PsiFunction > | |
void | update_logW (const matrix_t< Scalar > &alpha, const matrix_t< T > &S_ipk, const vector_t< Scalar > &alpha_pk, const vector_t< T > &S_ppk, const PsiFunction &psi_fn, matrix_t< double > &logW) |
Perform an update on logW matrix. More... | |
template<typename T , typename Scalar , typename PsiFunction > | |
void | update_logH (const matrix_t< Scalar > &beta, const matrix_t< T > &S_pjk, const Scalar b, const PsiFunction &psi_fn, matrix_t< double > &logH) |
Perform an update on logW matrix. More... | |
template<typename T > | |
std::tuple< std::vector< size_t >, std::vector< size_t >, std::vector< T > > | find_nonzero (const matrix_t< T > &X) |
Find nonzero entries and their indices in the given matrix and return indices and values as vectors. More... | |
template<typename T > | |
double | update_allocation (const std::vector< size_t > &ii, const std::vector< size_t > &jj, const std::vector< T > &xx, bld::EMResult< T > &res, vector_t< T > &S_ppk) |
Update the current allocation by performing a maximization step for each nonzero entry of the original input matrix. More... | |
template<typename T , typename Scalar > | |
double | delta_log_PS (const matrix_t< Scalar > &alpha, const matrix_t< Scalar > &beta, const matrix_t< T > &S_ipk, const matrix_t< T > &S_pjk, const vector_t< Scalar > &alpha_pk, const vector_t< T > &S_ppk, Scalar b) |
Compute the difference in log_PS value computed using the given model variables. More... | |
Namespace containing online_EM algorithm related functions.
double bnmf_algs::details::online_EM::delta_log_PS | ( | const matrix_t< Scalar > & | alpha, |
const matrix_t< Scalar > & | beta, | ||
const matrix_t< T > & | S_ipk, | ||
const matrix_t< T > & | S_pjk, | ||
const vector_t< Scalar > & | alpha_pk, | ||
const vector_t< T > & | S_ppk, | ||
Scalar | b | ||
) |
Compute the difference in log_PS value computed using the given model variables.
T | Type of the matrix entries. |
Scalar | Type of the model parameters. |
alpha | alpha matrix containing alpha model parameters. |
beta | beta matrix containing beta model parameters. |
S_ipk | Sum of S tensor along its 2nd axis. |
S_pjk | Sum of S tensor along its 1st axis. |
alpha_pk | Column sums of alpha matrix. |
S_ppk | Sum of S tensor along its 1st and 2nd dimensions. |
b | b model parameter |
std::tuple<std::vector<size_t>, std::vector<size_t>, std::vector<T> > bnmf_algs::details::online_EM::find_nonzero | ( | const matrix_t< T > & | X | ) |
Find nonzero entries and their indices in the given matrix and return indices and values as vectors.
T | Type of the input matrix. |
X | Input matrix. |
std::pair<matrix_t<Scalar>, matrix_t<Scalar> > bnmf_algs::details::online_EM::init_alpha_beta | ( | const std::vector< alloc_model::Params< Scalar >> & | param_vec, |
size_t | y | ||
) |
Initialize each entry of alpha and beta matrices with the given model parameters.
The returned alpha matrix is of shape \(x \times z\) and beta matrix is of shape \(z \times y\).
Scalar | Type of the model parameters. |
param_vec | Vector containing an alloc_model::Params object for every hidden dimension. |
y | Columns of beta matrix. |
size_t bnmf_algs::details::online_EM::init_nan_values | ( | matrix_t< T > & | X | ) |
Initialize all NaN values in the given matrix with the mean of the remaining values that are different than NaN.
T | Type of the matrix entries. |
X | Input matrix containing NaN values. |
std::tuple<matrix_t<T>, matrix_t<T>, vector_t<T> > bnmf_algs::details::online_EM::init_S_xx | ( | const matrix_t< T > & | X_full, |
size_t | z, | ||
const std::vector< size_t > & | ii, | ||
const std::vector< size_t > & | jj | ||
) |
Initialize S_pjk, S_ipk matrices and S_ppk vector from a Dirichlet distribution with all parameters equal to 1.
For every nonzero value \(X_{ij}\) in the input matrix X, this function samples from Dirichlet distribution with \(z\) many 1's as the parameter vector and adds the resulting sample to \(i^{th}\) row of S_ipk matrix, \(j^{th}\) row of S_pjk matrix and to S_ppk vector.
T | Type of the matrix entries. |
X_full | Input matrix X not containing any NaN values (NaNs must be initialized to some value). |
z | Rank of the decomposition (hidden layer count). |
ii | Row indices of every nonzero value in the original X input matrix. |
jj | Column indices of every nonzero value in the original X input matrix. |
double bnmf_algs::details::online_EM::update_allocation | ( | const std::vector< size_t > & | ii, |
const std::vector< size_t > & | jj, | ||
const std::vector< T > & | xx, | ||
bld::EMResult< T > & | res, | ||
vector_t< T > & | S_ppk | ||
) |
Update the current allocation by performing a maximization step for each nonzero entry of the original input matrix.
T | Type of the input matrix. |
ii | Row indices of the original nonzero entries. |
jj | Column indices of the original nonzero entries. |
xx | Corresponding original nonzero entries. |
res | EMResult object containing the results computed up until now. Matrices and sums given in this EMResult object will be modified with the computed values. |
S_ppk | S_ppk vector that will be modified in-place. |
void bnmf_algs::details::online_EM::update_logH | ( | const matrix_t< Scalar > & | beta, |
const matrix_t< T > & | S_pjk, | ||
const Scalar | b, | ||
const PsiFunction & | psi_fn, | ||
matrix_t< double > & | logH | ||
) |
Perform an update on logW matrix.
T | Type of the input matrix. |
Scalar | Type of the model parameters. |
PsiFunction | Function/functor to compute psi (digamma) of a value. |
beta | beta matrix returned by init_alpha_beta. |
S_pjk | Sum of \(S\) along its first dim, i.e. \(S_{+jk}\). |
b | b model parameter passed to EM algorithm. (rate parameter of Gamma distribution). |
psi_fn | Psi function to use. |
logH | logH matrix to update in-place. |
void bnmf_algs::details::online_EM::update_logW | ( | const matrix_t< Scalar > & | alpha, |
const matrix_t< T > & | S_ipk, | ||
const vector_t< Scalar > & | alpha_pk, | ||
const vector_t< T > & | S_ppk, | ||
const PsiFunction & | psi_fn, | ||
matrix_t< double > & | logW | ||
) |
Perform an update on logW matrix.
T | Type of the input matrix. |
Scalar | Type of the model parameters. |
PsiFunction | Function/functor to compute psi (digamma) of a value. |
alpha | alpha matrix returned by init_alpha_beta. |
S_ipk | Sum of \(S\) tensor along its second dim, i.e. \(S_{i+k}\). |
alpha_pk | Vector containing column sums of alpha matrix. |
S_ppk | Sum of \(S\) tensor along its first 2 dimensions, i.e. \(S_{++k}\). |
psi_fn | Psi function to use. |
logW | logW matrix to update in-place. |