planc
Parallel Lowrank Approximation with Non-negativity Constraints
distmu.hpp
Go to the documentation of this file.
1 /* Copyright 2016 Ramakrishnan Kannan */
2 
3 #ifndef DISTNMF_DISTMU_HPP_
4 #define DISTNMF_DISTMU_HPP_
5 #include "distnmf/aunmf.hpp"
6 
13 namespace planc {
14 
15 template <class INPUTMATTYPE>
16 class DistMU : public DistAUNMF<INPUTMATTYPE> {
17  MAT HWtW;
18  MAT WHtH;
19  ROWVEC localWnorm;
20  ROWVEC Wnorm;
21 
22  protected:
31  void updateW() {
32  WHtH = (this->W * this->HtH) + EPSILON;
33 #ifdef MPI_VERBOSE
34  DISTPRINTINFO("::WHtH::" << endl << this->WHtH);
35 #endif // ifdef MPI_VERBOSE
36  this->W = (this->W % this->AHtij.t()) / WHtH;
37  DISTPRINTINFO("MU::updateW::HtH::"
38  << PRINTMATINFO(this->HtH) << "::WHtH::" << PRINTMATINFO(WHtH)
39  << "::AHtij::" << PRINTMATINFO(this->AHtij)
40  << "::W::" << PRINTMATINFO(this->W));
41  DISTPRINTINFO("MU::updateW::HtH::"
42  << norm(this->HtH, "fro") << "::WHtH::" << norm(WHtH, "fro")
43  << "::AHtij::" << norm(this->AHtij, "fro")
44  << "::W::" << norm(this->W, "fro"));
45 
46  /*localWnorm = sum(this->W % this->W);
47  mpitic();
48  MPI_Allreduce(localWnorm.memptr(), Wnorm.memptr(), this->k, MPI_FLOAT,
49  MPI_SUM, MPI_COMM_WORLD);
50  double temp = mpitoc();
51  this->time_stats.allgather_duration(temp);
52  for (int i = 0; i < this->k; i++) {
53  if (Wnorm(i) > 1) {
54  float norm_const = sqrt(Wnorm(i));
55  this->W.col(i) = this->W.col(i) / norm_const;
56  //this->H.col(i) = norm_const * this->H.col(i);
57  }
58  }*/
59  this->Wt = this->W.t();
60  }
69  void updateH() {
70  HWtW = this->H * this->WtW + EPSILON;
71  this->H = (this->H % this->WtAij.t()) / HWtW;
72 #ifdef MPI_VERBOSE
73  DISTPRINTINFO("::HWtW::" << endl << HWtW);
74 #endif // ifdef MPI_VERBOSE
75 
76  // fixNumericalError<MAT>(&this->H);
77  DISTPRINTINFO("MU::updateH::WtW::"
78  << PRINTMATINFO(this->WtW) << "::HWtW::" << PRINTMATINFO(HWtW)
79  << "::WtAij::" << PRINTMATINFO(this->WtAij)
80  << "::H::" << PRINTMATINFO(this->H));
81  DISTPRINTINFO("MU::updateH::WtW::"
82  << norm(this->WtW, "fro") << "::HWtW::" << norm(HWtW, "fro")
83  << "::WtAij::" << norm(this->WtAij, "fro")
84  << "::H::" << norm(this->H, "fro"));
85  this->Ht = this->H.t();
86  }
87 
88  public:
89  DistMU(const INPUTMATTYPE& input, const MAT& leftlowrankfactor,
90  const MAT& rightlowrankfactor, const MPICommunicator& communicator,
91  const int numkblks)
92  : DistAUNMF<INPUTMATTYPE>(input, leftlowrankfactor, rightlowrankfactor,
93  communicator, numkblks) {
94  WHtH.zeros(this->globalm() / this->m_mpicomm.size(), this->k);
95  HWtW.zeros(this->globaln() / this->m_mpicomm.size(), this->k);
96  localWnorm.zeros(this->k);
97  Wnorm.zeros(this->k);
98  PRINTROOT("DistMU() constructor successful");
99  }
100 };
101 
102 } // namespace planc
103 
104 #endif // DISTNMF_DISTMU_HPP_
const int globaln() const
returns globaln
Definition: distnmf.hpp:86
DistMU(const INPUTMATTYPE &input, const MAT &leftlowrankfactor, const MAT &rightlowrankfactor, const MPICommunicator &communicator, const int numkblks)
Definition: distmu.hpp:89
const int globalm() const
returns globalm
Definition: distnmf.hpp:84
#define DISTPRINTINFO(MSG)
Definition: distutils.h:37
#define EPSILON
Definition: utils.h:44
#define MAT
Definition: utils.h:52
#define ROWVEC
Definition: utils.h:54
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 PRINTROOT(MSG)
Definition: distutils.h:32
#define PRINTMATINFO(A)
Definition: utils.h:63