planc
Parallel Lowrank Approximation with Non-negativity Constraints
distntfhals.hpp
Go to the documentation of this file.
1 /* Copyright Ramakrishnan Kannan 2018 */
2 
3 #ifndef DISTNTF_DISTNTFHALS_HPP_
4 #define DISTNTF_DISTNTFHALS_HPP_
5 
6 #include "distntf/distauntf.hpp"
7 
8 namespace planc {
9 
10 class DistNTFHALS : public DistAUNTF {
11  protected:
19  MAT update(const int mode) {
20  MAT H(this->m_local_ncp_factors.factor(mode));
21  // iterate over all columns of H
22  for (int i = 0; i < this->m_local_ncp_factors.rank(); i++) {
23  VEC updHi;
24  if (m_nls_sizes[mode] > 0) {
25  updHi = H.col(i) + ((this->ncp_local_mttkrp_t[mode].row(i)).t() -
26  H * this->global_gram.col(i));
27  } else {
28  updHi = H.col(i);
29  updHi.zeros();
30  }
31 
32  fixNumericalError<VEC>(&updHi);
33  double normHi = arma::norm(updHi, 2);
34  normHi *= normHi;
35  double globalnormHi = normHi;
36  MPI_Allreduce(&normHi, &globalnormHi, 1, MPI_DOUBLE, MPI_SUM,
37  MPI_COMM_WORLD);
38  if (globalnormHi > 0) {
39  H.col(i) = updHi;
40  }
41  }
42  return H.t();
43  }
44 
45  public:
46  DistNTFHALS(const Tensor &i_tensor, const int i_k, algotype i_algo,
47  const UVEC &i_global_dims, const UVEC &i_local_dims,
48  const UVEC &i_nls_sizes, const UVEC &i_nls_idxs,
49  const NTFMPICommunicator &i_mpicomm)
50  : DistAUNTF(i_tensor, i_k, i_algo, i_global_dims, i_local_dims,
51  i_nls_sizes, i_nls_idxs, i_mpicomm) {}
52 }; // class DistNTFHALS
53 
54 } // namespace planc
55 
56 #endif // DISTNTF_DISTNTFHALS_HPP_
Data is stored such that the unfolding is column major.
Definition: tensor.hpp:32
algotype
Definition: utils.h:10
#define UVEC
Definition: utils.h:58
DistNTFHALS(const Tensor &i_tensor, const int i_k, algotype i_algo, const UVEC &i_global_dims, const UVEC &i_local_dims, const UVEC &i_nls_sizes, const UVEC &i_nls_idxs, const NTFMPICommunicator &i_mpicomm)
Definition: distntfhals.hpp:46
#define MAT
Definition: utils.h:52
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
Definition: ncpfactors.hpp:20
#define VEC
Definition: utils.h:61