3 #ifndef NTF_NTFAOADMM_HPP_ 4 #define NTF_NTFAOADMM_HPP_ 23 MAT update(
const int mode) {
25 MAT updated_fac(this->m_ncp_factors.factor(mode));
26 MAT prev_fac = updated_fac;
30 arma::trace(this->gram_without_one) / this->m_ncp_factors.rank();
31 alpha = (alpha > 0) ? alpha : 0.01;
32 tempgram = this->gram_without_one;
33 tempgram.diag() += alpha;
34 L = arma::chol(tempgram,
"lower");
36 bool stop_iter =
false;
39 for (
int i = 0; i < admm_iter && !stop_iter; i++) {
40 prev_fac = updated_fac;
41 m_ncp_aux_t.
set(mode, m_ncp_aux.
factor(mode).t());
44 mode, arma::solve(arma::trimatl(L),
45 this->ncp_mttkrp_t[mode] +
46 (alpha * (updated_fac.t() +
47 m_ncp_aux_t.
factor(mode)))));
49 mode, arma::solve(arma::trimatu(Lt), m_temp_ncp_aux_t.
factor(mode)));
52 updated_fac = m_ncp_aux_t.
factor(mode).t();
54 updated_fac = updated_fac - m_ncp_aux.
factor(mode);
56 [](MAT::elem_type &val) { val = val > 0.0 ? val : 0.0; });
59 m_ncp_aux.
set(mode, m_ncp_aux.
factor(mode) + updated_fac -
60 m_ncp_aux_t.
factor(mode).t());
63 double facnorm = arma::norm(updated_fac,
"fro");
66 double dualnorm = arma::norm(m_ncp_aux.
factor(mode),
"fro");
69 double r = norm(updated_fac.t() - m_ncp_aux_t.
factor(mode),
"fro");
70 double s = norm(updated_fac - prev_fac,
"fro");
71 if (r < (tolerance * facnorm) && s < (tolerance * dualnorm))
75 return updated_fac.t();
80 :
AUNTF(i_tensor, i_k, i_algo),
81 m_ncp_aux(i_tensor.dimensions(), i_k, false),
82 m_ncp_aux_t(i_tensor.dimensions(), i_k, true),
83 m_temp_ncp_aux_t(i_tensor.dimensions(), i_k, true) {
86 m_temp_ncp_aux_t.
zeros();
89 tempgram.zeros(i_k, i_k);
97 #endif // NTF_NTFAOADMM_HPP_ NTFAOADMM(const Tensor &i_tensor, const int i_k, algotype i_algo)
Data is stored such that the unfolding is column major.
#define EPSILON_1EMINUS16
void normalize()
only during initialization. Reset's all lambda.
void set(const int i_n, const MAT &i_factor)
Set the mode i_n with the given factor matrix.
void zeros()
this is for reinitializing zeros across different processors.
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
MAT & factor(const int i_n) const
factor matrix of a mode i_n